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 FOREIGN KEY (id) REFERENCES source_message (id) ON DELETE CASCADE ON UPDATE RESTRICT );
Note
Table names can be customized in the configuration file.
Table source_message
will store all messages...