Cecil supports text translation and date localization.
Use the trans tag or filter to translate texts in templates.
{% trans with variables into locale %}{% endtrans %}{{ message|trans(variables = []) }}{% trans %}Hello World!{% endtrans %}{{ message|trans }}Include variables:
{% trans with {'%name%': 'Arnaud'} %}Hello %name%!{% endtrans %}{{ message|trans({'%name%': 'Arnaud'}) }}Force locale:
{% trans into 'fr_FR' %}Hello World!{% endtrans %}Pluralize:
{% trans with {'%count%': 42} %}{0}I don't have apples|{1}I have one apple|]1,Inf[I have %count% apples{% endtrans %}Translation files must be named messages.<locale>.<extension> and stored in the translations directory.
Supported file extensions are defined by each translation format in layouts.translations.formats.
The locale code (e.g.: fr_FR) of a language is defined in the languages entries of the configuration. A file named with the language code only (e.g.: messages.fr.yaml) is also loaded, and the translations of the themes are merged with those of the site.
Example:
<my-site>
└─ translations
├─ messages.fr_FR.mo <- Machine Object format
└─ messages.fr_FR.yaml <- YAML format
:::info You can easily extract translations from your templates with the following command:
php cecil.phar util:translations:extract --locale=<code> --showUse --save instead of (or in addition to) --show to save the translations to a file. The --locale option is required. The default output format is yaml (use --format=po for gettext PO format).
:::
:::tip Poedit is a simple and cross-platform translation editor for gettext (PO), and Poedit Pro supports extraction of translation strings from templates out of the box. :::
:::important Translations are cached: the cache is refreshed when a translation file is updated or removed, but not when a new one is added.
Cache can be cleared with the following command:
php cecil.phar cache:clear:translations:::
Use the Twig format_date filter to localize a date in templates.
{{ page.date|format_date('long') }}
{# September 30, 2022 #}Supported values are: none, short, medium, long, and full.
The format_datetime and format_time filters are also available.
:::important If you want to use these filters with locales other than "en", you should install the intl PHP extension. :::