【问题标题】:Yii2 translationYii2翻译
【发布时间】:2015-03-09 20:35:33
【问题描述】:

我有 Yii2 - 高级模板 我保留源语言英语 目标语言是法语 系统消息翻译如下: Yii::t('yii','Update') 翻译为“修饰符”

但我所有的自定义翻译都不起作用 - 这是我所做的:

修改:后端\config\main.php:

    'i18n' => [
        'translations' => [
            'app*' => [
                'class' => 'yii\i18n\PhpMessageSource',
                'basePath' => '@common/messages',
                'sourceLanguage' => 'en-US',
                'fileMap' => [
                    'app' => 'app.php',
                    'app/error' => 'error.php',
                ],
            ],
        ],
    ],
],
'language' => 'fr',

创建:common\config\i18n.php

<?php
return [
    'sourcePath' => __DIR__. '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR,
    'languages' => ['fr-FR','en-EN'], //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' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'messages',
    'overwrite' => true,
];

当然,我肯定弄混了一些东西,但我找不到 - 一些帮助会很好!

【问题讨论】:

    标签: internationalization yii2


    【解决方案1】:

    您的配置看起来正确。我假设您的 common/messages 文件夹中有 fr 文件夹用于自定义翻译。

    您需要使用Yii::t('app','your_custom_word');

    your_custom_word 应该在common/messages/fr/app.php 文件中定义。

    【讨论】:

    • 感谢提示:我使用 yii message/extract @common/config/i18n.php 自动生成了文件夹
    • 感谢您的提示:我使用“yii message/extract @common/config/i18n.php”自动生成了文件夹,并在设置 fr-FR 时创建了文件夹 fr-FR - 我重命名了该文件夹,它的工作原理
    猜你喜欢
    • 2014-12-20
    • 1970-01-01
    • 2016-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-23
    相关资源
    最近更新 更多