-
-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Italian basics Rules #197
base: 2.0.x
Are you sure you want to change the base?
Italian basics Rules #197
Changes from all commits
ed272d7
06ba7cc
08e4c22
cc37086
cab1a42
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two rules could be merged into |
||
} | ||
|
||
/** | ||
* @return Substitution[] | ||
*/ | ||
public static function getIrregular() : iterable | ||
{ | ||
return yield new Substitution(new Word(''), new Word('')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks unfinished |
||
// yield new Substitution(new Word('studente'), new Word('studenti')); | ||
//yield new Substitution(new Word('negozio'), new Word('negozi')); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# doctrine-Italian-inflector- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file seems irrelevant once we merge the PR |
||
|
||
## 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"> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()) | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These words looks like copy-pasted from English |
||
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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely |
||
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'); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This transformation will never happen given the previous one has exactly same catch pattern