| @@ 174-184 (lines=11) @@ | ||
| 171 | * @param string $text |
|
| 172 | * @return string |
|
| 173 | */ |
|
| 174 | public static function pluralize($text) : string |
|
| 175 | { |
|
| 176 | if(in_array($text, self::$noPlurals)) { |
|
| 177 | return $text; |
|
| 178 | } |
|
| 179 | foreach(self::$pluralRules as $rule) { |
|
| 180 | if(preg_match($rule[0], $text, $matches)) { |
|
| 181 | return substr($text, 0, strlen($text) - strlen($matches['remove'] ?? '')) . $rule[1]; |
|
| 182 | } |
|
| 183 | } |
|
| 184 | } |
|
| 185 | ||
| 186 | /** |
|
| 187 | * Generates the english singular of a given word. |
|
| @@ 192-203 (lines=12) @@ | ||
| 189 | * @param string $text |
|
| 190 | * @return string |
|
| 191 | */ |
|
| 192 | public static function singularize($text) : string |
|
| 193 | { |
|
| 194 | if(in_array($text, self::$noPlurals)) { |
|
| 195 | return $text; |
|
| 196 | } |
|
| 197 | foreach(self::$singularRules as $rule) { |
|
| 198 | if(preg_match($rule[0], $text, $matches)) { |
|
| 199 | return substr($text, 0, strlen($text) - strlen($matches['remove'] ?? '')) . $rule[1]; |
|
| 200 | } |
|
| 201 | } |
|
| 202 | return $text; |
|
| 203 | } |
|
| 204 | } |
|
| 205 | ||