Translate module Simple module to handle application translations
#1
Posted 10 May 2011 - 06:10 AM
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
#2
Posted 10 May 2011 - 02:31 PM
This will really come in handy when I get around to translating my app.
Thanks.
#3
Posted 11 May 2011 - 07:50 AM
<?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');
#4
Posted 11 May 2011 - 08:02 AM
#5
Posted 11 May 2011 - 09:05 AM
duna, on 11 May 2011 - 07:50 AM, said:
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
#6
Posted 16 May 2011 - 04:23 PM
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;
}
}
}
}
}
Toshi
YM : toshifirmasyah
Skype : toshifirmansyah
#7
Posted 16 May 2011 - 04:34 PM
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
#8
Posted 18 May 2011 - 03:00 PM
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
#9
Posted 18 August 2011 - 04:45 AM
Gustavo, on 18 May 2011 - 03:00 PM, said:
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
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
#10
Posted 18 August 2011 - 06:28 PM
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
#11
Posted 22 August 2011 - 01:22 AM
Gustavo, on 18 August 2011 - 06:28 PM, said:
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
#12
Posted 23 August 2011 - 02:14 AM
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
#13
Posted 23 August 2011 - 02:14 AM
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
#14
Posted 09 January 2012 - 10:47 PM
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
#15
Posted 10 January 2012 - 06:41 AM
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
#16
Posted 14 January 2012 - 01:49 PM
Gustavo, on 10 January 2012 - 06:41 AM, said:
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
#17
Posted 24 January 2012 - 09:01 PM
just declare with correct filter's string :
public function filters() {
return array(
'userGroupsAccessControl',
);
}for other candidate, I've patched the default Giix rules template. So Giix generates directly the right code
BASEYIIDIR/protected/extensions/giix-core/giixCrud/templates/default/auth/auth_filter_default.php
enjoy !
Shama
#18
Posted 29 March 2012 - 01:59 AM
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?
#19
Posted 29 March 2012 - 03:49 AM
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.
#20
Posted 10 April 2012 - 04:06 AM
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.

Help













