I’m using trntv/Yii2-starter-kit. How can I extract messages to DB? My config:
'*'=> [ 'class' => 'yiii18nDbMessageSource', 'sourceMessageTable'=>'{{%i18n_source_message}}', 'messageTable'=>'{{%i18n_message}}', 'enableCaching' => YII_ENV_DEV, 'cachingDuration' => 3600, 'on missingTranslation' => ['backendmodulesi18nModule', 'missingTranslation'] ]
My I18N file:
'sourcePath'=>Yii::getAlias('@base'), 'languages' => ['uz','ru'], 'translator' => 'Yii::t', 'sort' => false, 'removeUnused' => true, 'only' => [ '*.php', ], 'ignoreCategories' => ['yii'],
I tryed:
php yii message @common/config/messages/_base.php
And php yii message But always it writes all messages to files: vendor/yiisoft/yii2/messages. How can I export messages to DB? Has anyone help?
Advertisement
Answer
You need to use the following as per CONSOLE-DOCS
there is a ExtendedMessageControler
class. This controller extends default MessageController
to provide some useful actions:
To migrate messages between different message sources run the common like below
php console/yii message/migrate @common/config/messages/php.php @common/config/messages/db.php
Which means you should have a file inside the @common/confiog/messages/
folder with the name db.php
that will be used to create the message
and source_message
tables the contents of the file should be
<?php return yiihelpersArrayHelper::merge( require(__DIR__ . '/_base.php'), [ // 'db' output format is for saving messages to database. 'format' => 'db', // Connection component to use. Optional. 'db' => 'db', // Custom source message table. Optional. 'sourceMessageTable' => '{{%i18n_source_message}}', // Custom name for translation message table. Optional. 'messageTable' => '{{%i18n_message}}', ] );
and the messages source directory will be determined by the php.php
file inside the @common/config/messages
directory that contains the following
<?php return yiihelpersArrayHelper::merge( require(__DIR__ . '/_base.php'), [ // 'php' output format is for saving messages to php files. 'format' => 'php', // Root directory containing message translations. 'messagePath' => Yii::getAlias('@common/messages'), // boolean, whether the message file should be overwritten with the merged messages 'overwrite' => true, ] );
You just need to run the migration command and the tables will be created and the messages will be exported to the respective tables.
for more details see the SOURCE
for the actionMigrate()
.