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

Testing whether a word is plural or not #31

Closed
wants to merge 3 commits into from

Conversation

pdscopes
Copy link
Contributor

As discussed in #28, this PR adds three new functions to the inflector class:

  • is_plural - whether a word is plural or uncountable
  • is_singular - whether a word is singular or uncountable
  • is_uncountable - whether a word is uncountable

I have deliberately not added helper functions at this point as this functionality is fairly niche.


Points raised in issue

Thanks for your suggestion, that could be useful. Instead of applying inflections and checking if the word changes, what do you think about using the plural and singular regexp available in the Inflections instance?

This was not possible because of the catchall regex like /$/.


Known bugs

This PR does break the testing because, I believe, the inflections in some languages are incomplete, e.g.:

  • Spanish: singularize('interés') = 'interé' which is incorrect
  • Turkish: pluralize('kirazlar') = 'kirazlarlar' which is incorrect

Unfortunately, I am not a speaker of these languages and therefore cannot correct them confidently, however some imcomplete suggestions:

// lib/inflections/tr.php
  $inflect
  // Add the negative look behind: "(?<!l[ae]r)"
  ->plural('/([aoıu][^aoıueöiü]{0,6})(?<!l[ae]r)$/u', '\1lar')
  ->plural('/([eöiü][^aoıueöiü]{0,6})(?<!l[ae]r)$/u', '\1ler')
  // ...
     

// lib/inflections/es.php
  $inflect
  // ...
  // Add the negative look behind "(?<!eré)"
  ->singular('/(?<!eré)s$/', '\1')
  // ...

@olvlvl
Copy link
Member

olvlvl commented Apr 25, 2019

Hi Pete, thanks for the contribution. We have 68 nationalities at work I should be able to find somebody to confirm the Spanish and Turkish inflections. I'll have a look as soon as possible.

@pdscopes
Copy link
Contributor Author

Amazing, FYI it is also failing on Norwegian "nb".

@olvlvl
Copy link
Member

olvlvl commented May 21, 2019

@pdscopes I implemented is_uncountable() over here: #32. Sorry I didn't have time to do more yet.

@pdscopes
Copy link
Contributor Author

@olvlvl no worries, I've resolved the conflicts that #32 caused in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants