Skip to content

Twig Locale Reference

The locale adapter provides localization and translation methods for internationalized templates. For broader i18n concepts and setup, see Localization.

Get the list of supported languages as a name-to-locale mapping.

{% set langs = cms.locale.languages() %}
<select name="language">
{% for name, code in langs %}
<option value="{{ code }}">{{ name }}</option>
{% endfor %}
</select>

Returns: array<string, string> — language display name to locale code (e.g., {'English': 'en_US', 'Deutsch': 'de_DE'})

Set the active locale for the current request. Requires the PHP intl extension.

{{ cms.locale.set('de_DE') }}
ParameterTypeDescription
localestringLocale code (e.g., 'en_US', 'de_DE', 'fr_FR')

Returns: string — empty string (for use in output context)

Get the current active locale. Defaults to 'en_US' if the intl extension is not available.

<html lang="{{ cms.locale.get() }}">

Translate a key from the admin translation domain. Supports parameter interpolation.

{{ cms.locale.t('save') }}
{{ cms.locale.t('welcome_message', {name: user.name}) }}
{{ cms.locale.t('item_count', {count: items|length}) }}
ParameterTypeDefaultDescription
keystringrequiredTranslation key
paramsarray[]Parameters to interpolate into the translation

Alias for t().

{{ cms.locale.translate('save') }}

Get all translations as a flat array for use in JavaScript. Useful for passing translations to frontend code.

<script>
window.translations = {{ cms.locale.jsTranslations()|json_encode|raw }};
</script>

Returns: array<string, string> — key-value pairs of all translations