Yii2:如何更改系统消息翻译文件

Yii2: How to change a system message translation file

问题

Yii 正在为系统消息提供自己的翻译,例如当我网站上的语言更改为德语时,'File upload failed' 被翻译为 'Das Hochladen der Datei ist gescheitert.'。这很好,但有些翻译在语法上不正确,我想更改它们。

我找到了 yii 用来处理翻译的消息文件:yiisoft>yii2>messages>de>yii.php 但我无法将其作为 vendor 目录的一部分进行更改,我所做的任何更改都会在下一次 yii 更新时被覆盖。

我试过的

我已经尝试按照用户在此处列出的说明进行操作:https://forum.yiiframework.com/t/translating-system-messages/29733。这涉及制作 yii.php 的副本,将其放入新目录,进行所需的翻译更改,然后在配置中将 coreMessages 指向它。我已经按照所有这些步骤操作,但它似乎并没有真正为我做任何事情。

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'
        ],
    ],
],

现在您可以将调整后的翻译放到 @app/messages/<language>/yii.php


顺便说一句 - 你提到

[...] translations are grammatically incorrect [...]

如果你能解决这个问题,对 Yii 2 及其社区来说会很棒 - 请 fork this file 并发送 PR。