Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293279

Add format_plural to twig filters

$
0
0

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

  1. Add i18n extension
  2. Subclass the i18n extension and override it in a way that it maps to our functions
  3. Change the usage of gettext() to t() and format_plural().
  4. Then test or better even write a test that tests t() and format_plural from templates via {% trans %}
  5. 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.

Viewing all articles
Browse latest Browse all 293279

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>