Answers.Body: <p>I forget to update locale template code with the same switch statement. Now problem solved.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-04-15T10:03:27.813Z
Answers.LastActivityDate: 2018-04-15T10:03:27.813Z
Answers.UserDisplayName: orionlogic
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-13T08:51:13.433Z
Comments.Text: Have to ask: is the entry enabled for both locales?
Comments.UserDisplayName: Paul
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-13T08:54:16.043Z
Comments.Text: Yes all entries and sections enabled.
Comments.UserDisplayName: orionlogic
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-13T09:07:23.113Z
Comments.Text: 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?
Comments.UserDisplayName: Paul
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-13T09:31:01.980Z
Comments.Text: Oh, i am so dumb. i forget to use the same code in other locale template! Thanks for helping.
Comments.UserDisplayName: orionlogic
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-13T09:32:30.350Z
Comments.Text: 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.
Comments.UserDisplayName: Paul
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-13T09:37:47.800Z
Comments.Text: 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.
Comments.UserDisplayName: orionlogic
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-04-14T23:20:02.537Z
Comments.Text: Can you add your fix as an official answer, @orionlogic?
Comments.UserDisplayName: Brad Bell
Tags: <templating><localization>
Title: Problem with switch statement in language picker - [Solved]
ThreadText: # 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' %}
     <a href="{{ craft.entries.id(entry.id).locale('de').first().url }}">Deutsch
    {% case 'de' %}
     <a href="{{ craft.entries.id(entry.id).locale('en_us').first().url}}">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.
  
  
  ---
  
  