请教下model里的error怎么翻译

问题咨询 · Alur · 于 5年前 发布 · 2667 次阅读

\fecshop\vendor\fancyecommerce\fecshop\models\mysqldb\customer\CustomerRegister.php L78 $this->addError($attribute, 'this email is exist!'); 这一句貌似没有通过翻译机制? Yii::$service->page->translate 折腾了半天,未找到不修改源文件或重写能翻译的机制,求教方法。

共收到 6 条回复
Fecmall#15年前 0 个赞

中文下,默认是有翻译的!!

在:https://github.com/fecshop/yii2_fecshop/blob/master/services/helper/Errors.php

可以看到 helper error services 的error的添加都会经过翻译函数

Yii::$service->page->translate->__($s);

因此,将这个错误信息在翻译文件中添加即可,打开 @fecshop/app/appfront/languages/zh_CN/appfront.php文件可以看到

 'this email is exist!'          => '该邮箱地址已经被注册',

这个翻译文件,如果你想要进行修改,但你不能在这里改,你可以在本地路径中覆盖配置

'this email is exist!'          => '该邮箱地址已经被注册3333',

注册账户的时候会发现被修改了

Fecmall#25年前 0 个赞

更多关于fecshop多语言翻译的文档:Fecshop 多语言翻译

Alur#35年前 0 个赞

我确实有这么操作 但是没有出来 我再仔细对比一下 看看是否哪里有遗漏 感谢terry

4楼 已删除.
Alur#55年前 0 个赞

经过仔细比对,仍然不知问题所在,请进一步指教,内容详见下面描述: 代码部分: 1。common/config/fecshop_local_services/FecshopLang.php


<?php

return [
    'fecshoplang' => [
        //'class' => 'fecshop\services\FecshopLang',
        //  mongoSearchLangName 在各个语言下字段参考资料如下:(不支持中文)
        //  https://docs.mongodb.com/manual/reference/text-search-languages/#text-search-languages
        'allLangCode' => [
            // 'en_US' 是标准语言简码  code对应的值en取 “标准语言简码”的前两位字符,
            // 该值设置后,进行了产品分类数据的添加后,不能修改,否则会出现部分翻译语言丢失。
            'zh_CN' => [
                'code' => 'zh',
            ],
        ],
        // 默认语言。
        'defaultLangCode' => 'zh',
    ],
];

2。apphtml5/config/fecshop_local_services/FecshopLang.php

<?php

return [
    'fecshoplang' => [
        'defaultLangCode' => 'zh',
    ],
];

3。apphtml5/config/fecshop_local_services/Store.php

<?php
return [
    'store' => [
        'class' => 'fecshop\services\Store',
        'stores' => [
            // store key:域名去掉http部分,作为key,这个必须这样定义。
            '1马赛克2' => [
                'language' => 'zh_CN',        // 语言简码需要在@common/config/fecshop_local_services/FecshopLang.php 中定义。
                'languageName' => '中文',    // 语言简码对应的文字名称,将会出现在语言切换列表中显示。
                'localThemeDir' => '@apphtml5/theme/马赛克/theme', // 设置当前store对应的模板路径。关于多模板的方面的知识,您可以参看fecshop多模板的知识。
                'thirdThemeDir' => [],  // 第三方模板路径,数组,可以多个路径
                'currency' => 'CNY', // 当前store的默认货币,这个货币简码,必须在货币配置中配置
                // 用于sitemap生成中域名。
                'https' => false,
                // sitemap的路径。
                'sitemapDir' => '@apphtml5/web/sitemap.xml',
                'thirdLogin' => [
                    'facebook' => [                       #fb api配置 ,fb可以一个app设置pc和手机两个域名
                        'facebook_app_id' => 'novalue',
                        'facebook_app_secret' => 'novalue',
                    ],
                    "google" => [                       #谷歌api visit https://code.google.com/apis/console to generate your google api
                        'CLIENT_ID' => 'novalue',
                        'CLIENT_SECRET' => 'novalue',
                    ],
                ],
            ],
        ],
    ],
];

描述部分 我发现其他翻译也不能正常出来,比如resetpasswordsuccess页面的密码重置成功也不对。是否还存在其他设置项目我没有发现的导致这个问题呢?

Fecmall#65年前 0 个赞

仔细看文档:http://www.fecshop.com/doc/fecshop-guide/instructions/cn-1.0/guide-fecshop_mutil_lang.html2.配置各个入口的i18n组件(yii2的i18n组件的配置)部分,解决如下:

打开@app/config/main.php(@app是各个入口的统称,可以以@appfront为例子)

找到下面的配置

	'i18n' => [
            'translations' => [
                'appfront' => [
                    'basePaths' => [
                        '@appfront/languages',
                    ],
                    // base language code
                    'sourceLanguage' => 'zh_CN',
                    /**
                     * @var bool whether to force message translation when the source and target languages are the same.
                     * Defaults to false, meaning translation is only performed when source and target languages are different.
                     * see: @yii/i18n/MessageSource.php  @property $forceTranslation
                     */
                    'forceTranslation' => true,
                ],
            ],
        ],

设置 'sourceLanguage' => 'zh_CN','forceTranslation' => true,

你这种方式通过上面的方式可以这样修改,基础语言和当前语言相同的时候,通过设置 'forceTranslation' => true,强制翻译。

Alur#75年前 0 个赞

感谢老大回答。 经查,我的main.php文件是没有 'forceTranslation' => true, 这一句的, 加上就好了。

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册
Your Site Analytics