How to change default language


I’ve just downloaded copy of yii framework and would like to change application default language.

According to documentation I’ve added ‘language’=>‘pl’ in main configuration file, but it does not change anything, all messages are still in english. I’ve also tried to copy messages file from framework dir do my application dir but it does not help.

When I put a call to method to show current language in template it shows correctly: pl, but messages are not translated

Any advices?

Best Regards

All texts in your views, controllers and model attributes need to be changed using the Yii::t() function. These function uses a file you should create in your messages directory having all translated messages.

Problem: .po files are not seen by app.

My config/messages.php

return array


        'sourcePath'        => '[PATH_TO_APP]',

        'messagePath'       => '[PATH_TO_APP]/protected/messages',

        'languages'         => array('ru_RU'),

        'fileTypes'         => array('php', 'phtml'),

        'exclude'           => array(




Related lines in my config/main.php:


'sourceLanguage'    =>'en_US',

'language'          =>'ru_RU',


                'messages'          => array(

                        'class'             => 'CGettextMessageSource',

                        'useMoFile'         => true,

                        'useBigEndian'      => true,

                        'cachingDuration'   => '0',

                        'basePath'          => '[PATH_TO]/protected/messages/'



Yii::t() is used correctly a couple of times.

Installed and used the extension PoPHPCommand.

Creating .php files works, creating .po files from .php the works too, when I comment ‘messages’ the translation comes out of .php files and work well (i.e. dirs are correct), need to make .po files work too.

Seems it is a configuration issues (sorry, downloaded yii first time only yesterday…), googling does not help, any comments appreciated…

Here it says

So try to set useMoFile to false.

Not only that option was tried… Would not write here otherwise…


I was facing the same problem, and it turens out that you have to define the ‘catalog’ as the following :





replace ‘default’ with your po file name.

I know, it doesn’t make sense, but it works like this.


I read that the catalog is to specify the default name of the file (messages) as it said in CGettextMessageSource.php file

 * @var string the message catalog name. This is the name of the message file (without extension)

 * that stores the translated messages. Defaults to 'messages'.

So this will not do anything.

I just add this small code in the main.php to set the default value if there is no cookie stored.

//set default language 

if (!isset(Yii::app()->request->cookies['language']))

{		$daysExpires = 100;


    $cookie = new CHttpCookie('language', 'es');

    $cookie->expire = time() + 60 * 60 * 24 * $daysExpires;

    Yii::app()->request->cookies['language'] = $cookie;