Symfony Translation Bundle for Twig Extension to handle collection
- Composer
"require": {
"eddiejaoude/eddie-jaoude-symfony-translation-twig-collection-bundle": "dev-master"
}
- Run update
php composer.phar update
- Add to AppKernel
$bundles = array(
// ...
new EddieJaoude\Bundle\SymfonyTranslationTwigCollectionBundle\EddieJaoudeSymfonyTranslationTwigCollectionBundle(),
// ...
)
Translation file (eg. messages.en.yml
)
termsAndConditions:
title: Terms and Conditions
paragraph:
- Terms Information 1
- Terms Information 2
- Terms Information 3
- Terms Information 4
...
Twig template (eg. index.html.twig
)
{% for i in range(0,'termsAndConditions.paragraph'|translationLength) -%}
<p>{{('termsAndConditions.paragraph.'~i)|trans}}</p>
{%- endfor %}
Output
Terms Information 1
Terms Information 2
Terms Information 3
Terms Information 4
Inspired by acontell http://stackoverflow.com/questions/27868921/symfony2-translation-yaml-array-and-twig-loop