Yii模块国际化 [英] Yii modules internationalization

查看:92
本文介绍了Yii模块国际化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Yii文档:
模块可以无限嵌套 水平.也就是说,一个模块可以包含 另一个可以包含的模块 另一个模块.我们称前者 父模块,而后一个孩子 模块.子模块必须声明 在其模块的属性中 父模块,就像我们声明模块一样 在显示的应用程序配置中 如上所述.

Yii Doc:
Modules can be nested in unlimited levels. That is, a module can contain another module which can contain yet another module. We call the former parent module while the latter child module. Child modules must be declared in the modules property of their parent module, like we declare modules in the application configuration shown as above.

我尝试使用 Yii :: t()函数创建虚拟应用程序:

I try to create myltilingual application using Yii::t() function:

Yii文档:
当使用Yii :: t()进行翻译时 扩展消息,以下 应该使用格式,而不是:Yii::t('Xyz.categoryName', 'message to be translated')

Yii Doc:
And when using Yii::t() to translate an extension message, the following format should be used, instead: Yii::t('Xyz.categoryName', 'message to be translated')

我使用Yii::t('MyModule.source', 'Test');翻译模块消息,它适用于模块.
但不适用于子模块Yii::t('MyModule.SubModule.source', 'Test');
问题是:
消息存储在以下位置时,如何在模块中为SubModule定义源路径:
/protected/modules/MyModule/modules/SubModule/messages/

I translate modules messages with Yii::t('MyModule.source', 'Test'); it works for modules.
But not works for submodules Yii::t('MyModule.SubModule.source', 'Test');
The question is:
How to define source path for SubModule in Module when messages stored in:
/protected/modules/MyModule/modules/SubModule/messages/

推荐答案

您正试图错误地使用Yii::t.

CPhpMessageSource(Yii::t的第一个参数)的路径应为模块,在其中出现对Yii::t的调用.该模块是否聚集在另一个模块中没关系.

The path for the CPhpMessageSource (first parameter of Yii::t) should be the module in which the call to Yii::t appears. It doesn't matter if that module is aggregated inside another module.

因此在您的示例中,您应该使用

So in your example, you should use

Yii::t('SubModule.source', 'Test');

并将邮件放置在/protected/modules/SubModule/messages/中.

如果您需要根据是否从子模块内部执行转换来更改消息,请在消息中添加参数.

If you need the message to change based on whether the translation is performed from inside a submodule, add parameters to the message.

这篇关于Yii模块国际化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