NCS_One
(Ncsantos Ncs)
1
Hi,
I have this tables:
product (
id,
...
);
product_translation (
product_id,
lang_code,
name,
...
);
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',
'condition'=>Yii::app()->db->quoteColumnName('productTranslation.lang_code')."='".Yii::app()->user->language."'"
),
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?
konapaz
(Konapaz)
2
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)
NCS_One
(Ncsantos Ncs)
3
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.
konapaz
(Konapaz)
4
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