mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-11-21 15:31:00 +00:00
Added GA
This commit is contained in:
parent
c5863fcc84
commit
7853ec0f0a
3 changed files with 37 additions and 11 deletions
20
main.py
20
main.py
|
@ -4,14 +4,20 @@ from flask import Flask, render_template, jsonify, request, abort, send_from_dir
|
|||
from app.language import languages
|
||||
from flask_swagger import swagger
|
||||
from flask_swagger_ui import get_swaggerui_blueprint
|
||||
from flask_limiter import Limiter
|
||||
|
||||
parser = argparse.ArgumentParser(description='LibreTranslate - Free and Open Source Translation API')
|
||||
parser.add_argument('host', type=str,
|
||||
help='Hostname', default="127.0.0.1")
|
||||
parser.add_argument('port', type=int,
|
||||
help='Port', default=5000)
|
||||
parser.add_argument('--char-limit', default=-1,
|
||||
help='Character limit')
|
||||
parser.add_argument('--host', type=str,
|
||||
help='Hostname (%(default)s)', default="127.0.0.1")
|
||||
parser.add_argument('--port', type=int,
|
||||
help='Port (%(default)s)', default=5000)
|
||||
parser.add_argument('--char-limit', default=-1, metavar="<number of characters>",
|
||||
help='Set character limit (%(default)s)')
|
||||
parser.add_argument('--req-limit', default=-1, metavar="<number>",
|
||||
help='Set maximum number of requests per hour per client (%(default)s)')
|
||||
parser.add_argument('--google-analytics', default=None, metavar="<GA ID>",
|
||||
help='Enable Google Analytics on the API client page by providing an ID (%(default)s)')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
boot()
|
||||
|
@ -29,7 +35,7 @@ def server_error(e):
|
|||
|
||||
@app.route("/")
|
||||
def index():
|
||||
return send_from_directory('static', 'index.html')
|
||||
return render_template('index.html', gaId=args.google_analytics)
|
||||
|
||||
@app.route("/languages")
|
||||
def langs():
|
||||
|
|
|
@ -2,3 +2,4 @@ argostranslate==1.0.3
|
|||
Flask==1.1.2
|
||||
flask-swagger==0.2.14
|
||||
flask-swagger-ui==3.36.0
|
||||
Flask-Limiter==1.4
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>LibreTranslate - Free and Open Source Translation API</title>
|
||||
|
||||
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
|
||||
<!-- Compiled and minified CSS -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
|
||||
|
@ -31,6 +34,18 @@
|
|||
overflow: auto;
|
||||
}
|
||||
</style>
|
||||
|
||||
{% if gaId %}
|
||||
<!-- Global site tag (gtag.js) - Google Analytics -->
|
||||
<script async src="https://www.googletagmanager.com/gtag/js?id={{ gaId }}"></script>
|
||||
<script>
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
|
||||
gtag('config', '{{ gaId }}');
|
||||
</script>
|
||||
{% endif %}
|
||||
</head>
|
||||
<body>
|
||||
<nav class="blue lighten-1" role="navigation">
|
||||
|
@ -73,7 +88,7 @@
|
|||
<div class="card horizontal">
|
||||
<div class="card-stacked">
|
||||
<div class="card-content">
|
||||
<i class="material-icons">warning</i><p> {{ error }}</p>
|
||||
<i class="material-icons">warning</i><p> [[ error ]]</p>
|
||||
</div>
|
||||
<div class="card-action">
|
||||
<a href="#" @click="dismissError">Dismiss</a>
|
||||
|
@ -98,7 +113,7 @@
|
|||
<div class="input-field col s5">
|
||||
<select class="browser-default" v-model="sourceLang" ref="sourceLangDropdown"@change="handleInput">
|
||||
<template v-for="option in langs">
|
||||
<option :value="option.code">{{ option.name }}</option>
|
||||
<option :value="option.code">[[ option.name ]]</option>
|
||||
</template>
|
||||
</select>
|
||||
</div>
|
||||
|
@ -108,7 +123,7 @@
|
|||
<div class="input-field col s5">
|
||||
<select class="browser-default" v-model="targetLang" ref="targetLangDropdown" @change="handleInput">
|
||||
<template v-for="option in langs">
|
||||
<option :value="option.code">{{ option.name }}</option>
|
||||
<option :value="option.code">[[ option.name ]]</option>
|
||||
</template>
|
||||
</select>
|
||||
</div>
|
||||
|
@ -118,7 +133,7 @@
|
|||
<textarea id="textarea1" class="materialize-textarea" v-model="inputText" @input="handleInput" ref="inputTextarea"></textarea>
|
||||
<label for="textarea1">Input Text</label>
|
||||
<div v-if="charactersLimit !== -1">
|
||||
<label>{{ inputText.length }} / {{ charactersLimit }}</label>
|
||||
<label>[[ inputText.length ]] / [[ charactersLimit ]]</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="input-field col s6">
|
||||
|
@ -214,6 +229,7 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||
|
||||
var app = new Vue({
|
||||
el: '#app',
|
||||
delimiters: ['[[',']]'],
|
||||
data: {
|
||||
BaseUrl: BaseUrl,
|
||||
loading: true,
|
||||
|
@ -383,5 +399,8 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||
});
|
||||
|
||||
</script>
|
||||
{% if gaId %}
|
||||
|
||||
{% endif %}
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue