mirror of
https://codeberg.org/aryak/mozhi
synced 2024-11-30 00:21:59 +05:30
store preferred langpair, engine as a cookie (closes #19)
This commit is contained in:
parent
e63ae7e8a7
commit
403f68ddf1
@ -27,11 +27,17 @@ func HandleIndex(c *fiber.Ctx) error {
|
|||||||
for engine := range engines {
|
for engine := range engines {
|
||||||
enginesAsArray = append(enginesAsArray, engine)
|
enginesAsArray = append(enginesAsArray, engine)
|
||||||
}
|
}
|
||||||
|
engineCookie := c.Cookies("engine")
|
||||||
|
fromCookie := c.Cookies("from")
|
||||||
|
toCookie := c.Cookies("to")
|
||||||
var engine = utils.GetQueryOrFormValue(c, "engine")
|
var engine = utils.GetQueryOrFormValue(c, "engine")
|
||||||
if engine == "" || !slices.Contains(enginesAsArray, engine) {
|
if engine == "" || !slices.Contains(enginesAsArray, engine) {
|
||||||
|
if engineCookie != "" {
|
||||||
|
engine = engineCookie
|
||||||
|
} else {
|
||||||
engine = "google"
|
engine = "google"
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var sourceLanguages []libmozhi.List
|
var sourceLanguages []libmozhi.List
|
||||||
var targetLanguages []libmozhi.List
|
var targetLanguages []libmozhi.List
|
||||||
@ -47,9 +53,15 @@ func HandleIndex(c *fiber.Ctx) error {
|
|||||||
from := utils.GetQueryOrFormValue(c, "from")
|
from := utils.GetQueryOrFormValue(c, "from")
|
||||||
if from == "" {
|
if from == "" {
|
||||||
from = utils.GetQueryOrFormValue(c, "sl")
|
from = utils.GetQueryOrFormValue(c, "sl")
|
||||||
|
if from == "" && fromCookie != "" {
|
||||||
|
from = fromCookie
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if to == "" {
|
if to == "" {
|
||||||
to = utils.GetQueryOrFormValue(c, "tl")
|
to = utils.GetQueryOrFormValue(c, "tl")
|
||||||
|
if to == "" && toCookie != "" {
|
||||||
|
to = toCookie
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var translation libmozhi.LangOut
|
var translation libmozhi.LangOut
|
||||||
@ -88,6 +100,22 @@ func HandleIndex(c *fiber.Ctx) error {
|
|||||||
if defaultLangTarget == "" {
|
if defaultLangTarget == "" {
|
||||||
defaultLangTarget = "en"
|
defaultLangTarget = "en"
|
||||||
}
|
}
|
||||||
|
cookie := new(fiber.Cookie)
|
||||||
|
cookie.Name = "engine"
|
||||||
|
cookie.Value = engine
|
||||||
|
c.Cookie(cookie)
|
||||||
|
if from != "" {
|
||||||
|
cookie := new(fiber.Cookie)
|
||||||
|
cookie.Name = "from"
|
||||||
|
cookie.Value = from
|
||||||
|
c.Cookie(cookie)
|
||||||
|
}
|
||||||
|
if to != "" {
|
||||||
|
cookie := new(fiber.Cookie)
|
||||||
|
cookie.Name = "to"
|
||||||
|
cookie.Value = to
|
||||||
|
c.Cookie(cookie)
|
||||||
|
}
|
||||||
return c.Render("index", fiber.Map{
|
return c.Render("index", fiber.Map{
|
||||||
"Engine": engine,
|
"Engine": engine,
|
||||||
"enginesNames": engines,
|
"enginesNames": engines,
|
||||||
|
Loading…
Reference in New Issue
Block a user