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

style: rename

This commit is contained in:
eeeXun 2023-04-19 13:18:56 +08:00
parent 0d6a3576d6
commit adc1e2e632
2 changed files with 7 additions and 7 deletions

View File

@ -143,14 +143,14 @@ func (t *BingTranslate) Translate(message string) (translation, definition, part
if err != nil { if err != nil {
return "", "", "", err return "", "", "", err
} }
// Bing will return a list request part of speech success // Bing will return the request with list when success
// Otherwises, it would return map // Otherwises, it would return map
// Then the following err would not be nil // Then the following err would not be nil
if err = json.Unmarshal(body, &data); err == nil { if err = json.Unmarshal(body, &data); err == nil {
set := make(posSet) set := make(posSet)
for _, pos := range data[0].(map[string]interface{})["translations"].([]interface{}) { for _, pos := range data[0].(map[string]interface{})["translations"].([]interface{}) {
pos := pos.(map[string]interface{}) pos := pos.(map[string]interface{})
var words translationWord var words translationWords
words.target = pos["displayTarget"].(string) words.target = pos["displayTarget"].(string)
for _, backTranslation := range pos["backTranslations"].([]interface{}) { for _, backTranslation := range pos["backTranslations"].([]interface{}) {

View File

@ -4,20 +4,20 @@ import (
"fmt" "fmt"
) )
type translationWord struct { type translationWords struct {
target string target string
backTargets []string backTargets []string
} }
func (t *translationWord) add(s string) { func (t *translationWords) add(s string) {
t.backTargets = append(t.backTargets, s) t.backTargets = append(t.backTargets, s)
} }
type posSet map[string][]translationWord type posSet map[string][]translationWords
func (set posSet) add(tag string, words translationWord) { func (set posSet) add(tag string, words translationWords) {
if _, ok := set[tag]; !ok { if _, ok := set[tag]; !ok {
set[tag] = []translationWord{words} set[tag] = []translationWords{words}
} else { } else {
set[tag] = append(set[tag], words) set[tag] = append(set[tag], words)
} }