Yii Framework Forum: Translate module - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Translate module Simple module to handle application translations Rate Topic: -----

#1 User is offline   Gustavo 

  • Master Member
  • Yii
  • Group: Moderators
  • Posts: 916
  • Joined: 27-July 10
  • Location:Curitiba - Brasil

Posted 10 May 2011 - 06:10 AM

Post to discuss about the extension translate

More info in the extension link

Any doubts/bugs report here
--
Extensions:
translate modue - module to handle translations
multiActiveRecord - db selection in models
redisCache - redis cache component
mpCpanel - interact with cpanel api
mUploadify - use uploadify uploader in your application

Gustavo Salomé Silva
1

#2 User is offline   jacmoe 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 2,601
  • Joined: 10-October 10
  • Location:Denmark

Posted 10 May 2011 - 02:31 PM

Great!
This will really come in handy when I get around to translating my app.
Thanks. :)
"Less noise - more signal"
0

#3 User is offline   duna 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 04-May 11

Posted 11 May 2011 - 07:50 AM

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:

<?php

// module


    static $defaultLanguage;

    // ...

    static function missingTranslation($sender){

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

        // ....
    }

// usage:

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


0

#4 User is offline   duna 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 04-May 11

Posted 11 May 2011 - 08:02 AM

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.
0

#5 User is offline   Gustavo 

  • Master Member
  • Yii
  • Group: Moderators
  • Posts: 916
  • Joined: 27-July 10
  • Location:Curitiba - Brasil

Posted 11 May 2011 - 09:05 AM

View Postduna, on 11 May 2011 - 07:50 AM, said:

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:



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

Cheers
--
Extensions:
translate modue - module to handle translations
multiActiveRecord - db selection in models
redisCache - redis cache component
mpCpanel - interact with cpanel api
mUploadify - use uploadify uploader in your application

Gustavo Salomé Silva
0

#6 User is offline   toshi 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 02-March 11
  • Location:Indonesia

Posted 16 May 2011 - 04:23 PM

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( 
		"http*s://www.googleapis.com/language/translate/v2?key=[PUT_YOUR_GOOGLE_TRANSLATE_KEY_HERE]&q=$text&source=$srcLang&target=$destLang"
		); //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){
        Yii::import('translate.models.MessageSource');
        $attributes=array('category'=>$sender->category,'message'=>$sender->message);
        if(($model=MessageSource::model()->find('message=:message AND category=:category',$attributes))===null){
            $model=new MessageSource();
            $model->attributes=$attributes;
            if(!$model->save()){
                return;
            }
        }
		
        if($model->id) {
			Yii::import('translate.models.Message');
			//save in english
			$attributes=array('id'=>$model->id,'language'=>'en','translation'=>$sender->message);
			if(($model1=Message::model()->find('id=:id AND translation=:translation AND language=:language',$attributes))===null){
				$model1=new Message();
				$model1->attributes=$attributes;
				if(!$model1->save()){
					return;
				}
			}
			
			//save in dest lang
			if ($sender->language<>'en') {
				$translated=self::google_translated($sender->message,$sender->language);
				$attributes=array('id'=>$model->id,'language'=>$sender->language,'translation'=>$translated);
				if(($model2=Message::model()->find('id=:id AND translation=:translation AND language=:language',$attributes))===null){
					$model2=new Message();
					$model2->attributes=$attributes;
					if(!$model2->save()){
						return;
					}
				}
			}
		}
    }

Warm Regards,

Toshi
YM : toshifirmasyah
Skype : toshifirmansyah
2

#7 User is offline   Gustavo 

  • Master Member
  • Yii
  • Group: Moderators
  • Posts: 916
  • Joined: 27-July 10
  • Location:Curitiba - Brasil

Posted 16 May 2011 - 04:34 PM

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

Cheers,

Gustavo

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

This post has been edited by Gustavo: 17 May 2011 - 03:26 PM

--
Extensions:
translate modue - module to handle translations
multiActiveRecord - db selection in models
redisCache - redis cache component
mpCpanel - interact with cpanel api
mUploadify - use uploadify uploader in your application

Gustavo Salomé Silva
0

#8 User is offline   Gustavo 

  • Master Member
  • Yii
  • Group: Moderators
  • Posts: 916
  • Joined: 27-July 10
  • Location:Curitiba - Brasil

Posted 18 May 2011 - 03:00 PM

Version 0.2 released

Complete rewrite of the code to allow better customization
A lot of new funcionalities
Added google translate support

Check it out
--
Extensions:
translate modue - module to handle translations
multiActiveRecord - db selection in models
redisCache - redis cache component
mpCpanel - interact with cpanel api
mUploadify - use uploadify uploader in your application

Gustavo Salomé Silva
2

#9 User is offline   Tibor Katelbach 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 11-April 11
  • Location:Reunion Island

Posted 18 August 2011 - 04:45 AM

