I've got a bi-lingual site running nicely, /en/news/news-item displays the English version and /cy/news/news-item displays the Welsh version. Great!

I can't figure out how to get the URLs for the main site navigation to respect the currently used locale though. For example;

If I'm on the page: http://craft.dev/cy/news/news-title the main site navigation should list 'news' and 'artist' with a /cy preceding the URL (/cy/news and /cy/artists). Instead it's spitting out /en/news and /en/artists.

The code I'm using to get the URLs for the navigation is:

    <li><a href="{{ url('news') }}" {% if craft.request.firstSegment == 'news' %}class="active"{% endif %}>News</a></li>
    <li><a href="{{ url('artists') }}">Artists</a></li>

What am I doing wrong?

| improve this question | | | | |

Did you configure siteUrl in general.php, so Craft knows what the base URL is for your entries?

return array(
    'siteUrl' => array(
        'en' => 'http://craft.dev/en/',
        'cy' => 'http://craft.dev/cy/',
| improve this answer | | | | |
  • Yep, looks like this: gist.github.com/MattWilcox/… (oh man these comments are a PITA to format!) – Matt Wilcox Jul 16 '14 at 14:53
  • The first thing I'd try to do, is to remove that empty "non-locale" locale. – carlcs Jul 16 '14 at 16:40
  • I've removed that, no change. It's actually all links on the pages that are not using the correct locale prefix. It's odd; the page content itself is loading the correct locale, the links are not reflecting the correct locale. – Matt Wilcox Jul 17 '14 at 7:50
  • @Matt I found that there is not cy.php in framework/i18n/data, maybe that's the problem? But it probably shouldn't as this only contains the date and time translations. Try to simplify the general.php to the absolute minimum, check your "en" and "cy" index.php files and the sections' slug settings in the CP. Other then that, I've no clue what could be going wrong. – carlcs Jul 17 '14 at 13:03
  • I'd added the Welsh language files from the Yii library myself (though they're now included by default). I'll have to dig into this further on Monday. It doesn't look like anything is misconfigured, but I'll take your advice on stripping back. Thanks for the help. – Matt Wilcox Jul 19 '14 at 10:17

I found the problem. We use 'en' and 'gb' in the website's URLs (http://website.dev/en/whatever and http://website.dev/cy/whatever), and I'd mis-understood what Craft was looking for in the /craft/config/general.php setting - I'd put the 'site_url' values as those two-character codes - that's wrong.

In short, even though my URLs are en and cy, because the Locale values are actually en_gb and cy_gb, I needed to set the site_url array to those values (the URL has nothing to do with anything, which was what I'd mis-understood).

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.