eddiejaoude/eddie-jaoude-symfony-translation-twig-collection-bundle

Symfony Translation Bundle for Twig Extension to handle collection

2.6.0 2015-01-11 10:32 UTC

This package is not auto-updated.

Last update: 2024-07-06 14:59:19 UTC


README

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version Total Downloads Latest Unstable Version License

DashboardHub Badge

Symfony Translation Twig Collection Bundle

Symfony Translation Bundle for Twig Extension to handle collection

Version Branch Latest Release
Symfony 2.2+ 2.2 v2.2.0
Symfony 2.6+ 2.6 v2.6.0

Installation

  1. Composer
   "require": {
       "eddiejaoude/eddie-jaoude-symfony-translation-twig-collection-bundle": "dev-master"
   }
  1. Run update
php composer.phar update
  1. Add to AppKernel
   $bundles = array(
   // ...
   new EddieJaoude\Bundle\SymfonyTranslationTwigCollectionBundle\EddieJaoudeSymfonyTranslationTwigCollectionBundle(),
   // ...
   )

Usage

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

Credits

Inspired by acontell http://stackoverflow.com/questions/27868921/symfony2-translation-yaml-array-and-twig-loop