mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-19 17:21:26 -07:00
style: move main code out of if statement
This commit is contained in:
parent
303441125b
commit
c1ebe7eb3c
@ -71,7 +71,10 @@ func (t *ApertiumTranslate) Translate(message string) (translation, definition,
|
|||||||
return "", "", "", err
|
return "", "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(data) > 0 {
|
if len(data) <= 0 {
|
||||||
|
return "", "", "", errors.New("Translation not found")
|
||||||
|
}
|
||||||
|
|
||||||
switch res.StatusCode {
|
switch res.StatusCode {
|
||||||
case 200:
|
case 200:
|
||||||
translation += fmt.Sprintf("%v",
|
translation += fmt.Sprintf("%v",
|
||||||
@ -88,5 +91,3 @@ func (t *ApertiumTranslate) Translate(message string) (translation, definition,
|
|||||||
|
|
||||||
return translation, definition, partOfSpeech, nil
|
return translation, definition, partOfSpeech, nil
|
||||||
}
|
}
|
||||||
return "", "", "", errors.New("Translation not found")
|
|
||||||
}
|
|
||||||
|
@ -70,10 +70,11 @@ func (t *ArgosTranslate) Translate(message string) (translation, definition, par
|
|||||||
return "", "", "", err
|
return "", "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(data) > 0 {
|
if len(data) <= 0 {
|
||||||
|
return "", "", "", errors.New("Translation not found")
|
||||||
|
}
|
||||||
|
|
||||||
translation += fmt.Sprintf("%v", data["translatedText"])
|
translation += fmt.Sprintf("%v", data["translatedText"])
|
||||||
|
|
||||||
return translation, definition, partOfSpeech, nil
|
return translation, definition, partOfSpeech, nil
|
||||||
}
|
}
|
||||||
return "", "", "", errors.New("Translation not found")
|
|
||||||
}
|
|
||||||
|
@ -71,13 +71,15 @@ func (t *GoogleTranslate) Translate(message string) (translation, definition, pa
|
|||||||
return "", "", "", err
|
return "", "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(data) > 0 {
|
if len(data) <= 0 {
|
||||||
|
return "", "", "", errors.New("Translation not found")
|
||||||
|
}
|
||||||
|
|
||||||
// translation = data[0]
|
// translation = data[0]
|
||||||
for _, lines := range data[0].([]interface{}) {
|
for _, lines := range data[0].([]interface{}) {
|
||||||
translatedLine := lines.([]interface{})[0]
|
translatedLine := lines.([]interface{})[0]
|
||||||
translation += fmt.Sprintf("%v", translatedLine)
|
translation += fmt.Sprintf("%v", translatedLine)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 _, parts := range data[1].([]interface{}) {
|
||||||
@ -102,7 +104,6 @@ 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 _, parts := range data[12].([]interface{}) {
|
||||||
@ -121,8 +122,6 @@ func (t *GoogleTranslate) Translate(message string) (translation, definition, pa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return translation, definition, partOfSpeech, nil
|
return translation, definition, partOfSpeech, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", "", "", errors.New("Translation not found")
|
|
||||||
}
|
|
||||||
|
@ -54,9 +54,8 @@ func (t *GoogleTranslate) PlayTTS(lang, message string) error {
|
|||||||
if t.SoundLock.Stop {
|
if t.SoundLock.Stop {
|
||||||
t.SoundLock.Release()
|
t.SoundLock.Release()
|
||||||
return nil
|
return nil
|
||||||
} else {
|
|
||||||
time.Sleep(time.Millisecond)
|
|
||||||
}
|
}
|
||||||
|
time.Sleep(time.Millisecond)
|
||||||
}
|
}
|
||||||
if err = player.Close(); err != nil {
|
if err = player.Close(); err != nil {
|
||||||
t.SoundLock.Release()
|
t.SoundLock.Release()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user