Loheide-eu-mitarbeiterplatt.../vendor/symfony/string/Inflector/SpanishInflector.php
Friederich Loheide 9c0f8de791
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
Phase 0: Fundament für Inhaus
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3)
- Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung
- Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü
- Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person
- Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“
- Benutzerverwaltung im Admin, Zugang vorläufig über is_admin
- vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/
- PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung
- VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-25 20:35:30 +00:00

126 lines
3.5 KiB
PHP

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\String\Inflector;
final class SpanishInflector implements InflectorInterface
{
/**
* A list of all rules for pluralise.
*
* @see https://www.spanishdict.com/guide/spanish-plural-noun-forms
* @see https://www.rae.es/gram%C3%A1tica/morfolog%C3%ADa/la-formaci%C3%B3n-del-plural-plurales-en-s-y-plurales-en-es-reglas-generales
*/
// First entry: regex
// Second entry: replacement
private const PLURALIZE_REGEXP = [
// Specials sí, no
['/(sí|no)$/i', '\1es'],
// Words ending with vowel must use -s (RAE 3.2a, 3.2c)
['/(a|e|i|o|u|á|é|í|ó|ú)$/i', '\1s'],
// Word ending in s or x and the previous letter is accented (RAE 3.2n)
['/ás$/i', 'ases'],
['/és$/i', 'eses'],
['/ís$/i', 'ises'],
['/ós$/i', 'oses'],
['/ús$/i', 'uses'],
// Words ending in -ión must changed to -iones
['/ión$/i', '\1iones'],
// Words ending in some consonants must use -es (RAE 3.2k)
['/(l|r|n|d|j|s|x|ch|y)$/i', '\1es'],
// Word ending in z, must changed to ces
['/(z)$/i', 'ces'],
];
/**
* A list of all rules for singularize.
*/
private const SINGULARIZE_REGEXP = [
// Specials sí, no
['/(sí|no)es$/i', '\1'],
// Words ending in -ión must changed to -iones
['/iones$/i', '\1ión'],
// Word ending in z, must changed to ces
['/ces$/i', 'z'],
// Word ending in s or x and the previous letter is accented (RAE 3.2n)
['/(\w)ases$/i', '\1ás'],
['/eses$/i', 'és'],
['/ises$/i', 'ís'],
['/(\w{2,})oses$/i', '\1ós'],
['/(\w)uses$/i', '\1ús'],
// Words ending in some consonants and -es, must be the consonants
['/(l|r|n|d|j|s|x|ch|y)e?s$/i', '\1'],
// Words ended with vowel and s, must be vowel
['/(a|e|i|o|u|á|é|ó|í|ú)s$/i', '\1'],
];
private const UNINFLECTED_RULES = [
// Words ending with pies (RAE 3.2n)
'/.*(piés)$/i',
];
private const UNINFLECTED = '/^(lunes|martes|miércoles|jueves|viernes|análisis|torax|yo|pies)$/i';
public function singularize(string $plural): array
{
if ($this->isInflectedWord($plural)) {
return [$plural];
}
foreach (self::SINGULARIZE_REGEXP as $rule) {
[$regexp, $replace] = $rule;
if (1 === preg_match($regexp, $plural)) {
return [preg_replace($regexp, $replace, $plural)];
}
}
return [$plural];
}
public function pluralize(string $singular): array
{
if ($this->isInflectedWord($singular)) {
return [$singular];
}
foreach (self::PLURALIZE_REGEXP as $rule) {
[$regexp, $replace] = $rule;
if (1 === preg_match($regexp, $singular)) {
return [preg_replace($regexp, $replace, $singular)];
}
}
return [$singular.'s'];
}
private function isInflectedWord(string $word): bool
{
foreach (self::UNINFLECTED_RULES as $rule) {
if (1 === preg_match($rule, $word)) {
return true;
}
}
return 1 === preg_match(self::UNINFLECTED, $word);
}
}