Access A Module's Translation From Differernt Modules In Yii

I really need some help.

I have created two modules in my project: admin and account. In my admin module I have User model.

I have managed to translate my admin module using following structure:


modules

   -admin

       -models

       -controllers

       -views

       -messages

         - en

           user.php  

         - ru

           user.php

       -AdminModule.php

and used following expression:


Yii::t("adminModule.user","Username")

to output my translated message.

However this doesn’t work if I’m trying to access User model from account module. Fields are not translated and application even troughs an exception:


include(adminModule.php): failed to open stream: No such file or directory

Seems like I’m not able to include my admin module. So I have tried to import it as follows within my account/AccountModule.php


 public function init() {


    $this->setImport(array(

        'account.models.*',

        'account.components.*',            

        'application.modules.admin.models.*',

        'application.modules.admin.messages.*',

    ));

}

In my main config file I added following lines of code as it has been suggested. But no help,I still have the same exception.


'sourceLanguage' => 'en',

'language' => 'ru',



I’ve tried lots of stuff suggested in the following resources


    

    Yii modules internationalization

    www.rymland.org/post/27?title=Enforcing+translation+of+message+in+Yii

    yii use message in module



Also read Yii documentation


 yiiframework.ru/doc/guide/ru/topics.i18n

But yet nothing helped me.

If someone has some ideas, kindly ask you for your assistance, Thanks in advance

Actually You should import your module…

Example:

Yii::import();

your module class name and containing it file is named AdminModule, not adminModule.

try to use:




Yii::t("AdminModule.user","Username")



I did that in several ways:

Firstly I tried this from the init method of my account module




public function init() {


    $this->setImport(array(

        'account.models.*',

        'account.components.*',            

        'application.modules.*',

    ));

}

Also I tried with the statement you suggested


Yii::import();

Anyway didn’t succeed in both cases.

I tried, doesn’t help.

then try this…

In your Admin module:


public static function t($str='',$params=array(),$dic='admin') {


		return Yii::t("AdminModule.".$dic, $str, $params);


	}

Then in your view:


<?php echo AdminModule::t('Username'); ?>

All right, I need to apologise. My fault.

When I tried to import my module, I have used the following statement:


   

    public function init()  {

    	$this->setImport(array(

        	'account.models.*',

        	'account.components.*',        	

        	'application.modules.admin.models.*',

        	'application.modules.*',

    	));

	}

Assuming that I have imported all modules. But I was wrong.

The right way was to do:


   

    public function init()  {

    	$this->setImport(array(

        	'account.models.*',

        	'account.components.*',        	

        	'application.modules.admin.models.*',

        	'application.modules.admin.AdminModule',

    	));

	}

Thanks guys! Really appreciate your assistance!