Cecil logo Cecil
What's on this page

Localization

Cecil supports text translation and date localization.

Text translation

Use the trans tag or filter to translate texts in templates.

{% trans with variables into locale %}{% endtrans %}
{{ message|trans(variables = []) }}

Examples

{% 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

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

Date localization

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.