Brieneke
Brieneke

Reputation: 45

Custom :language cakephp

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?

Upvotes: 1

Views: 217

Answers (1)

Salines
Salines

Reputation: 5767

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);
    .......
}

Upvotes: 1

Related Questions