1
votes

We succesfully build a multiple language (NLD/DEU/ENG) cakephp website (cakephp 2.3.6). And now our client wants us to add the belgium language to his website. The code list doesn't contain a code for the Belgium language. it's either dut (Dutch; Flemish) or fre (French).

But instead of having this url: example.com/dut/controller/action
We would want to have this: example.com/bel/controller/action

Is it possible to work with 'dut', but show 'bel' in the url? Or is there a way to add a 'custom' language?

1
There is no such thing as a belgian language, but belgian variants of mostly french and dutch, then german. I'm pretty sure though that if you define a variant that doesn't exist (like bel) cake won't complain if you provide the necessary translation files too. But if you decide bel=dutch, the other half of belgians will be offended :)user221931

1 Answers

1
votes

You need to use the standard code for the language, the Belgian language does not exist (there are three official languages, Dutch, French, German). But if you have localized content for a particular country, then you should use the country code.

There are countries that have more than one official language (Belgium, Switzerland, Spain, Bosnia and Herzegovina, ..). In this case you should use a combination of language-country code as you can see here

Your URL should look like:

for the German country and language

www.example.com/de/

for the Netherlands and the Dutch language

www.example.com/nl/

for Belgium and the official language

www.example.com/nl-be/
www.example.com/fr-be/

In your AppController beforefilter put a switch statement, where you specify the rules for the language and localized content

EDIT (add example)

    AppControler.php
public function beforeFilter()
{
    switch ($this->params['lang'])){
        // for nederland
        case: 'nl':
            Configure::write('Config.language', 'dut');
            $this->set('for_country','nl');
            break;
        // for germany
        case: 'de':
            Configure::write('Config.language', 'deu');
            $this->set('for_country','de');
            break;
        // for belgium / dutch speakers
        case: 'nl_be':
            Configure::write('Config.language', 'dut');
            $this->set('for_country','be');
            break;
        // for belgium / french speakers
        case: 'nl_fr':
            Configure::write('Config.language', 'fr');
            $this->set('for_country','be');
            break;
        // default english
        case: 'en':
            Configure::write('Config.language', 'eng');
            $this->set('for_country','us');
            break;
    }
}

PostsController.php

public function index ()
{
    // find all posts for country, example only content for Belgium in french
    // example.com/nl_fr/posts
    $options = array(
        'conditions' => array(
            'Post.localized' => $for_country
        )
    );
    $posts = $this->Post->find('all',$options);
    .......
}