add support for transliteration
All checks were successful
mozhi pipeline / Push Docker image to Codeberg docker registry (push) Successful in 29m0s
mozhi pipeline / Build and publish artifacts (push) Successful in 1h1m0s

This commit is contained in:
Arya 2023-11-29 20:58:26 +05:30
parent 709e7c5ab9
commit b8c7be7a96
Signed by: arya
GPG Key ID: 842D12BDA50DF120
4 changed files with 42 additions and 26 deletions

2
go.mod
View File

@ -7,7 +7,7 @@ replace github.com/OwO-Network/gdeeplx => github.com/gi-yt/gdeeplx v0.0.0-202308
//replace codeberg.org/aryak/libmozhi => /home/arya/projects/mozhi/libmozhi //replace codeberg.org/aryak/libmozhi => /home/arya/projects/mozhi/libmozhi
require ( require (
codeberg.org/aryak/libmozhi v0.0.0-20231129140947-7c9580a1ea2d codeberg.org/aryak/libmozhi v0.0.0-20231129152229-c0d8dfbccd68
github.com/gofiber/fiber/v2 v2.51.0 github.com/gofiber/fiber/v2 v2.51.0
github.com/gofiber/swagger v0.1.14 github.com/gofiber/swagger v0.1.14
github.com/gofiber/template v1.8.0 github.com/gofiber/template v1.8.0

2
go.sum
View File

@ -51,6 +51,8 @@ codeberg.org/aryak/libmozhi v0.0.0-20231129121457-7f83a4201d39 h1:XmDg0Fm0WL8xGD
codeberg.org/aryak/libmozhi v0.0.0-20231129121457-7f83a4201d39/go.mod h1:Ohfzqv/+t2t350TFNlHNBIXc42lOdv+3MkBtozYxMUY= codeberg.org/aryak/libmozhi v0.0.0-20231129121457-7f83a4201d39/go.mod h1:Ohfzqv/+t2t350TFNlHNBIXc42lOdv+3MkBtozYxMUY=
codeberg.org/aryak/libmozhi v0.0.0-20231129140947-7c9580a1ea2d h1:CxJsKo6EHksw6yBWX02uDnNntbszkybgPuN0PzGyBNA= codeberg.org/aryak/libmozhi v0.0.0-20231129140947-7c9580a1ea2d h1:CxJsKo6EHksw6yBWX02uDnNntbszkybgPuN0PzGyBNA=
codeberg.org/aryak/libmozhi v0.0.0-20231129140947-7c9580a1ea2d/go.mod h1:Ohfzqv/+t2t350TFNlHNBIXc42lOdv+3MkBtozYxMUY= codeberg.org/aryak/libmozhi v0.0.0-20231129140947-7c9580a1ea2d/go.mod h1:Ohfzqv/+t2t350TFNlHNBIXc42lOdv+3MkBtozYxMUY=
codeberg.org/aryak/libmozhi v0.0.0-20231129152229-c0d8dfbccd68 h1:Pwsv6oLj51GhlcrlBIPc91jliNeJx6sPdPKYnzhZqMg=
codeberg.org/aryak/libmozhi v0.0.0-20231129152229-c0d8dfbccd68/go.mod h1:Ohfzqv/+t2t350TFNlHNBIXc42lOdv+3MkBtozYxMUY=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=

View File

@ -2,6 +2,7 @@ package serve
import ( import (
"html/template" "html/template"
"strings"
"log" "log"
"net/http" "net/http"
"os" "os"
@ -37,9 +38,8 @@ func Serve(port string) {
engine := html.NewFileSystem(views, ".html") engine := html.NewFileSystem(views, ".html")
engine.AddFunc( engine.AddFunc(
// Add unescape function. This is needed to render HTML from Markdown. "newlinetobr", func(s string) template.HTML {
"unescape", func(s string) template.HTML { return template.HTML(strings.ReplaceAll(strings.ReplaceAll(s, "\n", "<br>"), "\r", ""))
return template.HTML(s)
}, },
) )

View File

@ -64,10 +64,12 @@
<textarea autofocus class="item" id="input" name="text" dir="auto" placeholder="Enter Text Here"> <textarea autofocus class="item" id="input" name="text" dir="auto" placeholder="Enter Text Here">
{{ .OriginalText }}</textarea> {{ .OriginalText }}</textarea>
{{if .TtsFrom}} {{if .TtsFrom}}
<br>
<audio controls> <audio controls>
<source type="audio/mpeg" src="{{ .TtsFrom }}" /> <source type="audio/mpeg" src="{{ .TtsFrom }}" />
</audio> </audio>
{{end}} {{end}}
<br>
</div> </div>
{{ if .TranslateAll }} {{ if .TranslateAll }}
@ -77,11 +79,16 @@
<textarea class="translation item" dir="auto" placeholder="Translation" id="output" readonly> <textarea class="translation item" dir="auto" placeholder="Translation" id="output" readonly>
{{.OutputText}}</textarea> {{.OutputText}}</textarea>
{{if .AutoDetect}} {{if .AutoDetect}}
Detected Language: {{.AutoDetect}}{{end}} {{if $.TtsTo}} <br>Detected Language: {{.AutoDetect}}{{end}}
{{if .Translation.Transliteration}}
<br>Transliteration: {{newlinetobr .Translation.Transliteration}}{{end}}
{{if $.TtsTo}}
<br>
<audio controls> <audio controls>
<source type="audio/mpeg" src="{{ $.TtsTo }}" /> <source type="audio/mpeg" src="{{ $.TtsTo }}" />
</audio> </audio>
{{end}} {{end}}
<br>
</div> </div>
{{end}} {{end}}
{{ else }} {{if .TranslationExists}} {{ else }} {{if .TranslationExists}}
@ -89,11 +96,16 @@
<textarea class="translation item" dir="auto" placeholder="Translation" id="output" readonly> <textarea class="translation item" dir="auto" placeholder="Translation" id="output" readonly>
{{.Translation.OutputText}}</textarea> {{.Translation.OutputText}}</textarea>
{{if .Translation.AutoDetect}} {{if .Translation.AutoDetect}}
Detected Language: {{.Translation.AutoDetect}}{{end}} {{if .TtsTo}} <br>Detected Language: {{.Translation.AutoDetect}}{{end}}
{{if .Translation.Transliteration}}
<br>Transliteration: {{newlinetobr .Translation.Transliteration}}{{end}}
{{if .TtsTo}}
<br>
<audio controls> <audio controls>
<source type="audio/mpeg" src="{{ .TtsTo }}" /> <source type="audio/mpeg" src="{{ .TtsTo }}" />
</audio> </audio>
{{end}} {{end}}
<br>
{{end}} {{end}}
{{end}} {{end}}
<div style="display:flex; justify-content:space-around; align-items:center;"> <div style="display:flex; justify-content:space-around; align-items:center;">
@ -102,7 +114,9 @@
Copy the translation Copy the translation
</button> </button>
{{end}} {{end}}
{{ if and .Engine .From .To .OriginalText }}<p><a class="button" style="color:#010000; text-decoration: none;" href="/?engine={{.Engine}}&from={{.From}}&to={{.To}}&text={{.OriginalText}}">Copy translation link</a></p>{{end}} {{ if and .Engine .From .To .OriginalText }}<p><a class="button" style="color:#010000; text-decoration: none;"
href="/?engine={{.Engine}}&from={{.From}}&to={{.To}}&text={{.OriginalText}}">Copy translation link</a></p>
{{end}}
{{if .TranslationExists}} {{if .TranslationExists}}
<button class="wrap" type="submit"> <button class="wrap" type="submit">
{{else}} {{else}}