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

@ -18,7 +18,7 @@
<!-- This hidden input is so that the engine gets sent in the request even though its not declared here --> <!-- This hidden input is so that the engine gets sent in the request even though its not declared here -->
<input name="engine" value="{{.Engine}}" type="hidden" /> <input name="engine" value="{{.Engine}}" type="hidden" />
<div class="wrap languages center-area" > <div class="wrap languages center-area">
<div class="language"> <div class="language">
<select name="from" aria-label="Source language" id="sourceLanguage"> <select name="from" aria-label="Source language" id="sourceLanguage">
{{range $key, $value := .SourceLanguages}} {{if $.From}} {{range $key, $value := .SourceLanguages}} {{if $.From}}
@ -46,7 +46,7 @@
<div class="language"> <div class="language">
<select name="to" aria-label="Target language" id="targetLanguage"> <select name="to" aria-label="Target language" id="targetLanguage">
{{range $key, $value := .TargetLanguages}} {{if $.To}} {{range $key, $value := .TargetLanguages}} {{if $.To}}
<option value="{{ .Id }}" {{if eq $.To .Id}}selected{{end}}> <option value="{{ .Id }}" {{if eq $.To .Id}}selected{{end}}>
{{ .Name }} {{ .Name }}
</option> </option>
@ -54,20 +54,22 @@
<option value="{{ .Id }}" {{if eq .Id $.defaultLangTarget}}selected{{end}}> <option value="{{ .Id }}" {{if eq .Id $.defaultLangTarget}}selected{{end}}>
{{ .Name }} {{ .Name }}
</option> </option>
{{end}} {{end}} {{end}} {{end}}
</select> </select>
</div> </div>
</div> </div>
<div class="center-area2 item-wrapper"> <div class="center-area2 item-wrapper">
Source Text: Source Text:
<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,28 +96,35 @@
<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;">
{{if .TranslationExists}} {{if .TranslationExists}}
<button class="wrap" type="button" onclick="copyToClipboard()"> <button class="wrap" type="button" onclick="copyToClipboard()">
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;"
{{if .TranslationExists}} href="/?engine={{.Engine}}&from={{.From}}&to={{.To}}&text={{.OriginalText}}">Copy translation link</a></p>
<button class="wrap" type="submit"> {{end}}
{{else}} {{if .TranslationExists}}
<button class="wrap" style="margin-left:auto; position:relative; left:-10%;margin-top: 1%;" type="submit"> <button class="wrap" type="submit">
{{end}} {{else}}
Translate! <button class="wrap" style="margin-left:auto; position:relative; left:-10%;margin-top: 1%;" type="submit">
</button> {{end}}
</div> Translate!
</button>
</div>
</form> </form>
<script> <script>
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0 // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0
@ -135,4 +149,4 @@
} }
</script> </script>
</main> </main>
{{ template "footer" .}} {{ template "footer" .}}