Skip to content

Added a FrenchInflector for the String component #36929

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

Merged
merged 1 commit into from
Jul 31, 2020
Merged

Added a FrenchInflector for the String component #36929

merged 1 commit into from
Jul 31, 2020

Conversation

Alexandre-T
Copy link
Contributor

@Alexandre-T Alexandre-T commented May 23, 2020

I read in this blog post this sentence

Symfony Inflector component converts words between their singular and plural forms (for now, only in English)

So I created a FrenchInflector class implementing the InflectorInterface from the String component. This inflector uses regular expressions and it is tested in the FrenchInflectorTest with a lot of the french exceptions.

Q A
Branch master
Bug fix no
New feature yes
Deprecations no
License MIT
Doc PR Not yet

Changelog has been updated, but I'm not sure I did it in the good paragraph.

I don't know if I should update the symfony/symfony-docs, but I have created an example and I could create a PR with it, if you want.

<?php

use Symfony\Component\String\Inflector\FrenchInflector;

$inflector = new FrenchInflector();

$result = $inflector->singularize('dents');     // ['dent']
$result = $inflector->singularize('souris');    // ['souris']
$result = $inflector->singularize('messieurs'); // ['monsieur']

$result = $inflector->pluralize('cinquante'); // ['cinquante']
$result = $inflector->pluralize('pou');       // ['poux']
$result = $inflector->pluralize('cheval');    // ['chevaux']

fabbot.io is detecting a typo, but this is not. The patch done by fabpot suggests to replace the french 'embarras' word by 'embarrass'. I shall not remove or replace it, because "embarras" is an invariant word.

@nicolas-grekas nicolas-grekas added this to the next milestone May 23, 2020
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

nice thanks.
Here is my quick review.
Did you use any source we should mention to build this?

@Alexandre-T
Copy link
Contributor Author

Alexandre-T commented May 24, 2020

Thanks for your review, Nicolas!

As source, I verified that I forgot no rules with this chapter on NouvelObs and I used a reversed dictionnary to find all nouns finishing with -al.

  • Do you want that I add the link to the source as you do it in EnglishInflector?
  • Should I use solution1 (private singleton) or solution2 (long declaration for static uninflectedWords) link to review?

I will update my PR as soon as I have your recommendations.

@Alexandre-T
Copy link
Contributor Author

Alexandre-T commented Jun 27, 2020

Hi @nicolas-grekas ,
I fixed what you suggested in your reviews.
There is always a warning from fabbot.io that detects an error on the word: embarras. This is an invariable french word. I shouldn't replace it with embarrassment.
The bugs on Travis are due to other commits on master.

French inflector implements InflectorInterface, it uses regexp and it is tested in the FrenchInflectorTest
@Alexandre-T
Copy link
Contributor Author

Thanks for your review @GromNaN ! It's commited and pushed!

@fabpot
Copy link
Member

fabpot commented Jul 31, 2020

Thank you @Alexandre-T.

@fabpot fabpot merged commit 5256323 into symfony:master Jul 31, 2020
@nicolas-grekas nicolas-grekas modified the milestones: next, 5.2 Oct 5, 2020
@fabpot fabpot mentioned this pull request Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants