Can anyone share own experience and best practices implementing multilingual sites with Yii2? I want translate user input that is stored in database. For example article, that may have its name in three different languages, body and some translatable attributes as well.
Does Yii2 have built in features to translate the dynamic content? Or should I use third party extensions like these ones below:
https://github.com/creocoder/yii2-translateable
https://github.com/LAV45/yii2-translated-behavior
https://github.com/lajax/yii2-translate-manager
Your help would be appreciated.
Well, I can give you my point of view only based on what I have done.
There are to places to work translation
Now I will explain:
The i18n Message Translation is based on translating strings in your views, models, and in some cases like on the bootstrapped class.
You will en using
Yii::t('app/main', 'Your name is {0}'
as an example to translate strings that are stored on message php files.Now if you translate stings you will want to translate the routes so you will en with routes like /articles and /articulos when you change the language. for this purpose you will like to build a class that implements BootstrapInterface and that will be called from the process of bootstrapping your app.
So this is an example of my settings.php that I use for this
And remember to bootstrap the class in your config file «i.e. web.php»
And finally to translate text from the database you may want to make a table that supports the translated text like:
So when you call your app you can pull your data using something like the following on the action (only a simple example):
s->render('index',['articles'=>$articles, 'lang'=>$lang]);
or in the view as:
I hope this explains the way I have been translating my apps.
Use a Google translator API or Yandex API to for smooth translations for multiple languages. Few links that i have found on git
https://github.com/borodulin/yii2-i18n-google
Tutorial
RichWeber/yii2-google-translate-api
Google Api is a paid service however you can get free credit for 12 months if your a first time user