Answers.Body: <p>This is a rather hacky workaround, but I have no idea what else you could do to handle it. What I do is to compose an array of "route objects" that basically mirror the routes set up in the CP. This array can then be compared to the URL segments (→ <a href="http://buildwithcraft.com/docs/templating/craft.request#getSegments" rel="nofollow"><code>getSegments</code></a>). Not nice but it works :)</p>
  
  <pre><code>{# Map the corresponding routes #}
  {% set routes = [
      { en: 'news-events/tags', es: 'noticias-eventos/tags' },
      { en: 'news-events/categories', es: 'noticias-eventos/categorias' },
  ] %}
  
  {# Configure and loop through selected site locales #}
  {% set locales = ['en', 'es'] %}
  {% for locale in locales %}
  
      {# Is this an entry page? #}
      {% if entry is not defined %}
  
          {# ... Do entry stuff #}
  
      {# Not an entry page --&gt; check the routes #}
      {% else %}
  
          {# Get URL segments #}
          {% set segments = craft.request.getSegments %}
  
          {# Set var before loop #}
          {% set noRoute = true %}
  
          {# Loop routes array #}
          {% for prop in routes %}
  
              {# Check if URL segments match a route #}
              {% if prop[craft.locale]|split('/') == segments %}
  
                  {# Output link to the mapped route #}
                  &lt;a href="{{ craft.config.siteUrl[locale] ~ prop[locale] }}"&gt;{{ craft.i18n.getLocaleById(locale).name }}&lt;/a&gt;
  
                  {# Switch var value #}
                  {% set noRoute = false %}
  
              {% endif %}
  
          {% endfor %}
  
          {# No route found --&gt; output a link to the homepage #}
          {% if noRoute %}
              &lt;a href="{{ craft.config.siteUrl[locale] }}"&gt;{{ craft.i18n.getLocaleById(locale).name }}&lt;/a&gt;
          {% endif %}
  
      {% endif %}
  
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-11T00:40:47.510Z
Answers.Text: To clean this up a bit you could try to use the containment operator `in` instead of the `for` loop. Not the first time I fail on getting it to work with objects. I'm not sure what I am doing wrong, should be possible according to the [Twig docs](http://twig.sensiolabs.org/doc/templates.html#containment-operator).
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-12T17:35:23.333Z
Answers.Text: Thanks for the thoughtful response @carlcs. A great starting place.
Answers.UserDisplayName: Adam Snetman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-10-11T00:34:04.343Z
Answers.LastActivityDate: 2014-10-11T00:34:04.343Z
Answers.UserDisplayName: carlcs
Answers.Body: <p>I need something like this and found a solution: <a href="https://github.com/lindseydiloreto/craft-languagelink" rel="nofollow">craft-languagelink</a></p>
  
  <p><strong>UPDATE</strong>: This solution does not work for what Adam needs.  </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-06T13:13:46.543Z
Answers.Text: Can you please share how to set up the plugin to link from `news-events/tags` to `noticias-eventos/tags` if the pages are no entry pages?
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-06-23T01:04:21.667Z
Answers.Text: sorry, @carlcs I got it wrong, and also need something and it did not work.
Answers.UserDisplayName: Luiz Boaretto
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-24T02:45:45.360Z
Answers.LastActivityDate: 2016-06-23T01:02:30.073Z
Answers.LastEditDate: 2016-06-23T01:02:30.073Z
Answers.UserDisplayName: Luiz Boaretto
Body: <p>I'm working on a multilingual site with english and spanish locales. I've built persistent switcher that resides in the site footer. When users click it, it redirects to a corresponding entry in the other locale if one exists and the homepage if one does not.</p>
  
  <p>The problem is that I have a handful of pages on my site that aren't entries: they are routes that are tied to particular templates. For example:</p>
  
  <p><code>news-events/tags</code></p>
  
  <p>Is the route for a template that lists all tags in use in my news section, and:</p>
  
  <p><code>noticias-eventos/tags</code></p>
  
  <p>would be the corresponding route on the spanish site.</p>
  
  <p>I'd like to be able to check if the current uri is covered by a route and if so, whether there is a corresponding route in the other locale. If so, I'd redirect to that and if not, back to the homepage as per usual.</p>
  
  <p>But from what I can see, routes are not localizable and exist independently of each other. Am I wrong? How would I go about this?</p>
  
Tags: <localization><routes>
Title: How do I redirect to a corresponding route when user switches languages?
ThreadText: # How do I redirect to a corresponding route when user switches languages?
  
  (Asked by: username_0 on 2014-10-10)
  
  I'm working on a multilingual site with english and spanish locales. I've built persistent switcher that resides in the site footer. When users click it, it redirects to a corresponding entry in the other locale if one exists and the homepage if one does not.
  
  The problem is that I have a handful of pages on my site that aren't entries: they are routes that are tied to particular templates. For example:
  
  `news-events/tags`
  
  Is the route for a template that lists all tags in use in my news section, and:
  
  `noticias-eventos/tags`
  
  would be the corresponding route on the spanish site.
  
  I'd like to be able to check if the current uri is covered by a route and if so, whether there is a corresponding route in the other locale. If so, I'd redirect to that and if not, back to the homepage as per usual.
  
  But from what I can see, routes are not localizable and exist independently of each other. Am I wrong? How would I go about this?
  
  **Tags:** localization, routes
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2014-10-11. Score: 3
  
  This is a rather hacky workaround, but I have no idea what else you could do to handle it. What I do is to compose an array of "route objects" that basically mirror the routes set up in the CP. This array can then be compared to the URL segments (→ [`getSegments`](http://buildwithcraft.com/docs/templating/craft.request#getSegments)). Not nice but it works :)
  
  ```
  {# Map the corresponding routes #}
  {% set routes = [
      { en: 'news-events/tags', es: 'noticias-eventos/tags' },
      { en: 'news-events/categories', es: 'noticias-eventos/categorias' },
  ] %}
  
  {# Configure and loop through selected site locales #}
  {% set locales = ['en', 'es'] %}
  {% for locale in locales %}
  
      {# Is this an entry page? #}
      {% if entry is not defined %}
  
          {# ... Do entry stuff #}
  
      {# Not an entry page --> check the routes #}
      {% else %}
  
          {# Get URL segments #}
          {% set segments = craft.request.getSegments %}
  
          {# Set var before loop #}
          {% set noRoute = true %}
  
          {# Loop routes array #}
          {% for prop in routes %}
  
              {# Check if URL segments match a route #}
              {% if prop[craft.locale]|split('/') == segments %}
  
                  {# Output link to the mapped route #}
                  <a href="{{ craft.config.siteUrl[locale] ~ prop[locale] }}">{{ craft.i18n.getLocaleById(locale).name }}</a>
  
                  {# Switch var value #}
                  {% set noRoute = false %}
  
              {% endif %}
  
          {% endfor %}
  
          {# No route found --> output a link to the homepage #}
          {% if noRoute %}
              <a href="{{ craft.config.siteUrl[locale] }}">{{ craft.i18n.getLocaleById(locale).name }}</a>
          {% endif %}
  
      {% endif %}
  
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_1**: To clean this up a bit you could try to use the containment operator `in` instead of the `for` loop. Not the first time I fail on getting it to work with objects. I'm not sure what I am doing wrong, should be possible according to the [Twig docs](http://twig.sensiolabs.org/doc/templates.html#containment-operator).  
  > **username_0**: Thanks for the thoughtful response @username_1. A great starting place.  
  
  ---
  
  ### Answer by username_2 on 2016-05-24. Score: 2
  
  I need something like this and found a solution: [craft-languagelink](https://github.com/lindseydiloreto/craft-languagelink)
  
  **UPDATE**: This solution does not work for what username_0 needs.
  
  > **Comments:**
  > **username_1**: Can you please share how to set up the plugin to link from `news-events/tags` to `noticias-eventos/tags` if the pages are no entry pages?  
  > **username_2**: sorry, @username_1 I got it wrong, and also need something and it did not work.  
  
  ---
  
  