<p>I think this is partially related to a question I raised recently, even though my site won't have that many languages per country but some countries will have 2 languages.</p>

<p><a href="https://craftcms.stackexchange.com/questions/2234/how-can-i-add-in-new-locales-to-the-locale-list/2242#2242" title="How can I add in new Locales to the locale list?">How can I add in new Locales to the locale list?</a></p>

<p>Then you would do something like this in your config</p>

<pre><code>return array(
    'example.com' =&gt; array(
        'siteUrl' =&gt; array(
            // Global locales
            'en' =&gt; 'http://example.com/en/',
            'es' =&gt; 'http://example.com/es/',
            'fr' =&gt; 'http://example.com/fr/',
            'de' =&gt; 'http://example.com/de/',

            // Canada locales
            'ca_en' =&gt; 'http://ca.example.com/en/',
            'ca_es' =&gt; 'http://ca.example.com/es/',
            'ca_fr' =&gt; 'http://ca.example.com/fr/',
            'ca_de' =&gt; 'http://ca.example.com/de/',

            // UK locales
            'gb_en' =&gt; 'http://uk.example.com/en/',
            'gb_es' =&gt; 'http://uk.example.com/es/',
            'gb_fr' =&gt; 'http://uk.example.com/fr/',
            'gb_de' =&gt; 'http://uk.example.com/de/',
        ),
    ),
);
</code></pre>

<p>This should work, I haven't tested it as yet as my site is still in planning stages and I have not gotten into the development phase as yet.</p>

<p><strong>Edited answer based on comment.</strong></p>

<p>For all countries to use the same English, you can set your array to look like below, however this will not allow individual countries to have different English copy since we are pointing them all to the same Locale now.</p>

<pre><code>return array(
    'example.com' =&gt; array(
        'siteUrl' =&gt; array(
            // Global locales
            'en' =&gt; 'http://example.com/en/',
            'es' =&gt; 'http://example.com/es/',
            'fr' =&gt; 'http://example.com/fr/',
            'de' =&gt; 'http://example.com/de/',

            // Canada locales
            'en' =&gt; 'http://ca.example.com/en/',
            'ca_es' =&gt; 'http://ca.example.com/es/',
            'ca_fr' =&gt; 'http://ca.example.com/fr/',
            'ca_de' =&gt; 'http://ca.example.com/de/',

            // UK locales
            'en' =&gt; 'http://uk.example.com/en/',
            'gb_es' =&gt; 'http://uk.example.com/es/',
            'gb_fr' =&gt; 'http://uk.example.com/fr/',
            'gb_de' =&gt; 'http://uk.example.com/de/',
        ),
    ),
);
</code></pre>

CC BY-SA 3.0
2014-08-30T16:10:36.307Z
Thanks Andrew this is super helpful as is your related article. However, there will be 23 countries all using the same english, french translation etc. If I use the solution above won't that require that I enter a "french" translation 23 times per entry?
Adam
CC BY-SA 3.0
2014-08-30T19:57:50.000Z
My solution above would still work, but now that you clarify that all 23 countries will use the same english I will edit the answer to make it encompass that requirement.
Andrew Smith
CC BY-SA 3.0
2014-08-30T16:00:53.390Z
2014-08-30T20:01:22.553Z
2017-04-13T12:51:00.253Z
Andrew Smith
<p>What you could do to enable / disable entries from the Control Panel is to add a <a href="http://buildwithcraft.com/docs/lightswitch-fields" rel="nofollow">lightswitch field</a> to the entry type and use it as a ElementCriteriaModel parameter. You'd need one custom lightswitch for each country (additionally to the language lightswitches provided by Craft's localization feature).</p>

<p>To filter your elements with the right "country lightswitch" in your templates, you first have to figure out what country / subdomain the page is accessed from. Something you can do by requesting the <code>siteUrl</code> variable and use Twig filters (e.g. <a href="http://twig.sensiolabs.org/doc/filters/split.html" rel="nofollow"><code>slice</code></a>) to put the string into shape.</p>

<p>Now you can conditionally filter with the lightswitch relevant for the currently accessed country:</p>

