Answer the question
In order to leave comments, you need to log in
Yii and content translation
Good afternoon. So how is it correct to work with translations in YII?
I have some widget hanging in the header (en | ru | de ), the user clicks and we change the 'language' to ru_RU, for example. i18n is triggered - after switching to different pages, the message is processed, everything that is in Yii::t() is translated - everything is clear with this.
What to do with articles (if the translation is stored in the database)? Somehow make it clear to modules/controllers that now it is necessary to take content from this field of the base (content_ru) , and not from this one (content_en)?
Answer the question
In order to leave comments, you need to log in
https://github.com/mikehaertl/translatable behavior for translating models. There and about the base is described. The point is to store the essence and separately its translation.
the locale chosen is available to you, and how you build the architecture of the base is up to you.
Regarding the division into databases by language, this is not a very convenient option. At a minimum, there will be problems with data migration and deployment. And yes, it's just not kosher.
Well, I mean check in each controller "if ru, then content_ru"? Perhaps there are more civilized ways? (well, as I understand it, you can, of course, predefine the Controller yourself, so as not to write in each one)
Anyway, back to the question. We have two options:
1) Store `content_ru`,`content_en` in the model, get Yii::$app->language and somehow get
get->'name_'.Yii::$app->language (By the way, this is it possible to do it?)
2) Store `id`, and store a separate table `id`,`ru`,`en`, well, it's somehow like in Yii:t only with the base
What to choose after all. SEO doesn't matter
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question