mirror of
https://codeberg.org/aryak/mozhi
synced 2025-06-04 00:41:07 +05:30
refactor: cleanup and simplify code
This commit is contained in:
12
pages/api.go
12
pages/api.go
@@ -82,20 +82,14 @@ func HandleTranslate(c *fiber.Ctx) error {
|
||||
if engine == "" || from == "" || to == "" || text == "" {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "from, to, engine, text are required query strings.")
|
||||
}
|
||||
var dataarr []libmozhi.LangOut
|
||||
var data libmozhi.LangOut
|
||||
var err error
|
||||
if engine == "all" {
|
||||
dataarr = libmozhi.TranslateAll(to, from, text)
|
||||
dataarr := libmozhi.TranslateAll(to, from, text)
|
||||
return c.JSON(dataarr)
|
||||
} else {
|
||||
data, err = libmozhi.Translate(engine, to, from, text)
|
||||
data, err := libmozhi.Translate(engine, to, from, text)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
}
|
||||
}
|
||||
if engine == "all" {
|
||||
return c.JSON(dataarr)
|
||||
} else {
|
||||
return c.JSON(data)
|
||||
}
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ import (
|
||||
func langListMerge(engines map[string]string) ([]libmozhi.List, []libmozhi.List) {
|
||||
sl := []libmozhi.List{}
|
||||
tl := []libmozhi.List{}
|
||||
for key, _ := range engines {
|
||||
for key := range engines {
|
||||
temp, _ := libmozhi.LangList(key, "sl")
|
||||
temp2, _ := libmozhi.LangList(key, "tl")
|
||||
sl = append(sl, temp...)
|
||||
|
Reference in New Issue
Block a user