Getting full native language name in Craft3 language switcher 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) %}
   &lt;a href="{{url}}"&gt;{{ lang.language }}&lt;/a&gt;
{% endfor %}


The {{ lang.language }} is outputting en &amp; fr but how do I get it to display the full native language names i.e English &amp; 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
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) %}
&lt;a href="{{url}}"&gt;{{ locale.nativeName }}&lt;/a&gt;


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.