mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-21 18:10:17 -07:00
fix: part of speech may be nil
This commit is contained in:
parent
7d62d0bee2
commit
dd408d36bc
@ -69,8 +69,11 @@ func (t *LingvaTranslate) Translate(message string) (translation, definition, pa
|
|||||||
for _, definitions := range data["info"].(map[string]interface{})["definitions"].([]interface{}) {
|
for _, definitions := range data["info"].(map[string]interface{})["definitions"].([]interface{}) {
|
||||||
definitions := definitions.(map[string]interface{})
|
definitions := definitions.(map[string]interface{})
|
||||||
// part of speech
|
// part of speech
|
||||||
pos := definitions["type"]
|
if pos, ok := definitions["type"]; ok {
|
||||||
definition += fmt.Sprintf("[%v]\n", pos)
|
definition += fmt.Sprintf("[%v]\n", pos)
|
||||||
|
} else {
|
||||||
|
definition += "[]\n"
|
||||||
|
}
|
||||||
for _, sentences := range definitions["list"].([]interface{}) {
|
for _, sentences := range definitions["list"].([]interface{}) {
|
||||||
sentences := sentences.(map[string]interface{})
|
sentences := sentences.(map[string]interface{})
|
||||||
// definition
|
// definition
|
||||||
@ -86,8 +89,11 @@ func (t *LingvaTranslate) Translate(message string) (translation, definition, pa
|
|||||||
for _, partOfSpeeches := range data["info"].(map[string]interface{})["extraTranslations"].([]interface{}) {
|
for _, partOfSpeeches := range data["info"].(map[string]interface{})["extraTranslations"].([]interface{}) {
|
||||||
partOfSpeeches := partOfSpeeches.(map[string]interface{})
|
partOfSpeeches := partOfSpeeches.(map[string]interface{})
|
||||||
// part of speech
|
// part of speech
|
||||||
pos := partOfSpeeches["type"]
|
if pos, ok := partOfSpeeches["type"]; ok {
|
||||||
partOfSpeech += fmt.Sprintf("[%v]\n", pos)
|
partOfSpeech += fmt.Sprintf("[%v]\n", pos)
|
||||||
|
} else {
|
||||||
|
partOfSpeech += "[]\n"
|
||||||
|
}
|
||||||
for _, words := range partOfSpeeches["list"].([]interface{}) {
|
for _, words := range partOfSpeeches["list"].([]interface{}) {
|
||||||
words := words.(map[string]interface{})
|
words := words.(map[string]interface{})
|
||||||
dstWord := words["word"]
|
dstWord := words["word"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user