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
getLocaleByID()accepted a string, I thought anythinggetxxxByIdrequired integers. My mistake. – Dr_Codswallop Aug 01 '18 at 16:14locale.nativeNamewill work for now but is deprecated. Uselocale.displayNameinstead. – Dr_Codswallop Aug 02 '18 at 00:51getLocaleById()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 togetLocaleByCodeor something similar :P – Mats Mikkel Rummelhoff Aug 02 '18 at 08:05