cakephpinternationalizationcakedc

CakePHP 2 with CakeDC/I18n language prefix being lost


I have a CakePHP 2.5 site running with CakeDC/I18n plugin to allow for multi language support. I have installed the plugin to use a 3 letter prefix when switching languages:

www.example.com/eng/

This is working fine when I click a button to change languages. The language prefix is added to the url. The problem is when I switch pages by clicking on a link the prefix is dropped. Why would this be happening? Do I need to do something in the href markup? My understanding is that the CakeDC/I18n plugin would take care of this.

Any help would be greatly appreciated as I have been scratching my head with this one for awhile!


Solution

  • You need to pass as parameter the current language.

    Otherwise it'll always use the default language that you defined in the bootstrap.php

    Here is an example.

    Router::url(
        'lang' => 'spa',
        'controller' => 'articles',
        'action' => 'view',
        'slug' => 'test'
    );