Yii internationalization - how to set two languages?

Hello all,

I intend to use Yii on my future projects.

I do have some questions however, regarding the methods we have to achieve some things.

I hope someone could give me a hand here. :rolleyes:


I understand we have a target language and a source language. I understand that, on this case, we have one and only one source language but we may need two target languages.

If we wish to build an application on two languages, one of them being english, we have to set TWO target languages on our app/config.php file in order to it to switch according to the user choice ?

Thanks in advance,


You really need two target language in the same time?


What do you mean by ‘building an application in two languages’?

If you mean that you need its content to be translatable in two languages, then you may define a default one as Yii::app()->language, and switch it to the other one according to your application behaviour (for this case you may take a look at one of extensions as an example which way language handling may be coded). For translations storage you may use files or db. More often I use message files, dividing all translations into categories (one category - one file) and using key phrase that will be translated into any language, e.g.

Yii::t('caption', 'contact_us');

If you mean, that you need controllers/actions to be written in different languages (thus giving translated urls), then you may need to use CUrlManager, writing custom url-rules.

I mean a application where a user clicks on a flag country X and the site returns:

a) all messages (yii::t())

B) all contents (database);

c) all data and currency formats (???)

to user choice.

My question is where to switch it on c) cases ?