Skip to content

Commit

Permalink
style: Declare string only once in Translate & PlayTTS
Browse files Browse the repository at this point in the history
  • Loading branch information
eeeXun committed Feb 12, 2023
1 parent 3480526 commit 0239561
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 18 deletions.
6 changes: 1 addition & 5 deletions internal/translate/argostranslate/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ func (t *ArgosTranslate) SwapLang() {
t.srcLang, t.dstLang = t.dstLang, t.srcLang
}

func (t *ArgosTranslate) Translate(message string) (
translation string,
definition string,
partOfSpeech string,
err error) {
func (t *ArgosTranslate) Translate(message string) (translation, definition, partOfSpeech string, err error) {
var data interface{}

res, err := http.PostForm(textURL,
Expand Down
2 changes: 1 addition & 1 deletion internal/translate/argostranslate/tts.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func (t *ArgosTranslate) StopTTS() {
t.SoundLock.Stop = true
}

func (t *ArgosTranslate) PlayTTS(lang string, message string) error {
func (t *ArgosTranslate) PlayTTS(lang, message string) error {
t.SoundLock.Release()
return errors.New(t.EngineName + " does not support text to speech")
}
6 changes: 1 addition & 5 deletions internal/translate/googletranslate/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ func (t *GoogleTranslate) SwapLang() {
t.srcLang, t.dstLang = t.dstLang, t.srcLang
}

func (t *GoogleTranslate) Translate(message string) (
translation string,
definition string,
partOfSpeech string,
err error) {
func (t *GoogleTranslate) Translate(message string) (translation, definition, partOfSpeech string, err error) {
var data []interface{}

urlStr := fmt.Sprintf(
Expand Down
2 changes: 1 addition & 1 deletion internal/translate/googletranslate/tts.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (t *GoogleTranslate) StopTTS() {
t.SoundLock.Stop = true
}

func (t *GoogleTranslate) PlayTTS(lang string, message string) error {
func (t *GoogleTranslate) PlayTTS(lang, message string) error {
urlStr := fmt.Sprintf(
ttsURL,
url.QueryEscape(message),
Expand Down
8 changes: 2 additions & 6 deletions internal/translate/translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,12 @@ type Translator interface {
SetSrcLang(srcLang string)
SetDstLang(dstLang string)
SwapLang()
Translate(message string) (
translation string,
definition string,
partOfSpeech string,
err error)
Translate(message string) (translation, definition, partOfSpeech string, err error)
// text to speech
LockAvailable() bool
LockAcquire()
StopTTS()
PlayTTS(lang string, message string) error
PlayTTS(lang, message string) error
}

func NewTranslator(name string) Translator {
Expand Down

0 comments on commit 0239561

Please sign in to comment.