2

I`ve got a multilingual site (DE/EN) with a Structures section (pages) and one Single for the homepage.

In general.php I set up my localized site as described in the docs for a multi-environment config. German at the top level; English from en/ subfolder:

'domain.dev' => array(
    'siteUrl' => array(
        'de' => 'http://domain.dev/',
        'en' => 'http://domain.dev/en/',
    ),
),  

Within my public html folder I copied .htaccess and index.php to en/ and added define('CRAFT_LOCALE', 'en'); to index.php

Navigating to domain.dev shows the german pages:

  • Seite 1
  • Seite 2
  • Seite 3

Changing the URL manually to domain.dev/en/ shows their right translations

  • Page 1
  • Page 2
  • Page 3

and also their right links, e.g. http://domain.dev/en/page-1

BUT following the link to domain.dev/en/page-1 the german content shows up again and the navigation switches back to german.

{% set pages = craft.entries.section('pages').level(1) %}
<nav>
    <ul>
        {% for page in pages %}
            <li>{{ page.getLink() }}</li>
        {% endfor %}
    </ul>
</nav>

Going to any other english page (e.g. domain.dev/en/page-2) doesn't show up the english content (a translatable field) at all but neither the german content. So I think there is something wrong with my localization setup. Any ideas? Thanks much!


UPDATE

I set up a new craft installation and also a Localized Site as described in the docs. When defining the site URLs this way everything works like a charm:

return array(
    'siteUrl' => array(
        'de' => 'http://craft.dev/',
        'en' => 'http://craft.dev/en/',
    ),
);

in combination with my multi-environment config it is not working.

return array(
    'craft.dev' => array(
        'siteUrl' => array(
            'de' => 'http://craft.dev/',
            'en' => 'http://craft.dev/en/',
        ),
    ),
);

So I think my config is missing something to transmit the locale the right way?

Is there another way to set up a localized site with multi-environment config?

5
  • When you setup your second locale, did you set it up as generic "English", or something more specific like "English - United States" or "English - Great Britain"? Make sure that your locale code is actually en, and not en_us or en_gb. If it is a country-specific code, then just change the code specified in your index.php file.
    – Lindsey D
    Mar 9, 2015 at 16:55
  • On a related note, yesterday I released a new Language Link plugin, designed to make switching between languages a much easier process.
    – Lindsey D
    Mar 9, 2015 at 17:03
  • I set it up as generic English (en) and double checked the index.php. With the Language Link Plugin I had the same problems.. so I really think it is a configuration thing.
    – Patte
    Mar 9, 2015 at 19:50
  • 1
    multi-environment config needs to have the * key: return array('*' => array(), 'craft.dev' => array(...)); Mar 10, 2015 at 17:31
  • @MarionNewlevant You may want to submit that as a formal answer... I suspect that's the actual solution to the problem!
    – Lindsey D
    Mar 10, 2015 at 19:35

2 Answers 2

2

A multi-environment config needs to have a * key. This might work:

return array(
  '*' => array(),
  'craft.dev' => array(
    'siteUrl' => array(
      'de' => 'http://craft.dev/',
       en' => 'http://craft.dev/en/',
    ),
  ),
);
0
1

You may want to specify the locale of your nav links... craft.locale is the current locale.

{% set pages = craft.entries.section('pages').locale(craft.locale).level(1) %}
<nav>
    <ul>
        {% for page in pages %}
            <li>{{ page.getLink() }}</li>
        {% endfor %}
    </ul>
</nav>

There are many different ways to create language links, several of which are described in this thread...

2
  • Thanks for your help. Unfortunately this isn`t working, too, when having a multi-environment config. Navigating to an english page, e.g. craft.dev/en/page-1, results in links like craft.dev/page-2, without the locale in it. This behavior seems to depend on my config.
    – Patte
    Mar 10, 2015 at 11:15
  • Sounds like you may have hit a snag in Step 4: Define your site URLs...
    – Lindsey D
    Mar 10, 2015 at 19:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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