getgrav / grav-plugin-langswitcher

Grav LangSwitcher Plugin
https://getgrav.org
MIT License
28 stars 26 forks source link

Change shown name of language in language switcher #25

Closed kingemir closed 7 years ago

kingemir commented 7 years ago

for zh (chinese)

中文 (简体)

is shown. That means simplified chinese. Where does the plugin get this information from? How can I let it show

中文

(chinese) instead?

It's annoying especially when using zh-cn for traditional chinese, which shows

中文 (简体) (cn)

flaviocopes commented 7 years ago

It gets it from an internal reference, you can't change it. But you can override the Twig https://github.com/getgrav/grav-plugin-langswitcher/blob/develop/templates/partials/langswitcher.html.twig#L14 in your theme, copying it to user/themes/yourtheme/templates/partials and change it to, for example:

...
    {% set lang_name = native_name(key) %}
    {% if lang_name == 'zh' %}
      {% set lang_name = '中文' %}
    {% endif %}
    <li><a href="{{ lang_url ~ uri.params }}" class="external{{ active_class }}">{{  lang_name|capitalize }}</a></li>
...
kingemir commented 7 years ago

Could you please specify your answer, or provide the entire code for user/themes/yourtheme/templates/partials/langswitcher.html.twig, because adding your code or replacing the initial code with your code doesn't provoke the desired result. Thanks.

Since the internal reference of the plugin contains wrong information, it should be fixed:

These language tags follow the W3C standards (Language subtag plus Script subtag)

sunfree-lighting commented 6 years ago

Hi,

the entire code below works. my language tag is cn and en. NOT zh-cn. PS: just change {% set lang_name = native_name(key) %} to {% set lang_name = native_name(language) %}

The entire code are: