<p>The <a href="http://awseb-e-f-awsebloa-1f9jh1rryyr2z-94257389.us-west-2.elb.amazonaws.com/api/v3/craft-models-site.html#property-language" rel="nofollow noreferrer"><code>site.language</code></a> attribute is just a string, i.e. the language code or locale ID, e.g. <code>'en'</code>.</p>

<p>To get the native name you'll need to go through the <a href="https://docs.craftcms.com/api/v3/craft-i18n-i18n.html" rel="nofollow noreferrer"><code>I18N</code> service</a> to pull the actual <a href="https://docs.craftcms.com/api/v3/craft-i18n-locale.html" rel="nofollow noreferrer">Locale</a> object via that locale ID:</p>

<pre><code>{% set locale = craft.app.i18n.getLocaleById(lang.language) %}
&lt;a href="{{url}}"&gt;{{ locale.nativeName }}&lt;/a&gt;
</code></pre>

<p><strong>Edit:</strong> As @Dr_Codswallop mentions in the comments, <code>locale.nativeName</code> is deprecated in Craft 3, and will be removed completely in Craft 4. <code>locale.displayName</code> should be used instead.</p>

CC BY-SA 4.0
2018-08-01T16:14:09.680Z
Thankyou Mats! I'd tried that technique but didn't realise `getLocaleByID()` accepted a string, I thought anything `getxxxById` required integers. My mistake.
Dr_Codswallop
CC BY-SA 4.0
2018-08-02T00:51:44.977Z
If it helps anyone else on Craft3, `locale.nativeName` will work for now but is deprecated. Use `locale.displayName` instead.
Dr_Codswallop
CC BY-SA 4.0
2018-08-02T08:05:08.170Z
You're completely right, @Dr_Codswallop – thanks! And yeah, I agree that the `getLocaleById()` method name is a bit misleading/unconventional. Usually in Craft, "ID" refers to a unique (integer) ID. You should put in a feature request that they rename the method to `getLocaleByCode` or something similar :P
Mats Mikkel Rummelhoff
CC BY-SA 4.0
2018-08-01T07:00:28.173Z
2018-08-02T08:03:16.977Z
2018-08-02T08:03:16.977Z
Mats Mikkel Rummelhoff
<p>I'm porting across a multilingual project from Craft2 to Craft3 and have to rebuild the language switcher. I was previously using the <code>.nativeName</code> method but apparently this is deprecated. I've got a really basic one working for flipping between the English and French versions of my site :</p>

<pre><code>{% set langSwitcher = craft.app.sites.getAllSites() %}

{% for lang in langSwitcher %}
   {# Get base URL #}
   {% set url = alias(lang.baseUrl) %}
   &lt;a href="{{url}}"&gt;{{ lang.language }}&lt;/a&gt;
{% endfor %}
</code></pre>

<p>The <code>{{ lang.language }}</code> is outputting <code>en</code> &amp; <code>fr</code> but how do I get it to display the full native language names i.e <code>English</code> &amp; <code>Francais</code>?</p>

<p>I found the <code>getDisplayName()</code> function in the docs but can't seem to get it working properly: <a href="https://docs.craftcms.com/api/v3/craft-i18n-locale.html#public-methods" rel="nofollow noreferrer">https://docs.craftcms.com/api/v3/craft-i18n-locale.html#public-methods</a></p>

<craft3><localization><language>
Getting full native language name in Craft 3 language switcher
# Getting full native language name in Craft 3 language switcher

(Asked by: username_0 on 2018-08-01)

I'm porting across a multilingual project from Craft2 to Craft3 and have to rebuild the language switcher. I was previously using the .nativeName method but apparently this is deprecated. I've got a really basic one working for flipping between the English and French versions of my site :
{% set langSwitcher = craft.app.sites.getAllSites() %}

{% for lang in langSwitcher %}
   {# Get base URL #}
   {% set url = alias(lang.baseUrl) %}
   {{ lang.language }}
{% endfor %}

The {{ lang.language }} is outputting en & fr but how do I get it to display the full native language names i.e English & Francais?
I found the getDisplayName() function in the docs but can't seem to get it working properly: https://docs.craftcms.com/api/v3/craft-i18n-locale.html#public-methods

**Tags:** craft3, localization, language

---

## 1 answers

### Answer by username_1 on 2018-08-01. Score: 4 | Accepted answer

The site.language attribute is just a string, i.e. the language code or locale ID, e.g. 'en'.
To get the native name you'll need to go through the I18N service to pull the actual Locale object via that locale ID:
{% set locale = craft.app.i18n.getLocaleById(lang.language) %}
{{ locale.nativeName }}

Edit: As @Dr_Codswallop mentions in the comments, locale.nativeName is deprecated in Craft 3, and will be removed completely in Craft 4. locale.displayName should be used instead.

> **Comments:**
> **username_0**: Thankyou Mats! I'd tried that technique but didn't realise `getLocaleByID()` accepted a string, I thought anything `getxxxById` required integers. My mistake.  
> **username_0**: If it helps anyone else on Craft3, `locale.nativeName` will work for now but is deprecated. Use `locale.displayName` instead.  
> **username_1**: You're completely right, @Dr_Codswallop – thanks! And yeah, I agree that the `getLocaleById()` method name is a bit misleading/unconventional. Usually in Craft, "ID" refers to a unique (integer) ID. You should put in a feature request that they rename the method to `getLocaleByCode` or something similar :P  

---

