Translations :: variables instead

I was looking at how Yii does translations and really find having sentences instead of variables an issue.

Is there an alternative solution to over ride what the core does?

I’m thinking that all languages should be separate from the code.


Yii:t(‘accounts’, ‘please click any new users you wish to remove’)

To be honest, this is really hard to deal with for users who are not native speakers and it’s very hard to change something on the fly.

Is it possible to change it to:

Yii:t(‘accounts’, ‘button_remove_new_user’)?

You could then have:




Basically refer to everything like a variable. That way if I didn’t want to use “Please click to remove any new users or any other offending dork users” I could just use “remove dork” :)

well, you can simply do this.

in config (main.php) specify:



and use variables as literals. sourceLanguage=var is just something that is for sure not used as another language so everytime yii will seek for translation file.

Thanks for the answer!

This is gonna help a lot!

I’m on a huge g11n kick at the moment :)

Clever! Thanx for the idea.

Does Yii convert the translations on the fly in the view or in the controller?

I read the dic on localization but it didn’t mention when this occurs.

Which has got wondering about performance of translating on the fly.

Yii loads translation file first time Yii::t is called and there is no file loaded for current language. You can use Yii::t wherever you want (actions/widgets/views). Translation you have to provide on your own (there is "yiic message" command which helps to generate new translation files). There is however dedicated solution for translating views - if there is a subdirectory that match language and there is view file with same name - it will be used. Example:

you have such files structure:


     |- index.php

     |- en/

         |- index.php

then for english (en) /protected/views/site/en/index.php will be used. For any other language - /protected/views/site/index.php.

Thanks for all the helpful information!

Now I have to give it a try!

when I change this line of config/main.php to


its not working . i want this language how can i do plz tell me.


is what you wrought the app in.


is what you want the app to display in.