19

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?

Brandon Kelly
  • 34,307
  • 2
  • 71
  • 137

1 Answers1

21

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 }}
Brandon Kelly
  • 34,307
  • 2
  • 71
  • 137