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.

{{ cms.locale.get() }}{# e.g. en_US #}

Returns: string — the active locale code with an underscore separator (e.g., 'en_US')

Get the active locale as a BCP 47 language tag — the locale with its underscore converted to a hyphen (e.g., en_USen-US). This is the correct form for the HTML lang attribute; use it instead of get() on the <html> tag so screen readers, hyphenation, and spellcheck match the rendered language.

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

Returns: string — the active locale as a BCP 47 tag (e.g., 'en-US'). Falls back to 'en-US' when the intl extension is not available.

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