Extract and translate text stored in database

Hello all. I was wondering if there is a way to extract text stored in the database to translate it like one would do using i18n. I mean, when you use Yii::t you know that message is going to be extracted, but what if that string is extracted from db? For example, i have a nationality table with all nationality names (field name) in english. How can I make those names to be extracted with yii message/extract? Thank you in advance.

Take a look at the DbMessageSource

Thanks for the reply.

I saw it, and it is an option I am considering. But what I am looking for is something that just extracts the content of the database fields and writes them in the usual messages files/folders.

For example, if my table nationality is:




id    name

-----------

1     Spain

2     United Kingdom

3     Germany



Then in my views I would use:




Nationality: <?= Yii::t('app', $model->name) ?>



For this to work, I need in my app.php file inside all my supported languages’ folders the corresponding entries. Is there a way to ‘tell’ ./yii message/extract to ‘explore’ the content of some database fields (in my case, name from table nationality)?

I found the solution: github.com/lajax/yii2-translate-manager from lajax.

In the module configuration, you have the option ‘tables’ in which you can specify which column(s) of which table(s) should be translated. And when you scan the project (an action of the module itself) they are extracted to the database (DbMessageSource style) just like the other Yii::t strings. Awesome work lajax!

I found the solution: github.com/lajax/yii2-translate-manager from lajax.

In the module configuration, you have the option ‘tables’ in which you can specify which column(s) of which table(s) should be translated. And when you scan the project (an action of the module itself) they are extracted to the database (DbMessageSource style) just like the other Yii::t strings. Awesome work lajax!

This is solved.

Nice plugin. Nice to know about it.