Problem/Motivation
format_plural would be nice to have in the twig files instead of preprocessors.
Proposed resolution
Add format_plural
to twig filters list
Map i18n trans block to drupal format_plural() if has plural in it and drupal t() if not.
Map new format_plural formatter to format_plural() without the 3rd and 4th args.
Tasks
- Add i18n extension
- Subclass the i18n extension and override it in a way that it maps to our functions
- Change the usage of gettext() to t() and format_plural().
- Then test or better even write a test that tests t() and format_plural from templates via {% trans %}
- Update docs
References
http://twig.sensiolabs.org/doc/extensions/i18n.html
http://twig.sensiolabs.org/doc/advanced.html#creating-an-extension
http://twig.sensiolabs.org/doc/advanced.html#overloading
https://github.com/fabpot/Twig-extensions
Example syntax:
https://gist.github.com/joelpittet/742f9ee5c9c6ac41c39e
class I18nTwigExtension extends I18n_Twig_Extension
// And then add our drupal specific overrides there.