Improved code

git-svn-id: file:///srv/svn/repo/mai/trunk@20 e410bdd4-646f-c54f-a7ce-fffcc4f439ae
This commit is contained in:
manerakai
2023-08-31 08:28:02 +00:00
parent a550111b23
commit 4b95465cbe
7 changed files with 51 additions and 31 deletions

View File

@@ -90,8 +90,8 @@ func main() {
return c.Render("index", fiber.Map{
"Engine": engine,
"enginesNames": enginesNames,
"SourceLanguages": targetLanguages,
"TargetLanguages": sourceLanguages,
"SourceLanguages": sourceLanguages,
"TargetLanguages": targetLanguages,
"OriginalText": originalText,
"TranslatedText": translatedText,
"From": from,
@@ -168,9 +168,6 @@ func main() {
}
lang := c.Query("lang")
if lang == "" {
lang = "en"
}
if url, err := engines.Engines[engine].Tts(text, lang); err != nil {
return c.SendStatus(500)
@@ -188,6 +185,24 @@ func main() {
})
app.Post("/switchlanguages", func(c *fiber.Ctx) error {
if c.Cookies("from") != "" {
fromCookie := new(fiber.Cookie)
fromCookie.Name = "from"
fromCookie.Value = c.Cookies("to")
fromCookie.Expires = time.Now().Add(24 * time.Hour * 365)
toCookie := new(fiber.Cookie)
toCookie.Name = "to"
toCookie.Value = c.Cookies("from")
toCookie.Expires = time.Now().Add(24 * time.Hour * 365)
c.Cookie(fromCookie)
c.Cookie(toCookie)
}
return c.Redirect("/")
})
app.Static("/static", "./static")
app.Listen(":3000")

View File

@@ -57,19 +57,21 @@
<div class="item-wrapper">
<textarea autofocus class="item" id="input" name="text" dir="auto"
placeholder="Enter Text Here">{{ .OriginalText }}</textarea>
<div class="center">
<audio controls>
<source type="audio/mpeg" src="{{ .TtsFrom }}">
</audio>
</div>
{{if .TtsFrom}}
<audio controls>
<source type="audio/mpeg" src="{{ .TtsFrom }}">
</audio>
{{end}}
</div>
<div class="item-wrapper">
<textarea id="output" class="translation item" dir="auto" placeholder="Translation"
readonly>{{.TranslatedText}}</textarea>
{{if .TtsTo}}
<audio controls>
<source type="audio/mpeg" src="{{ .TtsTo }}">
</audio>
{{end}}
</div>
</div>