yii使用模块中的消息 [英] yii use message in module

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

问题描述

我想为模块之一使用消息,并且我有两种语言.一个是en,另一个是dk,所以我希望它们与我的模块一起使用,并且我已将message文件夹放置在我的模块中,因此文件夹结构类似于:

I want to use message for one of my module and i have two type of language. one is en and the other is dk so i want them to be used with my module and i have placed the message folder in my module so folder structure is something like :

application >  modules > modulename > message > en > app.php and de > app.php

所以我想在我的模块中使用这种语言.您能否建议我需要在模块配置文件中进行哪些更改或配置,以使其正常工作?

so i want to use this language in my module i. can you suggest me what changes or configuration i need to do in my module config file so that this should work?

这是我的模块文件

public function init()
{
Yii::setPathOfAlias('bootstrap', Yii::getPathOfAlias('smsLog.extensions.bootstrap'));
Yii::app()->setComponent('bootstrap', array('class'=>'smsLog.extensions.bootstrap.components.Bootstrap'));

Yii::app()->language='en_us';
$this->setImport(
    array(
        'smsLog.models.*',
        'smsLog.components.*',
        'smsLog.components.Services.*',
        'smsLog.components.Services.Twilio.*',
        'smsLog.components.Services.Twilio.Rest.*',
        'smsLog.message.*',
    )
);
$this->configure(array(
    'preload'=>array('bootstrap'),
    'components'=>array(
        'bootstrap' => array(
            'class'=>'smsLog.extensions.bootstrap.components.Bootstrap',
        ),
    ),

));

$this->preloadComponents();

}

请检查以下图片:

推荐答案

首先在您的 moduleName.php 文件中您需要像这样导入消息文件夹

class ModuleName extends CWebModule
{
public function init()
    {
$this->setImport(array(
            'smsLog.messages.*',
        ));
}
}

现在在带有名称消息的 smsLog中创建一个文件夹,然后创建一个en_us 文件夹.所以结构会像

smsLog/messages/en_us/app.php

在您的app.php中写这个

Now create a folder in your smsLog with name messages and then create a folder en_us. SO the structure would be something like

smsLog/messages/en_us/app.php

In your app.php write this

<?php 
return array(
'your message'=>' I am translated',
);

然后在模块内的控制器中,您可以使用想要的languange

Then in your controllers inside your module you can use the languange you want to like

Yii::t('smsLogModule.app','your message');

希望这会有所帮助:)

更新


您需要使用Yii::t('smsLogModule.app','your message'); 也就是说,您需要在 Yii :: t 的第一个参数前加上模块名称,并加上单词Module(模块).

Update


You need to use Yii::t('smsLogModule.app','your message'); i.e You need to prepend first argument of your Yii::t with the name of your module with the word Module.

这篇关于yii使用模块中的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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