mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-17 16:20:33 -07:00
refactor: rename variables & change some data type to interface array
This commit is contained in:
parent
39c892156c
commit
42b01a8cb2
@ -69,17 +69,19 @@ func (t *GoogleTranslate) Translate(message string) (translation, definition, pa
|
|||||||
}
|
}
|
||||||
// part of speech = data[1]
|
// part of speech = data[1]
|
||||||
if data[1] != nil {
|
if data[1] != nil {
|
||||||
for _, parts := range data[1].([]interface{}) {
|
for _, partOfSpeeches := range data[1].([]interface{}) {
|
||||||
|
partOfSpeeches := partOfSpeeches.([]interface{})
|
||||||
// part of speech
|
// part of speech
|
||||||
part := parts.([]interface{})[0]
|
pos := partOfSpeeches[0]
|
||||||
partOfSpeech += fmt.Sprintf("[%v]\n", part)
|
partOfSpeech += fmt.Sprintf("[%v]\n", pos)
|
||||||
for _, words := range parts.([]interface{})[2].([]interface{}) {
|
for _, words := range partOfSpeeches[2].([]interface{}) {
|
||||||
|
words := words.([]interface{})
|
||||||
// dst lang
|
// dst lang
|
||||||
dstWord := words.([]interface{})[0]
|
dstWord := words[0]
|
||||||
partOfSpeech += fmt.Sprintf("\t%v:", dstWord)
|
partOfSpeech += fmt.Sprintf("\t%v:", dstWord)
|
||||||
// src lang
|
// src lang
|
||||||
firstWord := true
|
firstWord := true
|
||||||
for _, word := range words.([]interface{})[1].([]interface{}) {
|
for _, word := range words[1].([]interface{}) {
|
||||||
if firstWord {
|
if firstWord {
|
||||||
partOfSpeech += fmt.Sprintf(" %v", word)
|
partOfSpeech += fmt.Sprintf(" %v", word)
|
||||||
firstWord = false
|
firstWord = false
|
||||||
@ -93,17 +95,19 @@ func (t *GoogleTranslate) Translate(message string) (translation, definition, pa
|
|||||||
}
|
}
|
||||||
// definition = data[12]
|
// definition = data[12]
|
||||||
if len(data) >= 13 && data[12] != nil {
|
if len(data) >= 13 && data[12] != nil {
|
||||||
for _, parts := range data[12].([]interface{}) {
|
for _, definitions := range data[12].([]interface{}) {
|
||||||
|
definitions := definitions.([]interface{})
|
||||||
// part of speech
|
// part of speech
|
||||||
part := parts.([]interface{})[0]
|
pos := definitions[0]
|
||||||
definition += fmt.Sprintf("[%v]\n", part)
|
definition += fmt.Sprintf("[%v]\n", pos)
|
||||||
for _, sentences := range parts.([]interface{})[1].([]interface{}) {
|
for _, sentences := range definitions[1].([]interface{}) {
|
||||||
|
sentences := sentences.([]interface{})
|
||||||
// definition
|
// definition
|
||||||
def := sentences.([]interface{})[0]
|
def := sentences[0]
|
||||||
definition += fmt.Sprintf("\t- %v\n", def)
|
definition += fmt.Sprintf("\t- %v\n", def)
|
||||||
// example sentence
|
// example sentence
|
||||||
if len(sentences.([]interface{})) >= 3 && sentences.([]interface{})[2] != nil {
|
if len(sentences) >= 3 && sentences[2] != nil {
|
||||||
example := sentences.([]interface{})[2]
|
example := sentences[2]
|
||||||
definition += fmt.Sprintf("\t\t\"%v\"\n", example)
|
definition += fmt.Sprintf("\t\t\"%v\"\n", example)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user