diff --git a/lib/Doctrine/Inflector/InflectorFactory.php b/lib/Doctrine/Inflector/InflectorFactory.php index a0740a7..02939b9 100644 --- a/lib/Doctrine/Inflector/InflectorFactory.php +++ b/lib/Doctrine/Inflector/InflectorFactory.php @@ -10,6 +10,7 @@ use Doctrine\Inflector\Rules\Portuguese; use Doctrine\Inflector\Rules\Spanish; use Doctrine\Inflector\Rules\Turkish; +use Doctrine\Inflector\Rules\Italian; use InvalidArgumentException; use function sprintf; @@ -41,6 +42,9 @@ public static function createForLanguage(string $language): LanguageInflectorFac case Language::TURKISH: return new Turkish\InflectorFactory(); + + case Language::ITALIAN: + return new Italian\InflectorFactory(); default: throw new InvalidArgumentException(sprintf( diff --git a/lib/Doctrine/Inflector/Language.php b/lib/Doctrine/Inflector/Language.php index 78c3cc7..db911a1 100644 --- a/lib/Doctrine/Inflector/Language.php +++ b/lib/Doctrine/Inflector/Language.php @@ -12,7 +12,7 @@ final class Language public const PORTUGUESE = 'portuguese'; public const SPANISH = 'spanish'; public const TURKISH = 'turkish'; - + public const ITALIAN = 'italian'; private function __construct() { } diff --git a/lib/Doctrine/Inflector/Rules/Italian/Inflectible.php b/lib/Doctrine/Inflector/Rules/Italian/Inflectible.php new file mode 100644 index 0000000..b009d4b --- /dev/null +++ b/lib/Doctrine/Inflector/Rules/Italian/Inflectible.php @@ -0,0 +1,44 @@ +<?php + +declare(strict_types=1); + +namespace Doctrine\Inflector\Rules\Italian; + +use Doctrine\Inflector\Rules\Pattern; +use Doctrine\Inflector\Rules\Substitution; +use Doctrine\Inflector\Rules\Transformation; +use Doctrine\Inflector\Rules\Word; + +class Inflectible +{ + /** + * @return Transformation[] + */ + public static function getSingular() : iterable + { + yield new Transformation(new Pattern('e$'), 'a'); + yield new Transformation(new Pattern('i$'), 'e'); + yield new Transformation(new Pattern('i$'), 'o'); + } + + /** + * @return Transformation[] + */ + public static function getPlural() : iterable + { + yield new Transformation(new Pattern('a$'), 'e'); + yield new Transformation(new Pattern('e$'), 'i'); + yield new Transformation(new Pattern('io$'), 'i'); + yield new Transformation(new Pattern('o$'), 'i'); + } + + /** + * @return Substitution[] + */ + public static function getIrregular() : iterable + { + return yield new Substitution(new Word(''), new Word('')); + // yield new Substitution(new Word('studente'), new Word('studenti')); + //yield new Substitution(new Word('negozio'), new Word('negozi')); + } +} diff --git a/lib/Doctrine/Inflector/Rules/Italian/InflectorFactory.php b/lib/Doctrine/Inflector/Rules/Italian/InflectorFactory.php new file mode 100644 index 0000000..a705f44 --- /dev/null +++ b/lib/Doctrine/Inflector/Rules/Italian/InflectorFactory.php @@ -0,0 +1,21 @@ +<?php + +declare(strict_types=1); + +namespace Doctrine\Inflector\Rules\Italian; + +use Doctrine\Inflector\GenericLanguageInflectorFactory; +use Doctrine\Inflector\Rules\Ruleset; + +final class InflectorFactory extends GenericLanguageInflectorFactory +{ + protected function getSingularRuleset() : Ruleset + { + return Rules::getSingularRuleset(); + } + + protected function getPluralRuleset() : Ruleset + { + return Rules::getPluralRuleset(); + } +} diff --git a/lib/Doctrine/Inflector/Rules/Italian/README.md b/lib/Doctrine/Inflector/Rules/Italian/README.md new file mode 100644 index 0000000..b757933 --- /dev/null +++ b/lib/Doctrine/Inflector/Rules/Italian/README.md @@ -0,0 +1,38 @@ +# doctrine-Italian-inflector- + +## italian language for the pluraliazer + +### Author: Mattias Raiani + +This is a first step for the italian language for Inflector. I'll improve it in the future + + +#### SET UP + 1. In the Inflector's Doctrine vendor pack, there is a folder named `Rules`; + Paste the [`Italian` folder](https://github.com/riettotek/doctrine-Italian-inflector-#:~:text=Commit%20time-,italian,-Italian%20Package) in such folder. Here is fully path: + ``` + vendor/doctrine/inflector/lib/Doctrine/Inflector/Rules + ``` +2. Add the const Italian in the `Language.php` file + +<img width="395" alt="Language" src="https://user-images.githubusercontent.com/75453324/166954294-d8dab91c-d91a-407d-9144-6c97bb02ec70.png"> + + +3. Add the `case` line in the createForLanguage() method at the end of the `InflectorFactory.php` file; +...and don't forget to apply the use statement at the top of file to allow loading the language files + +<img width="432" alt="inflectorFactory" src="https://user-images.githubusercontent.com/75453324/166954301-b3b1896b-cb24-4c9f-a182-c5aaafd04285.png"> + +### USAGE +By default it will create an English inflector. To use Italian language, just pass it to the createForLanguage() method: +``` +use Doctrine\Inflector\InflectorFactory; +use Doctrine\Inflector\Language; + +$inflector = InflectorFactory::createForLanguage(Language::ITALIAN)->build(); +``` +### USAGE in LARAVEL +In the Pluraliazer.php file locate in the Illuminate\Support namespace. +In here, then u have to set the value of the $language property to `italian` instead of 'english'. + +<img width="395" alt="Pluralizer" src="https://user-images.githubusercontent.com/75453324/166954350-77b4e8ce-da54-4b10-a65c-7795013558cd.png"> diff --git a/lib/Doctrine/Inflector/Rules/Italian/Rules.php b/lib/Doctrine/Inflector/Rules/Italian/Rules.php new file mode 100644 index 0000000..52cc491 --- /dev/null +++ b/lib/Doctrine/Inflector/Rules/Italian/Rules.php @@ -0,0 +1,31 @@ +<?php + +declare(strict_types=1); + +namespace Doctrine\Inflector\Rules\Italian; + +use Doctrine\Inflector\Rules\Patterns; +use Doctrine\Inflector\Rules\Ruleset; +use Doctrine\Inflector\Rules\Substitutions; +use Doctrine\Inflector\Rules\Transformations; + +final class Rules +{ + public static function getSingularRuleset() : Ruleset + { + return new Ruleset( + new Transformations(...Inflectible::getSingular()), + new Patterns(...Uninflected::getSingular()), + (new Substitutions(...Inflectible::getIrregular()))->getFlippedSubstitutions() + ); + } + + public static function getPluralRuleset() : Ruleset + { + return new Ruleset( + new Transformations(...Inflectible::getPlural()), + new Patterns(...Uninflected::getPlural()), + new Substitutions(...Inflectible::getIrregular()) + ); + } +} diff --git a/lib/Doctrine/Inflector/Rules/Italian/Uninflected.php b/lib/Doctrine/Inflector/Rules/Italian/Uninflected.php new file mode 100644 index 0000000..a2cc8dc --- /dev/null +++ b/lib/Doctrine/Inflector/Rules/Italian/Uninflected.php @@ -0,0 +1,101 @@ +<?php + +declare(strict_types=1); + +namespace Doctrine\Inflector\Rules\Italian; + +use Doctrine\Inflector\Rules\Pattern; + +final class Uninflected +{ + /** + * @return Pattern[] + */ + public static function getSingular() : iterable + { + yield from self::getDefault(); + + yield new Pattern('.*ss'); + yield new Pattern('clothes'); + yield new Pattern('data'); + yield new Pattern('fascia'); + yield new Pattern('fuchsia'); + yield new Pattern('galleria'); + yield new Pattern('mafia'); + yield new Pattern('militia'); + yield new Pattern('pantaloni'); + yield new Pattern('petunia'); + yield new Pattern('sepia'); + yield new Pattern('trivia'); + yield new Pattern('utopia'); + } + + /** + * @return Pattern[] + */ + public static function getPlural() : iterable + { + yield from self::getDefault(); + + yield new Pattern('media'); + } + + /** + * @return Pattern[] + */ + private static function getDefault() : iterable + { + yield new Pattern('\w+media'); + yield new Pattern('advice'); + yield new Pattern('art'); + yield new Pattern('audio'); + yield new Pattern('borghese'); + yield new Pattern('buffalo'); + yield new Pattern('chassis'); + yield new Pattern('clippers'); + yield new Pattern('cotton'); + yield new Pattern('data'); + yield new Pattern('education'); + yield new Pattern('emoji'); + yield new Pattern('equipment'); + yield new Pattern('evidence'); + yield new Pattern('feedback'); + yield new Pattern('food'); + yield new Pattern('furniture'); + yield new Pattern('gold'); + yield new Pattern('herpes'); + yield new Pattern('homework'); + yield new Pattern('information'); + yield new Pattern('jeans'); + yield new Pattern('knowledge'); + yield new Pattern('love'); + yield new Pattern('Maltese'); + yield new Pattern('management'); + yield new Pattern('metadata'); + yield new Pattern('money'); + yield new Pattern('music'); + yield new Pattern('news'); + yield new Pattern('nutrition'); + yield new Pattern('oil'); + yield new Pattern('patience'); + yield new Pattern('pistoiese'); + yield new Pattern('pokemon'); + yield new Pattern('police'); + yield new Pattern('polish'); + yield new Pattern('portoghese'); + yield new Pattern('progress'); + yield new Pattern('research'); + yield new Pattern('scissors'); + yield new Pattern('series'); + yield new Pattern('social media'); + yield new Pattern('spam'); + yield new Pattern('species'); + yield new Pattern('staff'); + yield new Pattern('sugar'); + yield new Pattern('talent'); + yield new Pattern('traffic'); + yield new Pattern('travel'); + yield new Pattern('weather'); + yield new Pattern('wood'); + } +}