Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Yii2-多语言_Php_Yii_Yii2 Advanced App - Fatal编程技术网

Php Yii2-多语言

Php Yii2-多语言,php,yii,yii2-advanced-app,Php,Yii,Yii2 Advanced App,我正在尝试使用i18l设置网站的前端翻译。下面是我放在frontend/config上的i18l.php文件 <?php return [ 'sourcePath' => 'frontend', 'languages' => ['en-US', 'pt-BR'] , //Add languages to the array for the language files to be generated. 'translator' => 'Yi

我正在尝试使用i18l设置网站的前端翻译。下面是我放在frontend/config上的i18l.php文件

    <?php
return [
    'sourcePath' => 'frontend',
    'languages' => ['en-US', 'pt-BR'] , //Add languages to the array for the language files to be generated.
    'translator' => 'Yii::t',
    'sort' => false,
    'removeUnused' => false,
    'only' => ['*.php'],
    'except' => [
        '.svn',
        '.git',
        '.gitignore',
        '.gitkeep',
        '.hgignore',
        '.hgkeep',
        '/messages',
        '/vendor',
    ],
    'format' => 'php',
    'messagePath' => 'frontend' . DIRECTORY_SEPARATOR . 'translations',
    'overwrite' => true,
];
我在网站和版面上使用
,当我运行命令时。/yii message/extract@frontend/config/i18n.php它为我创建了一个名为“translations”的文件夹,其中包含另外两个文件夹“en-US”和“pt-BR”,这两个文件夹都带有app.php,我已经用一些翻译填充了它们。但是,当我改变main.php上的语言时,仍然不会发生任何翻译(我认为)。 如果有人能帮我一把,我将不胜感激


谢谢。

非常好的帖子,包含了所有需要的细节

我也在为同样的事情挣扎,但你做得很好

因此,如果可以运行该命令并生成文件,则
sourcePath
正确的。 如果它在运行时不显示翻译消息,尽管您的设置发生了更改,那么我推测问题可能在您的
基本路径上:

尝试在basePath配置上使用以下选项:

'basePath' => '@frontend/translations',

棒极了。我只想指出一件事<代码>不确定是否是这样,但我发现如果目标和源目标相同,则需要强制转换以使其尊重文件,而不是来自
Yii::t
的参数输入。
'basePath' => '@frontend/translations',