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?

1
  • For anyone coming here for craft.locale: It's deprecated, use craft.app.language now. Commented Nov 20, 2019 at 9:43

1 Answer 1

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 }}
3
  • Nice Brandon! Can you please add how to access the i18n name for non-current locales? Let's say all I have is a string "de". Thanks
    – carlcs
    Commented Jul 10, 2014 at 1:36
  • @ChristianSeelbach updated ;) Commented Jul 10, 2014 at 12:54
  • Thanks! I now have to update this answer a 6th time ;)
    – carlcs
    Commented Jul 10, 2014 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.