Include more translations in result list
This commit is contained in:
@ -5,6 +5,7 @@ import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
"log"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
|
||||
@ -35,7 +36,7 @@ func executeTransShell(tj TransJob) ([]byte, error) {
|
||||
"-no-ansi",
|
||||
"-show-original", "n",
|
||||
"-show-original-phonetics", "n",
|
||||
"-show-dictionary", "n",
|
||||
"-show-dictionary", "y",
|
||||
"-show-languages", "n",
|
||||
"-show-prompt-message", "n",
|
||||
fmt.Sprintf("%s:%s", tj.fromLang, tj.toLang),
|
||||
@ -53,15 +54,16 @@ func (t Translation) Translate() []string {
|
||||
}
|
||||
|
||||
func parseTransOutput(out string) []string {
|
||||
outLines := strings.Split(out, "\n")
|
||||
translation := outLines[0]
|
||||
re := regexp.MustCompile(`(?m)^\s{4}\w.*$`)
|
||||
lineMatches := re.FindAllString(out, -1)
|
||||
|
||||
additionalTranslations := strings.Split(outLines[len(outLines)-2], ",")
|
||||
for i, translation := range additionalTranslations {
|
||||
additionalTranslations[i] = strings.TrimSpace(translation)
|
||||
results := []string{strings.Split(out, "\n")[0]}
|
||||
for _, line := range lineMatches {
|
||||
for _, word := range strings.Split(strings.TrimSpace(line), ",") {
|
||||
results = append(results, strings.TrimSpace(word))
|
||||
}
|
||||
}
|
||||
|
||||
return append([]string{translation}, additionalTranslations...)
|
||||
return results
|
||||
}
|
||||
|
||||
func uniqueSlice(items []string) []string {
|
||||
|
Reference in New Issue
Block a user