Merge pull request #95 from idotj/main

Add html5 structure + improve UX/UI
This commit is contained in:
Piero Toffanin 2021-06-04 16:04:21 -04:00 committed by GitHub
commit 625aee0a84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 545 additions and 426 deletions

149
app/static/css/main.css Normal file
View file

@ -0,0 +1,149 @@
/* Custom styles for LibreTranslate page */
h3.header {
margin-bottom: 2.5rem;
}
.mb-0 {
margin-bottom: 0 !important;
}
.mt-0 {
margin-top: 0 !important;
}
.position-relative {
position: relative;
}
.language-select {
display: inline-flex;
align-items: center;
justify-content: flex-start;
}
.language-select select {
border: none;
width: auto;
cursor: pointer;
font-weight: 600;
text-decoration: underline;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
text-indent: 1px;
text-overflow: "";
padding: 0;
height: 2rem;
}
.btn-switch-language {
color: black;
margin-left: -1.5rem;
margin-right: 1rem;
}
.textarea-container {
margin-top: 0;
position: relative;
}
.btn-delete-text {
position: absolute;
right: 1.5rem;
top: 0.75rem;
border: 0;
background: none;
padding: 0;
cursor: pointer;
color: #888;
}
.btn-delete-text:focus,
.btn-copy-translated:focus {
background: none !important;
}
.characters-limit-container {
position: absolute;
right: 2rem;
bottom: 1rem;
color: #888;
pointer-events: none;
}
.btn-copy-translated {
position: absolute;
right: 2rem;
bottom: 1rem;
display: flex;
align-items: center;
color: #888;
font-size: 0.85rem;
background: none;
border: none;
cursor: pointer;
margin-right: -1.5rem;
}
.btn-copy-translated span {
padding-right: 0.5rem;
}
.btn-copy-translated .material-icons {
font-size: 1.35rem;
}
.progress {
background-color: #efefef;
}
.progress.translate {
position: absolute;
}
.progress .indeterminate {
background-color: steelblue;
}
.textarea-container textarea {
font-size: 1.25rem;
resize: none;
border: 1px solid #ccc;
background: #efefef;
padding: 1rem 2rem 1rem 1.5rem;
overflow-y: hidden;
}
.code {
font-size: 90%;
border-radius: 4px;
padding: 1rem 1.5rem;
border: 1px solid #9e9e9e;
background: #fbfbfb;
overflow: auto;
font-family: monospace;
min-height: 280px;
width: 100%;
overflow: auto;
}
.page-footer .footer-copyright {
justify-content: center;
}
@media (max-width: 991px) {
.language-select {
}
}
@media (max-width: 760px) {
.language-select select{
text-align: center;
margin: auto;
}
.language-select span {
display: none;
}
}

1
app/static/css/main.min.css vendored Normal file
View file

