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.
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
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;
}
}
}
}
}
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.
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.
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 :
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?
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
),
@Gustavo: Glad to find someone with the same issue
I am currently tinkering with UserGroups and Translate Module to fix this issue, without complete success. I am also using this technique. I’m really confused about the hierarchy of processing of modules, controllers, and components.
How do I fix the issue (such that using language-indicating URLs are properly processed, routed and missing translations in the UserGroups module get added (wherever Yii::t has been used there) )?
Can you give me some docs/links to understand the differences between and order of execution of the above?