Answer the question
In order to leave comments, you need to log in
I18n in Yii2 using special keys instead of original language phrase?
Good afternoon.
Yii for localization suggests specifying text in one language in the program code, and pulling up translations for other languages. This is how we write in the code: <?= \Yii::t('app', 'Hello {0}', $name); ?>
And this is how it is in the dictionary:
retunr [
'Hello {0}' => 'Привет {0}',
];
<?= \Yii::t('app', 'user.greeting', $name); ?>
retunr [
'user.greeting' => 'Привет {0}',
];
Answer the question
In order to leave comments, you need to log in
Using keys is the normal approach. Specify `sourceLanguage` as `key` and go.
Try it. If you don't like it, go back to the original version.
The problem of duplicate keys is solved by dividing strings into different categories. The first argument in Yii::t is just a category.
The fact that you have to edit the dictionary after changing the phrase is normal. Yii is able to extract phrases for the dictionary itself, you will only need to find the old translation in the file and add it to the new line after a little correction.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question