initial commit
All checks were successful
Build and publish the docker image / build (push) Successful in 58s
All checks were successful
Build and publish the docker image / build (push) Successful in 58s
Signed-off-by: ngn <ngn@ngn.tf>
This commit is contained in:
46
routes/translate.go
Normal file
46
routes/translate.go
Normal file
@ -0,0 +1,46 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"git.ngn.tf/ngn/tren/extract"
|
||||
"git.ngn.tf/ngn/tren/util"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type translate_form struct {
|
||||
Dictionary string
|
||||
Term string
|
||||
}
|
||||
|
||||
func POST_translate(c *fiber.Ctx) error {
|
||||
var (
|
||||
extractor *extract.Extractor
|
||||
trans *extract.Translation
|
||||
form translate_form
|
||||
err error
|
||||
)
|
||||
|
||||
extractor = c.Locals("extractor").(*extract.Extractor)
|
||||
|
||||
if err = c.BodyParser(&form); err != nil {
|
||||
return util.RenderError(c, 400)
|
||||
}
|
||||
|
||||
if form.Dictionary == "" || form.Term == "" {
|
||||
return util.RenderError(c, 400)
|
||||
}
|
||||
|
||||
if trans, err = extractor.Translate(form.Dictionary, form.Term); err != nil {
|
||||
return util.RenderError(c, 500, err)
|
||||
}
|
||||
|
||||
if trans == nil {
|
||||
return util.RenderError(c, 400)
|
||||
}
|
||||
|
||||
return util.Render(c, "translate", fiber.Map{
|
||||
"term": form.Term,
|
||||
"fields": trans.Fields,
|
||||
"entries": trans.Entries,
|
||||
"suggestions": trans.Suggestions,
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user