@ -0,0 +1 @@
h3.header{margin-bottom:2.5rem}.mb-0{margin-bottom:0!important}.mt-0{margin-top:0!important}.position-relative{position:relative}.language-select{display:inline-flex;align-items:center;justify-content:flex-start}.language-select select{border:none;width:auto;cursor:pointer;font-weight:600;text-decoration:underline;-webkit-appearance:none;-moz-appearance:none;appearance:none;text-indent:1px;text-overflow:"";padding:0;height:2rem}.btn-switch-language{color:#000;margin-left:-1.5rem;margin-right:1rem}.textarea-container{margin-top:0;position:relative}.btn-delete-text{position:absolute;right:1.5rem;top:.75rem;border:0;background:0 0;padding:0;cursor:pointer;color:#888}.btn-copy-translated:focus,.btn-delete-text:focus{background:0 0!important}.characters-limit-container{position:absolute;right:2rem;bottom:1rem;color:#888;pointer-events:none}.btn-copy-translated{position:absolute;right:2rem;bottom:1rem;display:flex;align-items:center;color:#888;font-size:.85rem;background:0 0;border:none;cursor:pointer;margin-right:-1.5rem}.btn-copy-translated span{padding-right:.5rem}.btn-copy-translated .material-icons{font-size:1.35rem}.progress{background-color:#efefef}.progress.translate{position:absolute}.progress .indeterminate{background-color:#4682b4}.textarea-container textarea{font-size:1.25rem;resize:none;border:1px solid #ccc;background:#efefef;padding:1rem 2rem 1rem 1.5rem;overflow-y:hidden}.code{font-size:90%;border-radius:4px;padding:1rem 1.5rem;border:1px solid #9e9e9e;background:#fbfbfb;overflow:auto;font-family:monospace;min-height:280px;width:100%;overflow:auto}.page-footer .footer-copyright{justify-content:center}@media (max-width:760px){.language-select select{text-align:center;margin:auto}.language-select span{display:none}}

View file

@ -14,34 +14,12 @@
<meta property="og:image" content="https://user-images.githubusercontent.com/1951843/102724116-32a6df00-42db-11eb-8cc0-129ab39cdfb5.png" /> <meta property="og:image" content="https://user-images.githubusercontent.com/1951843/102724116-32a6df00-42db-11eb-8cc0-129ab39cdfb5.png" />
<meta property="og:description" name="description" class="swiftype" content="Free and Open Source Machine Translation API. 100% self-hosted, no limits, no ties to proprietary services. Run your own API server in just a few minutes."/> <meta property="og:description" name="description" class="swiftype" content="Free and Open Source Machine Translation API. 100% self-hosted, no limits, no ties to proprietary services. Run your own API server in just a few minutes."/>
<script src="{{ url_for('static', filename='js/vue@2.js') }}"></script> <script src="{{ url_for('static', filename='js/vue@2.js') }}"></script>
<!-- Compiled and minified CSS --> <!-- Compiled and minified CSS -->
<link rel="stylesheet" href="{{ url_for('static', filename='css/materialize.min.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='css/materialize.min.css') }}">
<link href="{{ url_for('static', filename='css/material-icons.css') }}" rel="stylesheet"> <link rel="stylesheet" href="{{ url_for('static', filename='css/material-icons.css') }}" />
<link href="{{ url_for('static', filename='css/prism.min.css') }}" rel="stylesheet" /> <link rel="stylesheet" href="{{ url_for('static', filename='css/prism.min.css') }}" />
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.min.css') }}" />
<style type="text/css">
textarea.materialize-textarea{height: 120px;}
.code{
font-size: 90%;
border-radius: 4px;
padding: 4px;
border: 1px solid #9e9e9e;
background: #fbfbfb;
overflow: auto;
font-family: monospace;
min-height: 280px;
width: 100%;
overflow: auto;
}
.progress.translate{
position: absolute;
}
.card.horizontal .card-stacked{
overflow: auto;
}
</style>
{% if gaId %} {% if gaId %}
<!-- Global site tag (gtag.js) - Google Analytics --> <!-- Global site tag (gtag.js) - Google Analytics -->
@ -50,14 +28,18 @@
window.dataLayer = window.dataLayer || []; window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);} function gtag(){dataLayer.push(arguments);}
gtag('js', new Date()); gtag('js', new Date());
gtag('config', '{{ gaId }}'); gtag('config', '{{ gaId }}');
</script> </script>
{% endif %} {% endif %}
</head> </head>
<body> <body>
<header>
<nav class="blue lighten-1" role="navigation"> <nav class="blue lighten-1" role="navigation">
<div class="nav-wrapper container"><a id="logo-container" href="/" class="brand-logo"><i class="material-icons">translate</i> LibreTranslate</a> <div class="nav-wrapper container">
<a id="logo-container" href="/" class="brand-logo">
<i class="material-icons">translate</i> LibreTranslate
</a>
<ul class="right hide-on-med-and-down"> <ul class="right hide-on-med-and-down">
<li><a href="/docs">API Docs</a></li> <li><a href="/docs">API Docs</a></li>
<li><a href="https://github.com/uav4geo/LibreTranslate">GitHub</a></li> <li><a href="https://github.com/uav4geo/LibreTranslate">GitHub</a></li>
@ -76,7 +58,9 @@
<a href="#" data-target="nav-mobile" class="sidenav-trigger"><i class="material-icons">menu</i></a> <a href="#" data-target="nav-mobile" class="sidenav-trigger"><i class="material-icons">menu</i></a>
</div> </div>
</nav> </nav>
<div id="app"> </header>
<main id="app">
<div class="section no-pad-bot center" v-if="loading"> <div class="section no-pad-bot center" v-if="loading">
<div class="container"> <div class="container">
<div class="row"> <div class="row">
@ -94,6 +78,7 @@
</div> </div>
</div> </div>
</div> </div>
<div v-else-if="error"> <div v-else-if="error">
<div class="section no-pad-bot"> <div class="section no-pad-bot">
<div class="container"> <div class="container">
@ -114,27 +99,29 @@
</div> </div>
</div> </div>
</div> </div>
<div v-else> <div v-else>
<div class="section no-pad-bot"> <div class="section no-pad-bot">
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<h3 class="header center">Translation API</h3> <h3 class="header center">Translation API</h3>
<div class="card horizontal">
<div class="card-stacked">
<div class="card-content">
<form class="col s12"> <form class="col s12">
<div class="row"> <div class="row mb-0">
<div class="input-field col s5"> <div class="col s6 language-select">
<span>Translate from</span>
<select class="browser-default" v-model="sourceLang" ref="sourceLangDropdown" @change="handleInput"> <select class="browser-default" v-model="sourceLang" ref="sourceLangDropdown" @change="handleInput">
<template v-for="option in langs"> <template v-for="option in langs">
<option :value="option.code">[[ option.name ]]</option> <option :value="option.code">[[ option.name ]]</option>
</template> </template>
</select> </select>
</div> </div>
<div class="col s2 center">
<a href="javascript:void(0)" @click="swapLangs" class="waves-effect waves-teal btn-flat btn-large" style="margin-top: 8px;"><i class="material-icons">swap_horiz</i></a> <div class="col s6 language-select">
</div> <a href="javascript:void(0)" @click="swapLangs" class="btn-switch-language">
<div class="input-field col s5"> <i class="material-icons">swap_horiz</i>
</a>
<span>Translate into</span>
<select class="browser-default" v-model="targetLang" ref="targetLangDropdown" @change="handleInput"> <select class="browser-default" v-model="targetLang" ref="targetLangDropdown" @change="handleInput">
<template v-for="option in langs"> <template v-for="option in langs">
<option v-if="option.code !== 'auto'" :value="option.code">[[ option.name ]]</option> <option v-if="option.code !== 'auto'" :value="option.code">[[ option.name ]]</option>
@ -142,35 +129,34 @@
</select> </select>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="input-field col s6"> <div class="input-field textarea-container col s6">
<textarea id="textarea1" class="materialize-textarea" v-model="inputText" @input="handleInput" ref="inputTextarea"></textarea> <textarea id="textarea1" v-model="inputText" @input="handleInput" ref="inputTextarea"></textarea>
<label for="textarea1">Input Text</label> <button class="btn-delete-text" title="Delete text" @click="deleteText">
<div v-if="charactersLimit !== -1"> <i class="material-icons">close</i>
</button>
<div class="characters-limit-container" v-if="charactersLimit !== -1">
<label>[[ inputText.length ]] / [[ charactersLimit ]]</label> <label>[[ inputText.length ]] / [[ charactersLimit ]]</label>
</div> </div>
</div> </div>
<div class="input-field col s6">
<div> <div class="input-field textarea-container col s6">
<textarea id="textarea2" class="materialize-textarea" v-model="translatedText" ref="translatedTextarea"></textarea> <div class="position-relative">
<label for="textarea2"><div class="progress translate" v-if="loadingTranslation"> <textarea id="textarea2" v-model="translatedText" ref="translatedTextarea"></textarea>
<button class="btn-copy-translated" @click="copyText">
<span>[[ copyTextLabel ]]</span> <i class="material-icons">content_copy</i>
</button>
<label for="textarea2">
<div class="progress translate" v-if="loadingTranslation">
<div class="indeterminate"></div> <div class="indeterminate"></div>
</div></label>
</div> </div>
</label>
</div> </div>
</div> </div>
<div class="row">
<div class="col s6">
<button class="btn btn-small" style="display: inline-block;" title="Delete text" @click="deleteText"><i class="material-icons">delete</i></button>
</div>
<div class="col s6" style="text-align: right;">
<button class="btn btn-small" style="display: inline-block;" @click="copyText">[[ copyTextLabel ]]</button>
</div>
</div> </div>
</form> </form>
</div>
</div>
</div>
</div> </div>
</div> </div>
</div> </div>
@ -179,15 +165,12 @@
<div class="container"> <div class="container">
<div class="row center"> <div class="row center">
<div class="col s12 m12"> <div class="col s12 m12">
<div class="card horizontal">
<div class="card-stacked">
<div class="card-content">
<div class="row center"> <div class="row center">
<div class="col s12 m12 l6 left-align"> <div class="col s12 m12 l6 left-align">
<p>Request</p> <p>Request</p>
<p>
<pre class="code"><code class="language-javascript" v-html="$options.filters.highlight(requestCode)"> <pre class="code"><code class="language-javascript" v-html="$options.filters.highlight(requestCode)">
</code></pre></p> </code></pre>
</div> </div>
<div class="col s12 m12 l6 left-align"> <div class="col s12 m12 l6 left-align">
<p>Response</p> <p>Response</p>
@ -200,9 +183,6 @@
</div> </div>
</div> </div>
</div> </div>
</div>
</div>
</div>
{% if web_version %} {% if web_version %}
<div class="section no-pad-bot" id="index-banner"> <div class="section no-pad-bot" id="index-banner">
<div class="container"> <div class="container">
@ -218,7 +198,7 @@
</div> </div>
{% endif %} {% endif %}
</div> </div>
</div> </main>
<footer class="page-footer blue darken-3"> <footer class="page-footer blue darken-3">
<div class="container"> <div class="container">
@ -226,9 +206,6 @@
<div class="col l12 s12"> <div class="col l12 s12">
<h5 class="white-text">LibreTranslate</h5> <h5 class="white-text">LibreTranslate</h5>
<p class="grey-text text-lighten-4">Free and Open Source Machine Translation API</p> <p class="grey-text text-lighten-4">Free and Open Source Machine Translation API</p>
<p class="grey-text text-lighten-4">
Made with ❤ by <a class="grey-text text-lighten-3" href="https://uav4geo.com">UAV4GEO</a> and powered by <a class="grey-text text-lighten-3" href="https://github.com/argosopentech/argos-translate/">Argos Translate</a>
</p>
<p><a class="grey-text text-lighten-4" href="https://www.gnu.org/licenses/agpl-3.0.en.html">License: AGPLv3</a></p> <p><a class="grey-text text-lighten-4" href="https://www.gnu.org/licenses/agpl-3.0.en.html">License: AGPLv3</a></p>
<p><a class="grey-text text-lighten-4" href="/javascript-licenses" rel="jslicense">JavaScript license information</a></p> <p><a class="grey-text text-lighten-4" href="/javascript-licenses" rel="jslicense">JavaScript license information</a></p>
{% if web_version %} {% if web_version %}
@ -237,20 +214,12 @@
</p> </p>
{% endif %} {% endif %}
</div> </div>
<div class="col l4 offset-l2 s12">
<!-- <h5 class="white-text">Links</h5>
<ul>
<li><a class="grey-text text-lighten-3" href="#!">Link 1</a></li>
<li><a class="grey-text text-lighten-3" href="#!">Link 2</a></li>
<li><a class="grey-text text-lighten-3" href="#!">Link 3</a></li>
<li><a class="grey-text text-lighten-3" href="#!">Link 4</a></li>
</ul> -->
<div class="container">
</div>
</div>
</div> </div>
</div> </div>
<div class="footer-copyright center"> <div class="footer-copyright center">
<p>
Made with ❤ by <a class="grey-text text-lighten-3" href="https://uav4geo.com">UAV4GEO</a> and powered by <a class="grey-text text-lighten-3" href="https://github.com/argosopentech/argos-translate/">Argos Translate</a>
</p>
</div> </div>
</footer> </footer>
@ -270,8 +239,8 @@ window.Prism.manual = true;
var BaseUrl = window.location.protocol + "//" + window.location.host; var BaseUrl = window.location.protocol + "//" + window.location.host;
document.addEventListener('DOMContentLoaded', function(){ document.addEventListener('DOMContentLoaded', function(){
var elems = document.querySelectorAll('.sidenav'); var sidenavElems = document.querySelectorAll('.sidenav');
var instances = M.Sidenav.init(elems); var sidenavInstances = M.Sidenav.init(sidenavElems);
var app = new Vue({ var app = new Vue({
el: '#app', el: '#app',
@ -287,11 +256,12 @@ document.addEventListener('DOMContentLoaded', function(){
loadingTranslation: false, loadingTranslation: false,
inputText: "", inputText: "",
inputTextareaHeight: 250,
translatedText: "", translatedText: "",
output: "", output: "",
charactersLimit: -1, charactersLimit: -1,
copyTextLabel: "Copy Text" copyTextLabel: "Copy text"
}, },
mounted: function(){ mounted: function(){
var self = this; var self = this;
@ -350,19 +320,18 @@ document.addEventListener('DOMContentLoaded', function(){
M.FormSelect.init(this.$refs.sourceLangDropdown); M.FormSelect.init(this.$refs.sourceLangDropdown);
M.FormSelect.init(this.$refs.targetLangDropdown); M.FormSelect.init(this.$refs.targetLangDropdown);
if (this.inputText === ""){ if (this.inputText === ""){
this.$refs.inputTextarea.style.height = 150 + "px"; this.$refs.inputTextarea.style.height = this.inputTextareaHeight + "px";
this.$refs.translatedTextarea.style.height = 150 + "px"; this.$refs.translatedTextarea.style.height = this.inputTextareaHeight + "px";
}else{ }else{
this.$refs.inputTextarea.style.height = this.$refs.translatedTextarea.style.height = "1px"; this.$refs.inputTextarea.style.height = this.$refs.translatedTextarea.style.height = "1px";
this.$refs.inputTextarea.style.height = Math.max(150, this.$refs.inputTextarea.scrollHeight) + "px"; this.$refs.inputTextarea.style.height = Math.max(this.inputTextareaHeight, this.$refs.inputTextarea.scrollHeight + 32) + "px";
this.$refs.translatedTextarea.style.height = Math.max(150, this.$refs.translatedTextarea.scrollHeight) + "px"; this.$refs.translatedTextarea.style.height = Math.max(this.inputTextareaHeight, this.$refs.translatedTextarea.scrollHeight + 32) + "px";
} }
if (this.charactersLimit !== -1 && this.inputText.length >= this.charactersLimit){ if (this.charactersLimit !== -1 && this.inputText.length >= this.charactersLimit){
this.inputText = this.inputText.substring(0, this.charactersLimit); this.inputText = this.inputText.substring(0, this.charactersLimit);
} }
}, },
computed: { computed: {
requestCode: function(){ requestCode: function(){
@ -466,11 +435,11 @@ document.addEventListener('DOMContentLoaded', function(){
this.$refs.translatedTextarea.setSelectionRange(0, 9999999); /* For mobile devices */ this.$refs.translatedTextarea.setSelectionRange(0, 9999999); /* For mobile devices */
document.execCommand("copy"); document.execCommand("copy");
if (this.copyTextLabel === "Copy Text"){ if (this.copyTextLabel === "Copy text"){
this.copyTextLabel = "Copied!"; this.copyTextLabel = "Copied";
var self = this; var self = this;
setTimeout(function(){ setTimeout(function(){
self.copyTextLabel = "Copy Text"; self.copyTextLabel = "Copy text";
}, 1500); }, 1500);
} }
}, },