mirror of
https://codeberg.org/aryak/mozhi
synced 2024-11-23 04:32:58 +05:30
make switchlanguage swap text (closes #10)
This commit is contained in:
parent
9ab37afc1a
commit
5984fdf1d9
@ -7,6 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
"codeberg.org/aryak/libmozhi"
|
||||||
_ "codeberg.org/aryak/mozhi/docs"
|
_ "codeberg.org/aryak/mozhi/docs"
|
||||||
"codeberg.org/aryak/mozhi/pages"
|
"codeberg.org/aryak/mozhi/pages"
|
||||||
"codeberg.org/aryak/mozhi/public"
|
"codeberg.org/aryak/mozhi/public"
|
||||||
@ -102,8 +103,17 @@ func Serve(port string) {
|
|||||||
engine := utils.Sanitize(utils.GetQueryOrFormValue(c, "engine"), "alpha")
|
engine := utils.Sanitize(utils.GetQueryOrFormValue(c, "engine"), "alpha")
|
||||||
from := utils.Sanitize(utils.GetQueryOrFormValue(c, "from"), "alpha")
|
from := utils.Sanitize(utils.GetQueryOrFormValue(c, "from"), "alpha")
|
||||||
to := utils.Sanitize(utils.GetQueryOrFormValue(c, "to"), "alpha")
|
to := utils.Sanitize(utils.GetQueryOrFormValue(c, "to"), "alpha")
|
||||||
text := utils.Sanitize(utils.GetQueryOrFormValue(c, "text"), "alpha")
|
text := utils.GetQueryOrFormValue(c, "text")
|
||||||
return c.Redirect("/?engine="+engine+"&from="+to+"&to="+from+"&text="+text+"&redirected=true", 301)
|
var swapText string
|
||||||
|
if engine != "all" && text != "" {
|
||||||
|
translation, tlerr := libmozhi.Translate(engine, to, from, text)
|
||||||
|
if tlerr == nil {
|
||||||
|
swapText = translation.OutputText
|
||||||
|
} else {
|
||||||
|
swapText = text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return c.Redirect("/?engine="+engine+"&from="+to+"&to="+from+"&text="+swapText+"&redirected=true", 301)
|
||||||
})
|
})
|
||||||
app.Get("/about", pages.HandleAbout)
|
app.Get("/about", pages.HandleAbout)
|
||||||
app.Use("/", filesystem.New(filesystem.Config{
|
app.Use("/", filesystem.New(filesystem.Config{
|
||||||
|
Loading…
Reference in New Issue
Block a user