Quick reminder for translations with catalogs and Twig

Hi,

I recently had to translate a whole part of my website. Many reasons can conduct you to this need: internationalization, easy access and modification of hard written content, replication of your business in some other sectors etc.

Here are a few tips and structure I use to increase efficiency:

I always put specific translations in the folder under XXXBundle/Ressources/translations For general translations I put it in App/Ressources/translations

File names are functionality.en.yml (replace EN with whatever you want).

In every doc I use, I set the main translation domain with {% trans_default_domain “MY_FILE_NAME” %} at the beginning.

I call the translator with {{ ‘something_to_translate’ | trans | raw }}. Raw allows me to write directly html in the translation file. Very useful to show long texts.

Every time I need to translate global text, I use {{ ‘something_to_translate’ | trans({}, ‘global_functionnality’) | raw }}

The architecture of a translation file is:

feature:
    option1:

Which is called by {{ ‘feature.option1’ | trans | raw }}

Leave a Reply

Your email address will not be published. Required fields are marked *