View PostGustavo, on 18 May 2011 - 03:00 PM, said:

Version 0.2 released

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?
http://127.0.0.1:888...googletranslate
is this also supposed to work on any localhost set up ? (localhost,127.0.0.1,...)
I couldn't see anything obvious, so I hope you know about this
Thanks
0

#10 User is offline   Gustavo 

  • Master Member
  • Yii
  • Group: Moderators
  • Posts: 916
  • Joined: 27-July 10
  • Location:Curitiba - Brasil

Posted 18 August 2011 - 06:28 PM

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.

Cheers,
Gustavo

EDIT:
Just uploaded the new version
--
Extensions:
translate modue - module to handle translations
multiActiveRecord - db selection in models
redisCache - redis cache component
mpCpanel - interact with cpanel api
mUploadify - use uploadify uploader in your application

Gustavo Salomé Silva
0

#11 User is offline   Tibor Katelbach 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 81
  • Joined: 11-April 11
  • Location:Reunion Island

Posted 22 August 2011 - 01:22 AM

View PostGustavo, on 18 August 2011 - 06:28 PM, said:

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.


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()
</pre>


Thanks for you help
Tibor
0

#12 User is offline   Gustavo 

  • Master Member
  • Yii
  • Group: Moderators
  • Posts: 916
  • Joined: 27-July 10
  • Location:Curitiba - Brasil

Posted 23 August 2011 - 02:14 AM

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.

Thanks
--
Extensions:
translate modue - module to handle translations
multiActiveRecord - db selection in models
redisCache - redis cache component
mpCpanel - interact with cpanel api
mUploadify - use uploadify uploader in your application

Gustavo Salomé Silva
0

#13 User is offline   Gustavo 

  • Master Member
  • Yii
  • Group: Moderators
  • Posts: 916
  • Joined: 27-July 10
  • Location:Curitiba - Brasil

Posted 23 August 2011 - 02:14 AM

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

Thanks
--
Extensions:
translate modue - module to handle translations
multiActiveRecord - db selection in models
redisCache - redis cache component
mpCpanel - interact with cpanel api
mUploadify - use uploadify uploader in your application

Gustavo Salomé Silva
0

#14 User is offline   bigshamallow 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 09-January 12

Posted 09 January 2012 - 10:47 PM

Hello,

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

Shama
0

#15 User is offline   Gustavo 

  • Master Member
  • Yii
  • Group: Moderators
  • Posts: 916
  • Joined: 27-July 10
  • Location:Curitiba - Brasil

Posted 10 January 2012 - 06:41 AM

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.

Gustavo
--
Extensions:
translate modue - module to handle translations
multiActiveRecord - db selection in models
redisCache - redis cache component
mpCpanel - interact with cpanel api
mUploadify - use uploadify uploader in your application

Gustavo Salomé Silva
0

#16 User is offline   bigshamallow 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 09-January 12

Posted 14 January 2012 - 01:49 PM

View PostGustavo, on 10 January 2012 - 06:41 AM, said:

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.

Gustavo

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

public function accessRules() {
	return array(
			array('allow',
				'actions'=>array('index','view'),
				'roles'=>array('admin', 'core', 5), 
				),
			array('allow', 
				'actions'=>array('minicreate', 'create','update'),
				'roles'=>array('UserCreator'),
				),
			array('allow', 
				'actions'=>array('admin','delete'),
				'users'=>array('admin'),
				),
			array('deny', 
				'users'=>array('*'),
				),
			);
}


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

array('allow', 
  'actions'=>array('update','admin'), 
  'groups'=>array('admin', 'core', 5), 
),

when running the answer is :

Property « CAccessRule.groups » is undefined.

???

I've missed something ?

Shama
0

#17 User is offline   bigshamallow 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 09-January 12

Posted 24 January 2012 - 09:01 PM

Shama was sleeping ... (RTFM)

just declare with correct filter's string :

	
public function filters() {
	return array(
		'userGroupsAccessControl', 
	);
}


:-X

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

BASEYIIDIR/protected/extensions/giix-core/giixCrud/templates/default/auth/auth_filter_default.php


enjoy !

Shama
1

#18 User is offline   cappadochian 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 147
  • Joined: 02-January 11

Posted 29 March 2012 - 01:59 AM

hi!

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?
0

#19 User is offline   SapporoGuy 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 177
  • Joined: 25-December 10
  • Location:Sappor Beer Refinery

Posted 29 March 2012 - 03:49 AM

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.
0

#20 User is offline   jowen 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 191
  • Joined: 13-July 11
  • Location:Malaysia

Posted 10 April 2012 - 04:06 AM

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??

  'components'=>array(
        //define the class and its missingTranslation event
        'messages'=>array(
            'class'=>'CDbMessageSource',
            'onMissingTranslation' => array('TranslateModule', 'missingTranslation'),  <--- this line
        ),


thanks man.
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users