Skip to content
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

Open
wants to merge 5 commits into
base: 2.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Doctrine/Inflector/InflectorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/Inflector/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
}
Expand Down
44 changes: 44 additions & 0 deletions lib/Doctrine/Inflector/Rules/Italian/Inflectible.php
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');
Copy link
Member

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

}

/**
* @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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two rules could be merged into new Pattern('i?o$') I believe

}

/**
* @return Substitution[]
*/
public static function getIrregular() : iterable
{
return yield new Substitution(new Word(''), new Word(''));
Copy link
Member

Choose a reason for hiding this comment

The 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'));
}
}
21 changes: 21 additions & 0 deletions lib/Doctrine/Inflector/Rules/Italian/InflectorFactory.php
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();
}
}
38 changes: 38 additions & 0 deletions lib/Doctrine/Inflector/Rules/Italian/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# doctrine-Italian-inflector-
Copy link
Member

Choose a reason for hiding this comment

The 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">
31 changes: 31 additions & 0 deletions lib/Doctrine/Inflector/Rules/Italian/Rules.php
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())
);
}
}
101 changes: 101 additions & 0 deletions lib/Doctrine/Inflector/Rules/Italian/Uninflected.php
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');
Copy link
Member

Choose a reason for hiding this comment

The 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');
Copy link
Member

Choose a reason for hiding this comment

The 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');
}
}