문제

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?

this is my module file

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();

}

Please check the image below :

enter image description here

enter image description here

enter image description here

도움이 되었습니까?

해결책

First of all in your moduleName.php file you need to import the message folder like this

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

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',
);

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

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

Hope this helps :)

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top