mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-26 08:56:20 +00:00
0bbe173d29
This PR was merged into the 3.x branch. Discussion ---------- [String] Add singularize and pluralize filter This PR follows up this one in Symfony https://github.com/symfony/symfony/pull/57245. It adds 2 new filters `singularize` and `pluralize`. It uses the String component, especially `EnglishInflector` and `FrenchInflector`. Examples: ```php {{ '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.') ``` Commits -------8c969d40Tweak code and docscb392489feat(string-extra): Add singularize and pluralize filter