O'Reilly logo

Yii2 By Example by Fabrizio Caldarelli

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required