When I output {{ craft.locale }}
in my template, I get the current locale’s ID (e.g. “en”) rather than its name (e.g. “English”).
How do I get the locale’s name?
You can get the current locale’s name via craft.i18n.getCurrentLocale()
.
{% set locale = craft.i18n.getCurrentLocale() %}
{{ locale.name }}
That will output the name using the current locale’s translation.
If you would prefer to output the locale’s name in its native tongue, use nativeName
instead:
{{ locale.nativeName }}
You can also output the name of any locale using (not necessarily the current one) using craft.i18n.getLocaleById()
:
{% set locale = craft.i18n.getLocaleById(entry.locale) %}
{{ locale.name }}
{{ locale.nativeName }}
craft.locale
: It's deprecated, usecraft.app.language
now.