Issue
The problem
Yii is providing its own translations for system messages, e.g. 'File upload failed' is translated to 'Das Hochladen der Datei ist gescheitert.' when the language on my website is changed to German. This would be fine but some of the translations are grammatically incorrect and I would like to change them.
I've found the messages file that yii is using to handle the translation: yiisoft>yii2>messages>de>yii.php
but I can't make changes to it as its part of the vendor directory and any changes I'd make would be overwritten during the next yii update.
What I've tried
I've tried following the instructions laid out by the users here: https://forum.yiiframework.com/t/translating-system-messages/29733. Which involves making a copy of yii.php
, putting it in a new directory, making the desired translation changes and then pointing coreMessages
towards it in the config. I've followed all these steps but it doesn't seem to actually do anything for me.
Solution
As it's stated in the Guide:
Yii comes with the default translation messages for validation errors and some other strings. These messages are all in the category yii. Sometimes you want to correct the default framework message translation for your application. In order to do so, configure the i18n application component like the following:
'i18n' => [
'translations' => [
'yii' => [
'class' => 'yii\i18n\PhpMessageSource',
'sourceLanguage' => 'en-US',
'basePath' => '@app/messages'
],
],
],
Now you can place your adjusted translations to @app/messages/<language>/yii.php
.
BTW - you mentioned that
[...] translations are grammatically incorrect [...]
It would be great for Yii 2 and its community if you could fix the problem - please fork this file and send a PR.
Answered By - Bizley
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.