I have this tables:
When I get the Product with its relation from product_translation I want it according to the user selected language, so on the relation I have:
'productTranslation' => array(self::HAS_ONE, 'ProductTranslation', 'product_id',
The problem is that the translation in the user language might not exist, so get it in the default language.
How can I do this?
Each request comes from specific client-user, so you have to use Yii::app()->language
If you want to set the language to the user, you have to do that manually (for example with database user + AR model)
Yes, right, it’s Yii::app()->language;
But what about if the translation doesn’t exist in the user language? I need to get it in the default language.
In your config/main.php you could set this
'sourceLanguage' => 'en', //the source language
'language' => 'el', //the default language
If you do not set this and there is no translated text, Yii will not translates your text, so the native text of code will be displayed