mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-29 05:50:17 -07:00
fix: contextResults is nil
This commit is contained in:
parent
2a9c52bcb2
commit
40fe5397ab
@ -90,24 +90,26 @@ func (t *ReversoTranslate) Translate(message string) (translation, definition, p
|
|||||||
// translation
|
// translation
|
||||||
translation += fmt.Sprintf("%v", data["translation"].([]interface{})[0])
|
translation += fmt.Sprintf("%v", data["translation"].([]interface{})[0])
|
||||||
// definition and part of speech
|
// definition and part of speech
|
||||||
for _, results := range data["contextResults"].(map[string]interface{})["results"].([]interface{}) {
|
if data["contextResults"] != nil {
|
||||||
results := results.(map[string]interface{})
|
for _, results := range data["contextResults"].(map[string]interface{})["results"].([]interface{}) {
|
||||||
// definition
|
results := results.(map[string]interface{})
|
||||||
srcExample := results["sourceExamples"].([]interface{})
|
// definition
|
||||||
dstExample := results["targetExamples"].([]interface{})
|
srcExample := results["sourceExamples"].([]interface{})
|
||||||
if len(srcExample) > 0 && len(dstExample) > 0 {
|
dstExample := results["targetExamples"].([]interface{})
|
||||||
for i := 0; i < len(srcExample) && i < len(dstExample); i++ {
|
if len(srcExample) > 0 && len(dstExample) > 0 {
|
||||||
definition += fmt.Sprintf("- %v\n\t\"%v\"\n", srcExample[i], dstExample[i])
|
for i := 0; i < len(srcExample) && i < len(dstExample); i++ {
|
||||||
|
definition += fmt.Sprintf("- %v\n\t\"%v\"\n", srcExample[i], dstExample[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// part of speech
|
||||||
|
if results["partOfSpeech"] == nil {
|
||||||
|
partOfSpeech += fmt.Sprintf("%v\n", results["translation"])
|
||||||
|
} else {
|
||||||
|
partOfSpeech += fmt.Sprintf("%v [%v]\n", results["translation"], results["partOfSpeech"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// part of speech
|
definition = regexp.MustCompile("<(|/)em>").ReplaceAllString(definition, "")
|
||||||
if results["partOfSpeech"] == nil {
|
|
||||||
partOfSpeech += fmt.Sprintf("%v\n", results["translation"])
|
|
||||||
} else {
|
|
||||||
partOfSpeech += fmt.Sprintf("%v [%v]\n", results["translation"], results["partOfSpeech"])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
definition = regexp.MustCompile("<(|/)em>").ReplaceAllString(definition, "")
|
|
||||||
|
|
||||||
return translation, definition, partOfSpeech, nil
|
return translation, definition, partOfSpeech, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user