You may use \yii\mongodb\i18n\MongoDbMessageSource for the i18n message translations storage. Application configuration example:
return [
//....
'components' => [
// ...
'i18n' => [
'translations' => [
'*' => [
'class' => 'yii\mongodb\i18n\MongoDbMessageSource'
]
]
],
]
];
\yii\mongodb\i18n\MongoDbMessageSource uses single collection to store all translations. Each entry in this collection should have 3 fields:
For example:
{
"category": "app",
"language": "de",
"messages": [
{
"message": "Hello world!",
"translation": "Hallo Welt!"
},
{
"message": "The dog runs fast.",
"translation": "Der Hund rennt schnell.",
},
...
],
}
You also can specify 'messages' using source message as a direct BSON key, while its value holds the translation. For example:
{
"category": "app",
"language": "de",
"messages": {
"Hello world!": "Hallo Welt!",
"See more": "Mehr sehen",
...
},
}
However such approach is not recommended as BSON keys can not contain symbols like .
or $
.
Please refer to \yii\mongodb\i18n\MongoDbMessageSource for more details about configuration and translation collection data structure.