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