GithubHelp home page GithubHelp logo

eddiejaoude / symfony-translation-twig-collection-bundle Goto Github PK

View Code? Open in Web Editor NEW
12.0 2.0 5.0 272 KB

Symfony Translation Bundle for Twig Extension to handle collection

License: MIT License

PHP 100.00%

symfony-translation-twig-collection-bundle's Introduction

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

symfony-translation-twig-collection-bundle's People

Contributors

eddiejaoude avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

symfony-translation-twig-collection-bundle's Issues

Failing Spec

Error Travis CI

EddieJaoude/Bundle/SymfonyTranslationTwigCollectionBundle/Twig/TranslationLength  
Extension                                                                       
  32  - it get the translation length filter
      method `Double\Symfony\Component\Translation\LoggingTranslator\P4::getMessages()` is not defined.

                            75%                                     25%          4
1 specs
4 examples (3 passed, 1 broken)
356ms

Spec

    function it_get_the_translation_length_filter(LoggingTranslator $translator)
    {
        $translator
            ->getMessages()
            ->shouldBeCalled()
            ->willReturn(
                array(
                    'messages' => array('information 1', 'information 2', 'information 3')
                )
            );
        $this->beConstructedWith($translator);

        $this->translationLengthFilter('translate.me')->shouldReturn(3);
    }

Code

    public function translationLengthFilter($id)
    { 
        $total = 0;
        foreach ($this->translator->getMessages()['messages'] as $position => $message) {
            if (substr($position, 0, strlen($id)) === $id) {
                $total++;
            }
        }

        return $total - 1;
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.