I'm using the Yii2 advanced template. I have implemented the translations(i18n) following this tutorial and reviewing this SO question. YES, I read the documentation.
My translations are not working and I found out in the debugger that it's looking for he translations in the frontend folder instead of he common folder where the message/extract created the translations files:
The message file for category 'app' does not exist: localhost/frontend/messages/es/app.php
I know the easiest thing would be to move the messages folder to the frontend folder since I'm not using translations in the backend, but I'd like to understand what I'm doing wrong.
This is my i18n file located in common/config:
'sourcePath' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR,
'languages' => ['es'], //Add languages to the array for the language files to be generated.
'translator' => 'Yii::t',
'sort' => false,
'removeUnused' => false,
'only' => ['*.php'],
'except' => [
'.svn',
'.git',
'.gitignore',
'.gitkeep',
'.hgignore',
'.hgkeep',
'/messages',
'/vendor',
],
'format' => 'php',
'messagePath' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'messages',
'overwrite' => true,
This is my common/config/main file
'i18n' => [
'translations' => [
'frontend*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@common/messages',
],
'backend*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@common/messages',
],
],
],
This is where the aliases are defined (default. common/config/bootstrap) and echoing @common returns common:
Yii::setAlias('@common', dirname(__DIR__));
Yii::setAlias('@frontend', dirname(dirname(__DIR__)) . '/frontend');
Yii::setAlias('@backend', dirname(dirname(__DIR__)) . '/backend');
Yii::setAlias('@console', dirname(dirname(__DIR__)) . '/console');