v/GTT
1
0
mirror of https://github.com/eeeXun/GTT.git synced 2025-05-19 09:10:42 -07:00

style: move main code out of if statement

This commit is contained in:
eeeXun 2023-02-15 20:39:53 +08:00
parent 303441125b
commit c1ebe7eb3c
4 changed files with 76 additions and 76 deletions

View File

@ -71,7 +71,10 @@ func (t *ApertiumTranslate) Translate(message string) (translation, definition,
return "", "", "", err
}
if len(data) > 0 {
if len(data) <= 0 {
return "", "", "", errors.New("Translation not found")
}
switch res.StatusCode {
case 200:
translation += fmt.Sprintf("%v",
@ -87,6 +90,4 @@ func (t *ApertiumTranslate) Translate(message string) (translation, definition,
}
return translation, definition, partOfSpeech, nil
}
return "", "", "", errors.New("Translation not found")
}

View File

@ -70,10 +70,11 @@ func (t *ArgosTranslate) Translate(message string) (translation, definition, par
return "", "", "", err
}
if len(data) > 0 {
if len(data) <= 0 {
return "", "", "", errors.New("Translation not found")
}
translation += fmt.Sprintf("%v", data["translatedText"])
return translation, definition, partOfSpeech, nil
}
return "", "", "", errors.New("Translation not found")
}

View File

@ -71,13 +71,15 @@ func (t *GoogleTranslate) Translate(message string) (translation, definition, pa
return "", "", "", err
}
if len(data) > 0 {
if len(data) <= 0 {
return "", "", "", errors.New("Translation not found")
}
// translation = data[0]
for _, lines := range data[0].([]interface{}) {
translatedLine := lines.([]interface{})[0]
translation += fmt.Sprintf("%v", translatedLine)
}
// part of speech = data[1]
if data[1] != nil {
for _, parts := range data[1].([]interface{}) {
@ -102,7 +104,6 @@ func (t *GoogleTranslate) Translate(message string) (translation, definition, pa
}
}
}
// definition = data[12]
if len(data) >= 13 && data[12] != nil {
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 "", "", "", errors.New("Translation not found")
return translation, definition, partOfSpeech, nil
}

View File

@ -54,9 +54,8 @@ func (t *GoogleTranslate) PlayTTS(lang, message string) error {
if t.SoundLock.Stop {
t.SoundLock.Release()
return nil
} else {
time.Sleep(time.Millisecond)
}
time.Sleep(time.Millisecond)
}
if err = player.Close(); err != nil {
t.SoundLock.Release()