<p>I forget to update locale template code with the same switch statement. Now problem solved.</p>

CC BY-SA 3.0
2018-04-15T10:03:27.813Z
2018-04-15T10:03:27.813Z
orionlogic
<p>I made a language picker, it works in one language but not in other. I want to get the current page of other locale. </p>

<pre><code>{% set locale = craft.i18n.getCurrentLocale() %}

 {% switch locale %}

  {% case 'en_us' %}
   &lt;a href="{{ craft.entries.id(entry.id).locale('de').first().url }}"&gt;Deutsch
  {% case 'de' %}
   &lt;a href="{{ craft.entries.id(entry.id).locale('en_us').first().url}}"&gt;English

 {% endswitch %}
</code></pre>

<p>Works in first case but not the second. What am i doing wrong?</p>

<p>Update: I forget to update the locale template in other language. Problem is solved, my mistake.</p>

CC BY-SA 3.0
2018-04-13T08:51:13.433Z
Have to ask: is the entry enabled for both locales?
Paul
CC BY-SA 3.0
2018-04-13T08:54:16.043Z
Yes all entries and sections enabled.
orionlogic
CC BY-SA 3.0
2018-04-13T09:07:23.113Z
And what happens in case the current locale is 'de'? Is that switch case even reached? What gets displayed if you put 'test' after {% case 'de' %}? Or if you do {{ dump(craft.entries.id(entry.id).locale('en_us').first()) }} there? Is devMode set to true, to see if any errors are thrown?
Paul
CC BY-SA 3.0
2018-04-13T09:31:01.980Z
Oh, i am so dumb. i forget to use the same code in other locale template! Thanks for helping.
orionlogic
CC BY-SA 3.0
2018-04-13T09:32:30.350Z
Wait, so you have a different template for each locale? In that case, you might try to include code snippets like the one above from a single source, so you don't have to change 'm for every locale.
Paul
CC BY-SA 3.0
2018-04-13T09:37:47.800Z
Yes i complete copy all templates. Although i have header template, my navigation have slight variance in different language. Will do your advice in my next project.
orionlogic
CC BY-SA 3.0
2018-04-14T23:20:02.537Z
Can you add your fix as an official answer, @orionlogic?
Brad Bell
<templating><localization>
Problem with switch statement in language picker - [Solved]
# Problem with switch statement in language picker - [Solved]

(Asked by: username_0 on 2018-04-13)

I made a language picker, it works in one language but not in other. I want to get the current page of other locale. 
{% set locale = craft.i18n.getCurrentLocale() %}

 {% switch locale %}

  {% case 'en_us' %}
   Deutsch
  {% case 'de' %}
   English

 {% endswitch %}

Works in first case but not the second. What am i doing wrong?
Update: I forget to update the locale template in other language. Problem is solved, my mistake.

**Tags:** templating, localization

> **Comments:**
> **username_1**: Have to ask: is the entry enabled for both locales?  
> **username_0**: Yes all entries and sections enabled.  
> **username_1**: And what happens in case the current locale is 'de'? Is that switch case even reached? What gets displayed if you put 'test' after {% case 'de' %}? Or if you do {{ dump(craft.entries.id(entry.id).locale('en_us').first()) }} there? Is devMode set to true, to see if any errors are thrown?  
> **username_0**: Oh, i am so dumb. i forget to use the same code in other locale template! Thanks for helping.  
> **username_1**: Wait, so you have a different template for each locale? In that case, you might try to include code snippets like the one above from a single source, so you don't have to change 'm for every locale.  
> **username_0**: Yes i complete copy all templates. Although i have header template, my navigation have slight variance in different language. Will do your advice in my next project.  
> **username_2**: Can you add your fix as an official answer, @username_0?  

---

## 1 answers

### Answer by username_0 on 2018-04-15. Score: 1 | Accepted answer

I forget to update locale template code with the same switch statement. Now problem solved.


---

