DB-based translations

Yii also supports database as a storage option for message translations.

It has to be explicitly configured in the config/web.php file if we are working in the basic template, or in common/config/main.php, if we are working in the advanced template.

Next, we need to add two more database tables to manage message sources and message translations.

Start by creating database tables, as suggested in Yii's official documentation at http://www.yiiframework.com/doc-2.0/yii-i18n-dbmessagesource.html:

CREATE TABLE source_message ( id INTEGER PRIMARY KEY AUTO_INCREMENT, category VARCHAR(32), message TEXT ); CREATE TABLE message ( id INTEGER, language VARCHAR(16), translation TEXT, PRIMARY KEY (id, language), CONSTRAINT fk_message_source_message ...

Get Yii2 By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.