PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.15.2
Independent Analytics – WordPress Analytics Plugin v2.15.2
2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / vendor / symfony / string / Inflector / FrenchInflector.php
independent-analytics / vendor / symfony / string / Inflector Last commit date
EnglishInflector.php 2 weeks ago FrenchInflector.php 2 years ago InflectorInterface.php 2 years ago
FrenchInflector.php
130 lines
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11 namespace IAWPSCOPED\Symfony\Component\String\Inflector;
12
13 /**
14 * French inflector.
15 *
16 * This class does only inflect nouns; not adjectives nor composed words like "soixante-dix".
17 * @internal
18 */
19 final class FrenchInflector implements InflectorInterface
20 {
21 /**
22 * A list of all rules for pluralise.
23 *
24 * @see https://la-conjugaison.nouvelobs.com/regles/grammaire/le-pluriel-des-noms-121.php
25 */
26 private const PLURALIZE_REGEXP = [
27 // First entry: regexp
28 // Second entry: replacement
29 // Words finishing with "s", "x" or "z" are invariables
30 // Les mots finissant par "s", "x" ou "z" sont invariables
31 ['/(s|x|z)$/i', '\\1'],
32 // Words finishing with "eau" are pluralized with a "x"
33 // Les mots finissant par "eau" prennent tous un "x" au pluriel
34 ['/(eau)$/i', '\\1x'],
35 // Words finishing with "au" are pluralized with a "x" excepted "landau"
36 // Les mots finissant par "au" prennent un "x" au pluriel sauf "landau"
37 ['/^(landau)$/i', '\\1s'],
38 ['/(au)$/i', '\\1x'],
39 // Words finishing with "eu" are pluralized with a "x" excepted "pneu", "bleu", "émeu"
40 // Les mots finissant en "eu" prennent un "x" au pluriel sauf "pneu", "bleu", "émeu"
41 ['/^(pneu|bleu|émeu)$/i', '\\1s'],
42 ['/(eu)$/i', '\\1x'],
43 // Words finishing with "al" are pluralized with a "aux" excepted
44 // Les mots finissant en "al" se terminent en "aux" sauf
45 ['/^(bal|carnaval|caracal|chacal|choral|corral|étal|festival|récital|val)$/i', '\\1s'],
46 ['/al$/i', '\\1aux'],
47 // Aspirail, bail, corail, émail, fermail, soupirail, travail, vantail et vitrail font leur pluriel en -aux
48 ['/^(aspir|b|cor|ém|ferm|soupir|trav|vant|vitr)ail$/i', '\\1aux'],
49 // Bijou, caillou, chou, genou, hibou, joujou et pou qui prennent un x au pluriel
50 ['/^(bij|caill|ch|gen|hib|jouj|p)ou$/i', '\\1oux'],
51 // Invariable words
52 ['/^(cinquante|soixante|mille)$/i', '\\1'],
53 // French titles
54 ['/^(mon|ma)(sieur|dame|demoiselle|seigneur)$/', 'IAWPSCOPED\\mes\\2s'],
55 ['/^(Mon|Ma)(sieur|dame|demoiselle|seigneur)$/', 'IAWPSCOPED\\Mes\\2s'],
56 ];
57 /**
58 * A list of all rules for singularize.
59 */
60 private const SINGULARIZE_REGEXP = [
61 // First entry: regexp
62 // Second entry: replacement
63 // Aspirail, bail, corail, émail, fermail, soupirail, travail, vantail et vitrail font leur pluriel en -aux
64 ['/((aspir|b|cor|ém|ferm|soupir|trav|vant|vitr))aux$/i', '\\1ail'],
65 // Words finishing with "eau" are pluralized with a "x"
66 // Les mots finissant par "eau" prennent tous un "x" au pluriel
67 ['/(eau)x$/i', '\\1'],
68 // Words finishing with "al" are pluralized with a "aux" expected
69 // Les mots finissant en "al" se terminent en "aux" sauf
70 ['/(amir|anim|arsen|boc|can|capit|capor|chev|crist|génér|hopit|hôpit|idé|journ|littor|loc|m|mét|minér|princip|radic|termin)aux$/i', '\\1al'],
71 // Words finishing with "au" are pluralized with a "x" excepted "landau"
72 // Les mots finissant par "au" prennent un "x" au pluriel sauf "landau"
73 ['/(au)x$/i', '\\1'],
74 // Words finishing with "eu" are pluralized with a "x" excepted "pneu", "bleu", "émeu"
75 // Les mots finissant en "eu" prennent un "x" au pluriel sauf "pneu", "bleu", "émeu"
76 ['/(eu)x$/i', '\\1'],
77 // Words finishing with "ou" are pluralized with a "s" excepted bijou, caillou, chou, genou, hibou, joujou, pou
78 // Les mots finissant par "ou" prennent un "s" sauf bijou, caillou, chou, genou, hibou, joujou, pou
79 ['/(bij|caill|ch|gen|hib|jouj|p)oux$/i', '\\1ou'],
80 // French titles
81 ['/^mes(dame|demoiselle)s$/', 'IAWPSCOPED\\ma\\1'],
82 ['/^Mes(dame|demoiselle)s$/', 'IAWPSCOPED\\Ma\\1'],
83 ['/^mes(sieur|seigneur)s$/', 'IAWPSCOPED\\mon\\1'],
84 ['/^Mes(sieur|seigneur)s$/', 'IAWPSCOPED\\Mon\\1'],
85 // Default rule
86 ['/s$/i', ''],
87 ];
88 /**
89 * A list of words which should not be inflected.
90 * This list is only used by singularize.
91 */
92 private const UNINFLECTED = '/^(abcès|accès|abus|albatros|anchois|anglais|autobus|bois|brebis|carquois|cas|chas|colis|concours|corps|cours|cyprès|décès|devis|discours|dos|embarras|engrais|entrelacs|excès|fils|fois|gâchis|gars|glas|héros|intrus|jars|jus|kermès|lacis|legs|lilas|marais|mars|matelas|mépris|mets|mois|mors|obus|os|palais|paradis|parcours|pardessus|pays|plusieurs|poids|pois|pouls|printemps|processus|progrès|puits|pus|rabais|radis|recors|recours|refus|relais|remords|remous|rictus|rhinocéros|repas|rubis|sans|sas|secours|sens|souris|succès|talus|tapis|tas|taudis|temps|tiers|univers|velours|verglas|vernis|virus)$/i';
93 /**
94 * {@inheritdoc}
95 */
96 public function singularize(string $plural) : array
97 {
98 if ($this->isInflectedWord($plural)) {
99 return [$plural];
100 }
101 foreach (self::SINGULARIZE_REGEXP as $rule) {
102 [$regexp, $replace] = $rule;
103 if (1 === \preg_match($regexp, $plural)) {
104 return [\preg_replace($regexp, $replace, $plural)];
105 }
106 }
107 return [$plural];
108 }
109 /**
110 * {@inheritdoc}
111 */
112 public function pluralize(string $singular) : array
113 {
114 if ($this->isInflectedWord($singular)) {
115 return [$singular];
116 }
117 foreach (self::PLURALIZE_REGEXP as $rule) {
118 [$regexp, $replace] = $rule;
119 if (1 === \preg_match($regexp, $singular)) {
120 return [\preg_replace($regexp, $replace, $singular)];
121 }
122 }
123 return [$singular . 's'];
124 }
125 private function isInflectedWord(string $word) : bool
126 {
127 return 1 === \preg_match(self::UNINFLECTED, $word);
128 }
129 }
130