Changing target language of il8n on view

How do I pro grammatically change the target language for a specific view?

Following this step:

Edit main config /protected/config/main.php - add sourceLanguage and language, ie:


'sourceLanguage' => 'en_us',

'language' => 'pl_pl', 

We could only change targe language for the whole application. I want to change target language for a specific view/action/controller.

Is a quite strange request, but you can accomplish like that:


$language= Yii::app()->language;

Yii::app()->language= 'it_it';

$this->renderPartial();

Yii::app()->language= $language;

This change the lanuage in the subview. If you need for a whole action, you can change in the controller, it will not affect the other requests.

@zaccaria

the switch you made as I see is in the application level


Yii:app->language

then after rendering the partial you returned it to its previous stage by restoring the bucket value from


$language

. It is an unnatural way but as I see it, it may work.

Is a lot innatural but you are asking for a site with the head in arabic, the body in chinese and the botton again in arabic… is a quite strange stuff, isn’t it?

That is not what I am trying to do. I am working on some tools for website development which I couldn’t mention here. Each of the tools are separated in modules and it depends on the user preferences what language he prefer for a specific tool because this tool can be used by various regions for a single company.

Ex.

The company subscribes for a particular tool to be used in their german office then it must be DE

The same company subscribes for a different tool or the same tool to be used in india thent it must be IN

a bump on this.

So save the preference of the language in the user table, and then load this preference at the onBeginRequest.

There is a tutorial for this here.

Read also the comment where we discuss how to use behavior for maintaining the language.

I will check this and get back to you . Thanks!