Fixed bug
git-svn-id: file:///srv/svn/repo/mai/trunk@40 e410bdd4-646f-c54f-a7ce-fffcc4f439ae
This commit is contained in:
@@ -153,17 +153,17 @@ func (_ *GoogleTranslate) Translate(text string, from, to string) (TranslationRe
|
|||||||
return TranslationResult{}, nil
|
return TranslationResult{}, nil
|
||||||
}
|
}
|
||||||
responseText := string(bodyBytes)
|
responseText := string(bodyBytes)
|
||||||
|
responseTextList := regexp.MustCompile(`\n\d+\n(.*)\n\d+\n`).FindStringSubmatch(responseText)
|
||||||
responseText = regexp.MustCompile(`\n\d+\n(.*)\n\d+\n`).FindStringSubmatch(responseText)[1]
|
definitions := make(map[string][]map[string]interface{})
|
||||||
|
translations := make(map[string]map[string]map[string]interface{})
|
||||||
|
if len(responseTextList) > 0 {
|
||||||
|
responseText = responseTextList[1]
|
||||||
var raw []interface{}
|
var raw []interface{}
|
||||||
err = json.Unmarshal([]byte(responseText), &raw)
|
err = json.Unmarshal([]byte(responseText), &raw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error:", err)
|
fmt.Println("Error:", err)
|
||||||
return TranslationResult{}, nil
|
return TranslationResult{}, nil
|
||||||
}
|
}
|
||||||
definitions := make(map[string][]map[string]interface{})
|
|
||||||
translations := make(map[string]map[string]map[string]interface{})
|
|
||||||
|
|
||||||
if len(raw) > 0 && raw[0] != nil &&
|
if len(raw) > 0 && raw[0] != nil &&
|
||||||
len(raw[0].([]interface{})) > 2 && raw[0].([]interface{})[2] != nil {
|
len(raw[0].([]interface{})) > 2 && raw[0].([]interface{})[2] != nil {
|
||||||
@@ -275,6 +275,8 @@ func (_ *GoogleTranslate) Translate(text string, from, to string) (TranslationRe
|
|||||||
if len(json_) > 0 && json_[0] != nil && len(json_[0].([]interface{})) > 2 && json_[0].([]interface{})[2] != nil {
|
if len(json_) > 0 && json_[0] != nil && len(json_[0].([]interface{})) > 2 && json_[0].([]interface{})[2] != nil {
|
||||||
from = json_[0].([]interface{})[2].(string)
|
from = json_[0].([]interface{})[2].(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if from == "auto" {
|
if from == "auto" {
|
||||||
|
|||||||
Reference in New Issue
Block a user