Swissdude
Swissdude

Reputation: 3556

Yii - get translation for another language

I'm using Yii and it's built in translation functionality.

Now, I need to translate some string depending on a user-setting (correspondence language), without changing the main language.

Means: The page itself is in english. The user can choose a correspondence language. The title for the user (Mr./Ms.) should be in the selected correspondence language (e.g. for French it should be Monsieur/Madame).

This can't be really achieved by using Yii::t('app', 'mr'). If there'd be a third variable I could pass to the translator for the desired language, that wouldn't be a problem. I guess I could set the default-language to the correspondence language before translating the title and change it back afterwards, but that seems a little unpractical?

Any ideas?

Upvotes: 0

Views: 116

Answers (1)

Taron Saribekyan
Taron Saribekyan

Reputation: 1390

You can use this TsTranslation extension, which allows to translate dinamic messages and get their translated value by Yii::t(): f.e. you can use this Yii::t($model, 'MrOrMs'), where $model intanceof CActiveRecord specific user.

Upvotes: 1

Related Questions