Answers.Body: <p>The basics for setting up your localized site are nicely written down in the <a href="http://buildwithcraft.com/docs/localization-guide" rel="nofollow noreferrer">Localization Guide</a>. This walks you through the steps necessary to make your site being available under their subfolders <code>/de</code> and <code>/fr</code>.</p>
  
  <p>Set up correctly, your templates will always show the field content translated to the currently accessed locale.</p>
  
  <p>If your one-pager template is not connected to an entry (case 4 in the <a href="http://buildwithcraft.com/docs/routing" rel="nofollow noreferrer">Routing article</a>) and you simply save your template files at <code>templates/de/index.html</code> and <code>templates/fr/index.html</code> (case 6), have a look at the <a href="http://twig.sensiolabs.org/doc/tags/include.html" rel="nofollow noreferrer"><code>include</code></a> tag, that allows you to maintain one template responsible for all of your locales (e.g. <code>{% include '../de/index.html' %}</code>).</p>
  
  <p>The following code is a simplified version of the <a href="https://craftcms.stackexchange.com/a/882/125">example I wrote down here</a>, and should do fine for a one-page website:</p>
  
  <pre><code>{# Loop through selected site locales #}
  {% set locales = ['de', 'fr'] %}
  {% for locale in locales %}
  
      {# Check if `locale` equals the requested page locale #}
      {% if locale == craft.locale %}
          {% set current = true %}
      {% endif %}
  
      {# Output a link to the hompage and add a class "current" to the current locale's link #}
      &lt;a href="{{ craft.config.siteUrl[locale] }}" class="{{ current ? 'current' }}"&gt;{{ craft.i18n.getLocaleById(locale).name }}&lt;/a&gt;
  
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-03T12:44:07.763Z
Answers.LastActivityDate: 2014-12-03T12:56:50.950Z
Answers.LastEditDate: 2017-04-13T12:50:59.930Z
Answers.UserDisplayName: carlcs
Body: <p>I'm building a site with two languages, and I need a language switcher so wherever you enter the website you can switch the language easily. The website is a onepager, so i can't direct to a specific language URL. Instead i'm thinking of adding a segment (/de /fr) to the URL.</p>
  
  <p>I don't know how to display the language fields and language globals.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-12-03T12:53:44.513Z
Comments.Text: Samuel, I removed your question about the visitors' language setting in the browser, as this needs to go in a separate post. But this probaby gets covered by [Brandon's answer to a similar question](http://craftcms.stackexchange.com/a/2129/125) anyways.
Comments.UserDisplayName: carlcs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-12-03T21:50:32.233Z
Comments.Text: I think this question is not a dupe, that's why I added an answer. The difference is, that you do not necessarily switch between entries on a one page website. This changes / simplifies the logic.
Comments.UserDisplayName: carlcs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2014-12-07T22:58:09.290Z
Comments.Text: Noted, thanks @carlcs! We'll go ahead and reopen it.
Comments.UserDisplayName: Lindsey D
Tags: <localization>
Title: Build a language switcher for a one page website?
ThreadText: # Build a language switcher for a one page website?
  
  (Asked by: username_0 on 2014-12-03)
  
  I'm building a site with two languages, and I need a language switcher so wherever you enter the website you can switch the language easily. The website is a onepager, so i can't direct to a specific language URL. Instead i'm thinking of adding a segment (/de /fr) to the URL.
  
  I don't know how to display the language fields and language globals.
  
  **Tags:** localization
  
  > **Comments:**
  > **username_1**: username_0, I removed your question about the visitors' language setting in the browser, as this needs to go in a separate post. But this probaby gets covered by [Brandon's answer to a similar question](http://craftcms.stackexchange.com/a/2129/125) anyways.  
  > **username_1**: I think this question is not a dupe, that's why I added an answer. The difference is, that you do not necessarily switch between entries on a one page website. This changes / simplifies the logic.  
  > **username_2**: Noted, thanks @username_1! We'll go ahead and reopen it.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-12-03. Score: 1
  
  The basics for setting up your localized site are nicely written down in the [Localization Guide](http://buildwithcraft.com/docs/localization-guide). This walks you through the steps necessary to make your site being available under their subfolders `/de` and `/fr`.
  
  Set up correctly, your templates will always show the field content translated to the currently accessed locale.
  
  If your one-pager template is not connected to an entry (case 4 in the [Routing article](http://buildwithcraft.com/docs/routing)) and you simply save your template files at `templates/de/index.html` and `templates/fr/index.html` (case 6), have a look at the [`include`](http://twig.sensiolabs.org/doc/tags/include.html) tag, that allows you to maintain one template responsible for all of your locales (e.g. `{% include '../de/index.html' %}`).
  
  The following code is a simplified version of the [example I wrote down here](https://craftcms.stackexchange.com/a/882/125), and should do fine for a one-page website:
  
  ```
  {# Loop through selected site locales #}
  {% set locales = ['de', 'fr'] %}
  {% for locale in locales %}
  
      {# Check if `locale` equals the requested page locale #}
      {% if locale == craft.locale %}
          {% set current = true %}
      {% endif %}
  
      {# Output a link to the hompage and add a class "current" to the current locale's link #}
      <a href="{{ craft.config.siteUrl[locale] }}" class="{{ current ? 'current' }}">{{ craft.i18n.getLocaleById(locale).name }}</a>
  
  {% endfor %}
  
  ```
  
  
  ---
  
  