We've retired the forum in favor of GitHub Discussions.

New conversations can be started on GitHub. Existing conversations will remain for a while longer.

Head over to GitHub →

Language Switcher

Peter Emil van den Berg November 20, 2017 by Peter Emil van den Berg

In continuation of https://statamic.com/forum/2525-localize-theme-partials I'm stuck creating a language switcher. I know the answer has to be quite easy, as I am yet to learn the tags of Statamic and the explanation of locales on https://docs.statamic.com/tags/locales is too compact for me now. This is what I like to see in my nav: when viewing Dutch show me the View in English button, and when viewing English show me the View in Dutch button. This is my code:

{{ locales }}
    {{ if locale == 'nl' }}
        <li><a href="{{ url }}">{{ locale:en }}</a></li>
    {{ else }}
        <li><a href="{{ url }}">{{ locale:nl }}</a></li>
    {{ /if }}
 {{ /locales }}

which results in showing always both buttons, no matter which language is being viewed.

Can anyone put me in the right direction?

Answered by Peter Rainer!
>>>>>>> Answered <<<<<<<
8 Replies