<p>Turns out the issue was my config set incorrectly. I was doing this:</p>

<pre><code>'siteUrl' =&gt; array(
    'en' =&gt; 'http://website.dev/en',
    'en-gb' =&gt; 'http://website.dev/en-gb',
    'en-us' =&gt; 'http://website.dev/en-us',
    'en-au' =&gt; 'http://website.dev/en-au',
    'en-nz' =&gt; 'http://website.dev/en-nz'
),
</code></pre>

<p>When the array keys need to match the way they are set in craft with underscores (and your public/locale/index.php file)</p>

<pre><code>'siteUrl' =&gt; array(
    'en' =&gt; 'http://website.dev/en',
    'en_gb' =&gt; 'http://website.dev/en-gb',
    'en_us' =&gt; 'http://website.dev/en-us',
    'en_au' =&gt; 'http://website.dev/en-au',
    'en_nz' =&gt; 'http://website.dev/en-nz'
),
</code></pre>

CC BY-SA 3.0
2017-02-08T09:48:44.297Z
2017-02-08T09:48:44.297Z
joe
<p>I'm trying to loop on locales to get the path to the current entry, but for the other locales (for a language switcher).</p>

<p>Here is my code:</p>

<pre><code>{% set locales = craft.i18n.getSiteLocales() %}
{% for locale in locales %}

    {% set localeEntry = craft.entries.id(entry.id).locale(locale.id).first %}

        {{dump(localeEntry.locale)}}
        {{dump(localeEntry.getUrl()) }}

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

<p>Results:</p>

<pre><code>"en"
"http://website.dev/en/page"

"en_gb"
"http://website.dev/en/page"

"en_us"
"http://website.dev/en/page"

"de"
"http://website.dev/de/page"
</code></pre>

<p>The language only versions are fine <code>en</code> and <code>de</code>, though the language-location versions are incorrect. These are all set correctly in my config.</p>

<p>What am I doing wrong here?</p>

CC BY-SA 3.0
2017-02-07T18:08:15.053Z
In your channel section, how did you define your url-format for your different locales?
Jan_dh
CC BY-SA 3.0
2017-02-08T09:15:02.483Z
Different for quite a few sections, sometimes just `{slug}`, sometimes `news/{slug}`. I never put `{locale}` in if that's what you're curious about? I've seen that isn't recommended.
joe
CC BY-SA 3.0
2017-02-08T10:36:40.000Z
Nevermind, sorted it.
joe
<templating><localization><language>
locale loop doesn't get correct path
# locale loop doesn't get correct path

(Asked by: username_0 on 2017-02-07)

I'm trying to loop on locales to get the path to the current entry, but for the other locales (for a language switcher).
Here is my code:
{% set locales = craft.i18n.getSiteLocales() %}
{% for locale in locales %}

    {% set localeEntry = craft.entries.id(entry.id).locale(locale.id).first %}

        {{dump(localeEntry.locale)}}
        {{dump(localeEntry.getUrl()) }}

{% endfor %}

Results:
"en"
"http://website.dev/en/page"

"en_gb"
"http://website.dev/en/page"

"en_us"
"http://website.dev/en/page"

"de"
"http://website.dev/de/page"

The language only versions are fine en and de, though the language-location versions are incorrect. These are all set correctly in my config.
What am I doing wrong here?

**Tags:** templating, localization, language
> **Comments:**
> **username_1**: In your channel section, how did you define your url-format for your different locales?  
> **username_0**: Different for quite a few sections, sometimes just `{slug}`, sometimes `news/{slug}`. I never put `{locale}` in if that's what you're curious about? I've seen that isn't recommended.  
> **username_0**: Nevermind, sorted it.  

---

## 1 answers

### Answer by username_0 on 2017-02-08. Score: 2 | Accepted answer

Turns out the issue was my config set incorrectly. I was doing this:
'siteUrl' => array(
    'en' => 'http://website.dev/en',
    'en-gb' => 'http://website.dev/en-gb',
    'en-us' => 'http://website.dev/en-us',
    'en-au' => 'http://website.dev/en-au',
    'en-nz' => 'http://website.dev/en-nz'
),

When the array keys need to match the way they are set in craft with underscores (and your public/locale/index.php file)
'siteUrl' => array(
    'en' => 'http://website.dev/en',
    'en_gb' => 'http://website.dev/en-gb',
    'en_us' => 'http://website.dev/en-us',
    'en_au' => 'http://website.dev/en-au',
    'en_nz' => 'http://website.dev/en-nz'
),


---

