Translate module

Post to discuss about the extension translate

More info in the extension link

Any doubts/bugs report here


This will really come in handy when I get around to translating my app.

Thanks. :)

I have added a default language to the module to speed it up. Maybe you want to add that feature. Almost all messages to translate are written in english and don’t have to be translated:


// module

    static $defaultLanguage;

    // ...

    static function missingTranslation($sender){

    	if (self::getLanguage() === self::$defaultLanguage)


        // ....


// usage:

TranslateModule::$acceptedLanguages = array('de' => 'German');

TranslateModule::$defaultLanguage = 'en';


Changed isset -> !empty in line 17 of the controller (if(isset($_POST[‘MissingTranslations’])){) because $_POST[‘MissingTranslations’] contains an empty string when I clicked the link and nothing had to be translated.

By default, if no language is set by the user or the one set is the same as the source language, it sets to null, that speed up the application (it wont try to translate)

you could also use forceTranslation setting to translate from sourceMessage to language even if its the same

As for the other issue, thank you for the fix, soon I’ll be uploading it with the corrections and probably a couple new functionalities.

Anyway, thanks for the reports


Hi all,

This is my idea, when its default language set in english so it will be automatically insert into MessageSource table if doesn’t exist and it will be automatically translated by google translate, so you don’t need to translate it manually one by one. To do that you must edit TranslateModule.php and add this code

static function google_translated( $text, $destLang , $srcLang = 'en' ) {


		$text = urlencode( $text );

		$destLang = urlencode( $destLang );

		$srcLang = urlencode( $srcLang );


		$trans = @file_get_contents( 


		); //remove * mark

		$json = json_decode( $trans );

		return $json->data->translations[0]->translatedText;


and edit on static function missingTranslation with this code

static function missingTranslation($sender){



        if(($model=MessageSource::model()->find('message=:message AND category=:category',$attributes))===null){

            $model=new MessageSource();







        if($model->id) {


			//save in english


			if(($model1=Message::model()->find('id=:id AND translation=:translation AND language=:language',$attributes))===null){

				$model1=new Message();







			//save in dest lang

			if ($sender->language<>'en') {



				if(($model2=Message::model()->find('id=:id AND translation=:translation AND language=:language',$attributes))===null){

					$model2=new Message();









Thanks Toshi!

I was thinking to do something using google translate but didn’t have time to work on it yet

I’ll definitely add it to the next release



EDIT: Soon I’ll be posting a new version with a complete rewrite of the code

[size="4"] [b]Version 0.2 released

[/b][/size]Complete rewrite of the code to allow better customization

A lot of new funcionalities

Added google translate support

Check it out

Hi Gustavo

I liked the old version but this one gave me the smile right away :) thx for the refactor.

Unfortunetly , I’m here to share that I keep getting the ‘error’ alert

when trying to launch the googleQuery?

is this also supposed to work on any localhost set up ? (localhost,,…)

I couldn’t see anything obvious, so I hope you know about this


Hi Tibor

Thanks! I’m glad you liked and was useful to you.

As for the error, it works in localhost normally. I believe that the error is because google can’t translate some text, therefore it returns an error message that is treated as an exception by the translate component.

To avoid the exception, I will soon update the extension . From now on, it will just log the message as an error.

If you have any suggestion or find any bug, let me know.




Just uploaded the new version

Hi Gustavo thanks for the new version

I can see you cleared the Dialog translation , cool.

here’s some feedback after installing the new version, cause I still get the Google translate error alert + something new

on /translate/translate/index

on click "Translate all with google translate" return an alert error for words like "Visibility" and "share your ideas"

On each word translation there is a ‘translate’ Button, when I click that it returns an alert containing this :

<h1>PHP Error [8]</h1>

<p>Trying to get property of non-object (X:\X_Dev\perfony\perfony\iperfony\protected\modules\translate\components\MPTranslate.php:274)</p>

<pre>#0 X:\X_Dev\perfony\perfony\iperfony\protected\modules\translate\components\MPTranslate.php(274): CWebApplication->handleError()

#1 X:\X_Dev\perfony\perfony\iperfony\protected\modules\translate\controllers\TranslateController.php(51): MPTranslate->googleTranslate()

#2 X:\X_Dev\perfony\perfony\yii-1.1.8.r3324\framework\web\actions\CInlineAction.php(50): TranslateController->actionGoogletranslate()

#3 X:\X_Dev\perfony\perfony\yii-1.1.8.r3324\framework\web\CController.php(300): CInlineAction->runWithParams()

#4 X:\X_Dev\perfony\perfony\yii-1.1.8.r3324\framework\web\CController.php(278): TranslateController->runAction()

#5 X:\X_Dev\perfony\perfony\yii-1.1.8.r3324\framework\web\CController.php(257): TranslateController->runActionWithFilters()

#6 X:\X_Dev\perfony\perfony\yii-1.1.8.r3324\framework\web\CWebApplication.php(277): TranslateController->run()

#7 X:\X_Dev\perfony\perfony\yii-1.1.8.r3324\framework\web\CWebApplication.php(136): CWebApplication->runController()

#8 X:\X_Dev\perfony\perfony\yii-1.1.8.r3324\framework\base\CApplication.php(158): CWebApplication->processRequest()

#9 X:\X_Dev\perfony\perfony\iperfony\index.php(13): CWebApplication->run()


Thanks for you help


Hey Tibor

The new error was caused when updating to new version and is now fixed in github.

Soon I’ll post the new download file.

As for the other error, I spent some time trying but I can’t reproduce it. Please provide more details of your configuration and I’ll run some tests.


Hey Tibor

The new error was caused when updating to new version and is now fixed in github.

Soon I’ll post the new download file.

As for the other error, I spent some time trying but I can’t reproduce it. Please provide more details of your configuration and I’ll run some tests.

Also, try calling the queryGoogle method directly by Yii::app()->translate->queryGoogle(‘some message’);



brand new, I’ve installed “translate” module on a clean 1.1.9 yii framework (+ userGroup module).

1st remak : the auto_increment in table “sourcemessage” wasn’t set. Once corrected, it works fine

2nd : basic pages works fine but after login problems comes. I’ve received :

Include(TranslateBaseController.php) [<a href=‘function.include’>function.include</a>]: failed to open stream: No such file or directory

After copying the TranslateBaseController.php into protected/controllers, working fine …

Is that the right way to installe this module ?

Is it a side effect of 1.1.9 version of the framework ? or is it the presence of userGroup module ?

thx for explanations


Hi Shama

I had the same problem when working with userGroups

It’s that to get all application controllers it imports the controllers folder of each module, but doesn’t import the components folder, where TranslateBaseController is located.


Thanks Gustavo, for the explanation.

that means that every controller in component (sub)directory must be copied into general controller folder ?

another question :

After model generation, I use the giix CRUD generator.

I select the ‘yii user management access control’ option to generate access control code into controller. The goal is to use the userGroups functionnality with the user access system. Generated code for as simple table (no relation …) is :

public function filters() {

	return array(




public function accessRules() {

	return array(



				'roles'=>array('admin', 'core', 5), 



				'actions'=>array('minicreate', 'create','update'),












as written in userGroups user guide, I change the rules by :



  'groups'=>array('admin', 'core', 5), 


when running the answer is :

Property « CAccessRule.groups » is undefined.


I’ve missed something ?


Shama was sleeping … (RTFM)

just declare with correct filter’s string :


public function filters() {

	return array(





for other candidate, I’ve patched the default Giix rules template. So Giix generates directly the right code ;D . The file is in :


enjoy !



I have yii-user module, and until I setup translate module it was shown in my language. Now it seems translate somehow forces other modules to appear in default english language. can it be somehow adjusted that modules that have their own separate translation, appear in the selected language?

Wow! I’m going check this out when I’m on my pc.

Question: why don’t you use variables for the base instead of straight language sentences in the views?

I’m thinking that too many apps have English that other language speakers have to deal with.

Hi guys,

I wonder why this line

'onMissingTranslation' => array('TranslateModule', 'missingTranslation'),

will cause all the pages become blank, But the pages ok once remove the line??


        //define the class and its missingTranslation event



            'onMissingTranslation' => array('TranslateModule', 'missingTranslation'),  <--- this line


thanks man.