<pre><code>{# Cut the `siteUrl` string into shape #}
{% set subDomain = siteUrl|split('/')[2]|split('.')[0] %}

{# Conditionally create the ElementCriteriaModel #}
{% switch subDomain %}

    {% case 'us' %}
        {% set entries = craft.entries.section('news').subDomainUS('1') %}

    {% case 'ca' %}
        {% set entries = craft.entries.section('news').subDomainCA('1') %}

    {% case 'uk' %}
        {% set entries = craft.entries.section('news').subDomainUK('1') %}

    {# No match found --&gt; global domain #}
    {% default %}
        {% set entries = craft.entries.section('news').globalSite('1') %}

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

CC BY-SA 3.0
2014-08-31T16:07:14.410Z
2014-08-31T16:07:14.410Z
carlcs
<p>I'm trying to setup a multi country site running off one Craft install. </p>

<p>example.com<br />
ca.example.com<br />
uk.example.com<br /></p>

<p>Each countries content will be translated into five languages (English - en, Spanish - es, French - fr, German - de, Japanese - ja). </p>

<p>example.com/en<br />
example.com/es<br />
example.com/fr<br />
example.com/de<br />
example.com/ja<br /></p>

<p>ca.example.com/en<br />
ca.example.com/es<br />
ca.example.com/fr<br />
ca.example.com/de<br />
ca.example.com/ja<br /></p>

<p>uk.example.com/en<br />
uk.example.com/es<br />
uk.example.com/fr<br />
uk.example.com/de<br />
uk.example.com/ja<br /></p>

<p>Entries will be translated into all five languages. But, entries should also have the ability to display in one or two or all of the countries etc. I understand how the locales (translations) functionality built into Craft can handle the languages but how would the countries be handled at the same time?</p>

CC BY-SA 3.0
2014-09-03T08:32:48.683Z
Adam, any thoughts on the approach I posted?
carlcs
<localization><multi-environment><language>
Multi-Region & Multi-Language
# Multi-Region & Multi-Language

(Asked by: username_0 on 2014-08-30)

I'm trying to setup a multi country site running off one Craft install.

example.com  
ca.example.com  
uk.example.com

Each countries content will be translated into five languages (English - en, Spanish - es, French - fr, German - de, Japanese - ja).

example.com/en  
example.com/es  
example.com/fr  
example.com/de  
example.com/ja

ca.example.com/en  
ca.example.com/es  
ca.example.com/fr  
ca.example.com/de  
ca.example.com/ja

uk.example.com/en  
uk.example.com/es  
uk.example.com/fr  
uk.example.com/de  
uk.example.com/ja

Entries will be translated into all five languages. But, entries should also have the ability to display in one or two or all of the countries etc. I understand how the locales (translations) functionality built into Craft can handle the languages but how would the countries be handled at the same time?

**Tags:** localization, multi-environment, language

> **Comments:**
> **username_1**: username_0, any thoughts on the approach I posted?  

---

## 2 answers

### Answer by username_2 on 2014-08-30. Score: 2

I think this is partially related to a question I raised recently, even though my site won't have that many languages per country but some countries will have 2 languages.
How can I add in new Locales to the locale list?
Then you would do something like this in your config
return array(
    'example.com' => array(
        'siteUrl' => array(
            // Global locales
            'en' => 'http://example.com/en/',
            'es' => 'http://example.com/es/',
            'fr' => 'http://example.com/fr/',
            'de' => 'http://example.com/de/',

            // Canada locales
            'ca_en' => 'http://ca.example.com/en/',
            'ca_es' => 'http://ca.example.com/es/',
            'ca_fr' => 'http://ca.example.com/fr/',
            'ca_de' => 'http://ca.example.com/de/',

            // UK locales
            'gb_en' => 'http://uk.example.com/en/',
            'gb_es' => 'http://uk.example.com/es/',
            'gb_fr' => 'http://uk.example.com/fr/',
            'gb_de' => 'http://uk.example.com/de/',
        ),
    ),
);

This should work, I haven't tested it as yet as my site is still in planning stages and I have not gotten into the development phase as yet.
Edited answer based on comment.
For all countries to use the same English, you can set your array to look like below, however this will not allow individual countries to have different English copy since we are pointing them all to the same Locale now.
return array(
    'example.com' => array(
        'siteUrl' => array(
            // Global locales
            'en' => 'http://example.com/en/',
            'es' => 'http://example.com/es/',
            'fr' => 'http://example.com/fr/',
            'de' => 'http://example.com/de/',

            // Canada locales
            'en' => 'http://ca.example.com/en/',
            'ca_es' => 'http://ca.example.com/es/',
            'ca_fr' => 'http://ca.example.com/fr/',
            'ca_de' => 'http://ca.example.com/de/',

            // UK locales
            'en' => 'http://uk.example.com/en/',
            'gb_es' => 'http://uk.example.com/es/',
            'gb_fr' => 'http://uk.example.com/fr/',
            'gb_de' => 'http://uk.example.com/de/',
        ),
    ),
);

> **Comments:**
> **username_0**: Thanks Andrew this is super helpful as is your related article. However, there will be 23 countries all using the same english, french translation etc. If I use the solution above won't that require that I enter a "french" translation 23 times per entry?  
> **username_2**: My solution above would still work, but now that you clarify that all 23 countries will use the same english I will edit the answer to make it encompass that requirement.  

---

### Answer by username_1 on 2014-08-31. Score: 1

What you could do to enable / disable entries from the Control Panel is to add a lightswitch field to the entry type and use it as a ElementCriteriaModel parameter. You'd need one custom lightswitch for each country (additionally to the language lightswitches provided by Craft's localization feature).
To filter your elements with the right "country lightswitch" in your templates, you first have to figure out what country / subdomain the page is accessed from. Something you can do by requesting the siteUrl variable and use Twig filters (e.g. slice) to put the string into shape.
Now you can conditionally filter with the lightswitch relevant for the currently accessed country:
{# Cut the `siteUrl` string into shape #}
{% set subDomain = siteUrl|split('/')[2]|split('.')[0] %}

{# Conditionally create the ElementCriteriaModel #}
{% switch subDomain %}

    {% case 'us' %}
        {% set entries = craft.entries.section('news').subDomainUS('1') %}

    {% case 'ca' %}
        {% set entries = craft.entries.section('news').subDomainCA('1') %}

    {% case 'uk' %}
        {% set entries = craft.entries.section('news').subDomainUK('1') %}

    {# No match found --> global domain #}
    {% default %}
        {% set entries = craft.entries.section('news').globalSite('1') %}

{% endswitch %}


---

