php - How to use config value in symfony2 translation? -


is possible use global variable config.yml in translation file in symfony 2? if yes, please can give example or useful link?

you can follow 2 simple steps:

  1. inject global variable in templates using twig configuration:

    # app/config/parameters.yml parameters:     my_favorite_website: www.stackoverflow.com 

    and

    # app/config/config.yml twig:     globals:         my_favorite_website: "%my_favorite_website%" 
  2. use message placeholders have ability place text in translation:

    # messages.en.yml i.love.website: "i love %website%!!"  # messages.fr.yml i.love.website: "j'adore %website%!!" 

you can use following twig syntax in templates expected result:

{{ 'i.love.website'|trans({'%website%': my_favorite_website}) }} 

Comments