tl;dr I have an app-advanced scheme that has a view stored in frontend app. This view renders a typical grid-view that displays data fetched by model stored in common app. Everything seems to be correctly configured and yet only layout and views files are translated. The grid-view widget that uses model from common app is not translated.
I have a Yii 2 App Advanced-based application where I have an Examination model stored in /common/models/. This file has the following method defined:
public function attributeLabels()
{
return [
'id' => Yii::t('models', 'ID'),
'patient_id' => Yii::t('models', 'Patient ID'),
'created_by' => Yii::t('models', 'Created By'),
'created_at' => Yii::t('models', 'Created At'),
'updated_at' => Yii::t('models', 'Updated At'),
];
}
As you can see, it uses non-standard models
category for translations.
I have run the following command:
php yii message common/i18n.php
And it correctly generated the /common/messages/pl/models.php file (among others, for different languages) with the correct content, which I have then partially translated:
return [
'Created At' => 'Data utworzenia',
'Created By' => 'Utworzone przez',
'ID' => '',
'Patient ID' => 'Identyfikator pacjenta',
'Relation between examination and doctor is incorrect' => '',
'Relation between examination and patient is incorrect' => '',
'Updated At' => 'Data modyfikacji',
];
I have also a partially modified / translated /frontend/views/examination/index.php file where I use the following part:
Yii::t('app', 'Login')
This time using the default app
category.
And I also have a widget configuration there:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'patient_id',
'created_by',
'created_at',
'updated_at',
[
'class' => ActionColumn::className(),
'urlCreator' => function ($action, Examination $model, $key, $index, $column) {
return Url::toRoute([$action, 'id' => $model->id]);
}
],
],
]); ?>
The $dataProvider
in this view is the very same Examination model (above) injected there by ExaminationController.php:
public function actionIndex()
{
$dataProvider = new ActiveDataProvider([
'query' => common\models\Examination::find(),
]);
return $this->render('index', [
'dataProvider' => $dataProvider,
]);
}
After executing another:
php yii message frontend/i18n.php
the /frontend/messages/pl/app.php file has been created with the content that I have also translated:
return [
'Login' => 'Zaloguj się',
];
So I assume that the configuration for my translation files generator is correct.
I have a main application configuration file for my frontend app (stored in /frontend/config/main.php) with the following component added:
'i18n' => [
'translations' => [
'models' => [
'class' => 'yii\i18n\PhpMessageSource',
'fileMap' => [
'app' => 'app.php',
'app/error' => 'errors.php',
],
],
],
],
Which – I am getting things correctly – causes view files to be translated (among others).
I have also added quite similar configuration to my common app (stored in /common/config/main.php) with the following content:
'i18n' => [
'translations' => [
'models' => [
'class' => 'yii\i18n\PhpMessageSource',
'fileMap' => [
'models' => 'models.php',
],
],
],
],
And yet, as in the introduction, the whole thing works only partially. Messages from frontend app are translated correctly, but the widget that uses model from common app is not translated.
What am I missing?