mozhi/views/index.html

155 lines
5.9 KiB
HTML
Raw Normal View History

2023-06-25 00:10:57 +05:30
{{template "header" .}}
<main>
2023-09-10 17:27:22 +05:30
<!-- Need to do this custom selector thingy since <select> cant submit on click -->
<div class="custom-select">
{{range $key, $value := .enginesNames}} {{ if eq $.Engine $key }}Translate
with: <a href="#" class="selected-option">{{$value}}</a> {{end}} {{end}}
2023-09-10 17:27:22 +05:30
<ul class="options">
{{range $key, $value := .enginesNames}}
<a href="/?engine={{$key}}">
<li>{{$value}}</li>
</a>
2023-09-10 17:27:22 +05:30
{{end}}
</ul>
</div>
<br /><br />
<form action="/" method="POST" id="translation-form">
<!-- This hidden input is so that the engine gets sent in the request even though its not declared here -->
2023-09-10 17:27:22 +05:30
<input name="engine" value="{{.Engine}}" type="hidden" />
2023-11-29 20:58:26 +05:30
<div class="wrap languages center-area">
2023-09-10 17:27:22 +05:30
<div class="language">
2023-09-10 20:22:51 +05:30
<select name="from" aria-label="Source language" id="sourceLanguage">
{{range $key, $value := .SourceLanguages}} {{if $.From}}
2023-09-10 17:27:22 +05:30
<option value="{{ .Id }}" {{if eq $.From .Id}}selected{{end}}>
{{ .Name }}
</option>
{{else}}
<option value="{{ .Id }}" {{if eq .Id $.defaultLang}}selected{{end}}>
{{ .Name }}
</option>
{{end}} {{end}}
2023-09-10 17:27:22 +05:30
</select>
</div>
<div class="switch_languages">
2023-09-20 16:04:20 +05:30
<button id="switchbutton" aria-label="Switch languages" formaction="/switchlanguages?engine={{ .Engine }}"
type="submit">
<!-- https://icon-sets.iconify.design/ci/arrow-left-right/ -->
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="m16 13l3 3m0 0l-3 3m3-3H5m3-5L5 8m0 0l3-3M5 8h14" />
</svg>
2023-09-10 17:27:22 +05:30
</button>
</div>
<div class="language">
2023-09-10 20:22:51 +05:30
<select name="to" aria-label="Target language" id="targetLanguage">
2023-11-29 20:58:26 +05:30
{{range $key, $value := .TargetLanguages}} {{if $.To}}
2023-09-10 17:27:22 +05:30
<option value="{{ .Id }}" {{if eq $.To .Id}}selected{{end}}>
{{ .Name }}
</option>
{{else}}
<option value="{{ .Id }}" {{if eq .Id $.defaultLangTarget}}selected{{end}}>
{{ .Name }}
</option>
2023-11-29 20:58:26 +05:30
{{end}} {{end}}
2023-09-10 17:27:22 +05:30
</select>
</div>
</div>
2023-11-29 20:58:26 +05:30
<div class="center-area2 item-wrapper">
Source Text:
2023-09-20 16:04:20 +05:30
<textarea autofocus class="item" id="input" name="text" dir="auto" placeholder="Enter Text Here">
{{ .OriginalText }}</textarea>
{{if .Translation.SourceTransliteration}}
<br>Transliteration: {{newlinetobr .Translation.SourceTransliteration}}{{end}}
2023-09-20 16:04:20 +05:30
{{if .TtsFrom}}
2023-11-29 20:58:26 +05:30
<br>
2023-09-20 16:04:20 +05:30
<audio controls>
<source type="audio/mpeg" src="{{ .TtsFrom }}" />
</audio>
{{end}}
2023-11-29 20:58:26 +05:30
<br>
2023-09-20 16:04:20 +05:30
</div>
2023-09-10 17:27:22 +05:30
2023-09-20 16:04:20 +05:30
{{ if .TranslateAll }}
{{range $key, $value := .TranslateAll}}
2023-10-13 18:30:41 +05:30
<div class="item-wrapper center-area2">
2023-09-20 16:04:20 +05:30
Engine: {{.Engine}}
2023-10-13 12:33:57 +05:30
<textarea class="translation item" dir="auto" placeholder="Translation" id="output" readonly>
2023-09-20 16:04:20 +05:30
{{.OutputText}}</textarea>
{{if .AutoDetect}}
2023-11-29 20:58:26 +05:30
<br>Detected Language: {{.AutoDetect}}{{end}}
{{if .Translation.TargetTransliteration}}
<br>Transliteration: {{newlinetobr .Translation.TargetTransliteration}}{{end}}
2023-11-29 20:58:26 +05:30
{{if $.TtsTo}}
<br>
2023-09-20 16:04:20 +05:30
<audio controls>
<source type="audio/mpeg" src="{{ $.TtsTo }}" />
</audio>
{{end}}
2023-11-29 20:58:26 +05:30
<br>
2023-09-10 17:27:22 +05:30
</div>
2023-09-20 16:04:20 +05:30
{{end}}
{{ else }} {{if .TranslationExists}}
2023-10-13 18:30:41 +05:30
<div class="item-wrapper center-area2">
2023-10-13 12:33:57 +05:30
<textarea class="translation item" dir="auto" placeholder="Translation" id="output" readonly>
2023-09-20 16:04:20 +05:30
{{.Translation.OutputText}}</textarea>
{{if .Translation.AutoDetect}}
2023-11-29 20:58:26 +05:30
<br>Detected Language: {{.Translation.AutoDetect}}{{end}}
{{if .Translation.TargetTransliteration}}
<br>Transliteration: {{newlinetobr .Translation.TargetTransliteration}}{{end}}
2023-11-29 20:58:26 +05:30
{{if .TtsTo}}
<br>
2023-09-20 16:04:20 +05:30
<audio controls>
<source type="audio/mpeg" src="{{ .TtsTo }}" />
</audio>
{{end}}
2023-11-29 20:58:26 +05:30
<br>
2023-09-20 16:04:20 +05:30
{{end}}
{{end}}
<div style="display:flex; justify-content:space-around; align-items:center;">
2023-11-29 20:58:26 +05:30
{{if .TranslationExists}}
<button class="wrap" type="button" onclick="copyToClipboard()">
Copy the translation
</button>
{{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}}
<button class="wrap" type="submit">
{{else}}
<button class="wrap" style="margin-left:auto; position:relative; left:-10%;margin-top: 1%;" type="submit">
{{end}}
Translate!
</button>
</div>
2023-09-10 17:27:22 +05:30
</form>
<script>
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0
// this code submits the translation form when pressing Ctrl/Meta+Enter while focussed on the input text field
document
.getElementById("input")
.addEventListener("keydown", function (event) {
if (event.keyCode === 13 && (event.metaKey || event.ctrlKey)) {
document.getElementById("translation-form").submit();
}
});
2023-09-20 16:04:20 +05:30
// This code makes the select language menu searchable if js is enabled
2023-09-10 20:22:51 +05:30
var options = { searchable: true };
NiceSelect.bind(document.getElementById("targetLanguage"), options);
NiceSelect.bind(document.getElementById("sourceLanguage"), options);
2023-10-13 12:33:57 +05:30
// This function allows to copy the translated text to the clipboard
function copyToClipboard() {
var copyText = document.getElementById("output");
copyText.select();
copyText.setSelectionRange(0, 99999); // This is for mobile devices.
document.execCommand("copy");
}
</script>
2023-06-25 00:10:57 +05:30
</main>
{{ template "footer" .}}