PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, February 28, 2022

[FIXED] Yii2: How to change a system message translation file

 February 28, 2022     internationalization, php, translation, yii, yii2     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing