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

用于处理集合的 Symfony 翻译 Bundle for Twig 扩展

2.6.0 2015-01-11 10:32 UTC

This package is not auto-updated.

Last update: 2024-09-28 16:10:15 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 翻译 Bundle for Twig 扩展

安装

  1. Composer
   "require": {
       "eddiejaoude/eddie-jaoude-symfony-translation-twig-collection-bundle": "dev-master"
   }
  1. 运行更新
php composer.phar update
  1. 添加到 AppKernel
   $bundles = array(
   // ...
   new EddieJaoude\Bundle\SymfonyTranslationTwigCollectionBundle\EddieJaoudeSymfonyTranslationTwigCollectionBundle(),
   // ...
   )

使用方法

翻译文件(例如 messages.en.yml

termsAndConditions:
  title: Terms and Conditions
  paragraph:
    - Terms Information 1
    - Terms Information 2
    - Terms Information 3
    - Terms Information 4
    ...

Twig 模板(例如 index.html.twig

{% for i in range(0,'termsAndConditions.paragraph'|translationLength) -%}
    <p>{{('termsAndConditions.paragraph.'~i)|trans}}</p>
{%- endfor %}

输出

Terms Information 1
Terms Information 2
Terms Information 3
Terms Information 4

致谢

灵感来自 acontell http://stackoverflow.com/questions/27868921/symfony2-translation-yaml-array-and-twig-loop