Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-01T16:14:09.680Z
Answers.Text: Thankyou Mats! I'd tried that technique but didn't realise `getLocaleByID()` accepted a string, I thought anything `getxxxById` required integers. My mistake.
Answers.UserDisplayName: Dr_Codswallop
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-02T00:51:44.977Z
Answers.Text: If it helps anyone else on Craft3, `locale.nativeName` will work for now but is deprecated. Use `locale.displayName` instead.
Answers.UserDisplayName: Dr_Codswallop
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-02T08:05:08.170Z
Answers.Text: 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
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-01T07:00:28.173Z
Answers.LastActivityDate: 2018-08-02T08:03:16.977Z
Answers.LastEditDate: 2018-08-02T08:03:16.977Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <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>
  
Tags: <craft3><localization><language>
Title: Getting full native language name in Craft 3 language switcher
ThreadText: # 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) %}
     <a href="{{url}}">{{ lang.language }}</a>
  {% 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`](http://awseb-e-f-awsebloa-1f9jh1rryyr2z-94257389.us-west-2.elb.amazonaws.com/api/v3/craft-models-site.html#property-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](https://docs.craftcms.com/api/v3/craft-i18n-i18n.html) to pull the actual [Locale](https://docs.craftcms.com/api/v3/craft-i18n-locale.html) object via that locale ID:
  
  ```
  {% set locale = craft.app.i18n.getLocaleById(lang.language) %}
  <a href="{{url}}">{{ locale.nativeName }}</a>
  
  ```
  
  **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 username_1! 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, @username_0 – 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  
  
  ---
  
  