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 app.language import languages
|
||||||
from flask_swagger import swagger
|
from flask_swagger import swagger
|
||||||
from flask_swagger_ui import get_swaggerui_blueprint
|
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 = argparse.ArgumentParser(description='LibreTranslate - Free and Open Source Translation API')
|
||||||
parser.add_argument('host', type=str,
|
parser.add_argument('--host', type=str,
|
||||||
help='Hostname', default="127.0.0.1")
|
help='Hostname (%(default)s)', default="127.0.0.1")
|
||||||
parser.add_argument('port', type=int,
|
parser.add_argument('--port', type=int,
|
||||||
help='Port', default=5000)
|
help='Port (%(default)s)', default=5000)
|
||||||
parser.add_argument('--char-limit', default=-1,
|
parser.add_argument('--char-limit', default=-1, metavar="<number of characters>",
|
||||||
help='Character limit')
|
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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
boot()
|
boot()
|
||||||
|
@ -29,7 +35,7 @@ def server_error(e):
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
return send_from_directory('static', 'index.html')
|
return render_template('index.html', gaId=args.google_analytics)
|
||||||
|
|
||||||
@app.route("/languages")
|
@app.route("/languages")
|
||||||
def langs():
|
def langs():
|
||||||
|
|
|
@ -2,3 +2,4 @@ argostranslate==1.0.3
|
||||||
Flask==1.1.2
|
Flask==1.1.2
|
||||||
flask-swagger==0.2.14
|
flask-swagger==0.2.14
|
||||||
flask-swagger-ui==3.36.0
|
flask-swagger-ui==3.36.0
|
||||||
|
Flask-Limiter==1.4
|
||||||
|
|
|
@ -4,6 +4,9 @@
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>LibreTranslate - Free and Open Source Translation API</title>
|
<title>LibreTranslate - Free and Open Source Translation API</title>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
|
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
|
||||||
<!-- Compiled and minified CSS -->
|
<!-- Compiled and minified CSS -->
|
||||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.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;
|
overflow: auto;
|
||||||
}
|
}
|
||||||
</style>
|
</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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<nav class="blue lighten-1" role="navigation">
|
<nav class="blue lighten-1" role="navigation">
|
||||||
|
@ -73,7 +88,7 @@
|
||||||
<div class="card horizontal">
|
<div class="card horizontal">
|
||||||
<div class="card-stacked">
|
<div class="card-stacked">
|
||||||
<div class="card-content">
|
<div class="card-content">
|
||||||
<i class="material-icons">warning</i><p> {{ error }}</p>
|
<i class="material-icons">warning</i><p> [[ error ]]</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-action">
|
<div class="card-action">
|
||||||
<a href="#" @click="dismissError">Dismiss</a>
|
<a href="#" @click="dismissError">Dismiss</a>
|
||||||
|
@ -98,7 +113,7 @@
|
||||||
<div class="input-field col s5">
|
<div class="input-field col s5">
|
||||||
<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>
|
||||||
|
@ -108,7 +123,7 @@
|
||||||
<div class="input-field col s5">
|
<div class="input-field col s5">
|
||||||
<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 :value="option.code">{{ option.name }}</option>
|
<option :value="option.code">[[ option.name ]]</option>
|
||||||
</template>
|
</template>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
@ -118,7 +133,7 @@
|
||||||
<textarea id="textarea1" class="materialize-textarea" v-model="inputText" @input="handleInput" ref="inputTextarea"></textarea>
|
<textarea id="textarea1" class="materialize-textarea" v-model="inputText" @input="handleInput" ref="inputTextarea"></textarea>
|
||||||
<label for="textarea1">Input Text</label>
|
<label for="textarea1">Input Text</label>
|
||||||
<div v-if="charactersLimit !== -1">
|
<div 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 class="input-field col s6">
|
||||||
|
@ -214,6 +229,7 @@ document.addEventListener('DOMContentLoaded', function(){
|
||||||
|
|
||||||
var app = new Vue({
|
var app = new Vue({
|
||||||
el: '#app',
|
el: '#app',
|
||||||
|
delimiters: ['[[',']]'],
|
||||||
data: {
|
data: {
|
||||||
BaseUrl: BaseUrl,
|
BaseUrl: BaseUrl,
|
||||||
loading: true,
|
loading: true,
|
||||||
|
@ -383,5 +399,8 @@ document.addEventListener('DOMContentLoaded', function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
{% if gaId %}
|
||||||
|
|
||||||
|
{% endif %}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Reference in a new issue