phpcakephplocalizationinternationalizationmultilingual

Cakephp 2.0 dynamic multilanguage website (best practice issue)


I have two domains pointing to the same cakephp app.

I read the domain on core.php and depending on a condition, I set the display language

        if(strstr($_SERVER['SERVER_NAME'],'por')>-1 ){
            Configure::write('Config.language', 'por');     
        }else{
            Configure::write('Config.language', 'spa'); 
        }

I'm not sure if this is the best practice since this doesn't use sessions. Moreover, I'm not sure how this may work with high concurrency, I'm guessing some users may experience language flickering.


Solution

  • If the language of your website do depend on the server name, I don't think it is a bad practice.

    Configure is a singleton class that is instanciated only once, but for each HTTP request as it is PHP. Unlike some applications servers such as Tomcat or even ASP.Net, it does not configure the 'application' for all users on your website, but only for the current request. So your users won't experience any language flickering.

    That said I would not put this test in core.php, but in bootstrap.php as it is intended for this kind of things.