2

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?

1
  • Adam, any thoughts on the approach I posted?
    – carlcs
    Sep 3, 2014 at 8:32

2 Answers 2

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/',
        ),
    ),
);
2
  • 1
    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
    Aug 30, 2014 at 16:10
  • 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. Aug 30, 2014 at 19:57
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 %}

Your Answer

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

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