add support for selecting certain engines in API
Some checks are pending
mozhi pipeline / Push Docker image to Codeberg docker registry (push) Waiting to run
mozhi pipeline / Build and publish artifacts (push) Waiting to run

This commit is contained in:
2024-04-03 17:03:14 +05:30
parent 10f76a7387
commit 721bd07771
4 changed files with 72 additions and 30 deletions

View File

@@ -2,6 +2,7 @@ package pages
import (
"codeberg.org/aryak/libmozhi"
"strings"
"codeberg.org/aryak/mozhi/utils"
"github.com/gofiber/fiber/v2"
)
@@ -85,6 +86,13 @@ func HandleTranslate(c *fiber.Ctx) error {
if engine == "all" {
dataarr := libmozhi.TranslateAll(to, from, text)
return c.JSON(dataarr)
} else if strings.Contains(engine, ",") == true {
engineArr := strings.Split(engine, ",")
dataarr, err := libmozhi.TranslateSome(engineArr, to, from, text)
if err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
}
return c.JSON(dataarr)
} else {
data, err := libmozhi.Translate(engine, to, from, text)
if err != nil {