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;
}
}
}
}
}