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

[String] Add singularize and pluralize filter #4107

Merged
merged 2 commits into from
Jul 5, 2024

Conversation

welcoMattic
Copy link
Contributor

This PR follows up this one in Symfony symfony/symfony#57245.

It adds 2 new filters singularize and pluralize. It uses the String component, especially EnglishInflector and FrenchInflector.

Examples:

{{ 'person'|pluralize('en') }} // persons
{{ 'person'|pluralize('en', false) }} // ['persons', 'people']


{{ 'personne'|pluralize('fr') }} // personnes
{{ 'personne'|pluralize('fr', false) }} // ['personnes']


{{ 'persons'|singluarize('en') }} // person
{{ 'people'|singluarize('en') }} // person
{{ 'persons'|singluarize('en', false) }} // ['person']

{{ 'personnes'|singluarize('fr') }} // personne
{{ 'personnes'|singluarize('fr', false) }} // ['personne']



{{ 'persona'|pluralize('it') }} // \InvalidArgumentException('Language "it" is not supported.')
{{ 'persone'|singluarize('it') }} // \InvalidArgumentException('Language "it" is not supported.')

doc/filters/pluralize.rst Outdated Show resolved Hide resolved
@fabpot
Copy link
Contributor

fabpot commented Jul 4, 2024

I've just pushed an additional commit that makes some significant changes. It contains many tweaks for the docs and the code, but most importantly, it renames the filters to singular and plural. Tell me what you think about these changes.

--TEST--
"plural" filter
--TEMPLATE--
{{ 'partition'|plural('it') }}
Copy link
Contributor

Choose a reason for hiding this comment

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

If that can motivate someone to implement pluralization in Italian, just to break this test 😂

@fabpot
Copy link
Contributor

fabpot commented Jul 5, 2024

Thank you @welcoMattic.

@fabpot fabpot merged commit 0bbe173 into twigphp:3.x Jul 5, 2024
64 of 76 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants