diff --git a/README.md b/README.md index 8ca1ef7018ca4af6ed96a9ae30abfc8be39271f4..bd891592e60b785b084438db36c2eb20df7120e6 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,6 @@ docker-compose up -d --build | --frontend-language-source | Set frontend default language - source | `en` | | --frontend-language-target | Set frontend default language - target | `es` | | --frontend-timeout | Set frontend translation timeout | `500` | -| --offline | Run user-interface entirely offline (don't use internet CDNs) | `false` | | --api-keys | Enable API keys database for per-user rate limits lookup | `Don't use API keys` | | --load-only | Set available languages | `all from argostranslate` | diff --git a/app/app.py b/app/app.py index 96a1c140f2f5d11333d3269bcc9c8756679517d7..2b0466ea98d1bd79fb3611204af72595f4271ef5 100644 --- a/app/app.py +++ b/app/app.py @@ -47,9 +47,8 @@ def get_routes_limits(default_req_limit, api_keys_db): return [limits] def create_app(args): - if not args.offline: - from app.init import boot - boot(args.load_only) + from app.init import boot + boot(args.load_only) from app.language import languages app = Flask(__name__) @@ -100,12 +99,12 @@ def create_app(args): @app.route("/") @limiter.exempt def index(): - return render_template('index.html', gaId=args.ga_id, frontendTimeout=args.frontend_timeout, offline=args.offline, api_keys=args.api_keys, web_version=os.environ.get('LT_WEB') is not None) + return render_template('index.html', gaId=args.ga_id, frontendTimeout=args.frontend_timeout, api_keys=args.api_keys, web_version=os.environ.get('LT_WEB') is not None) @app.route("/javascript-licenses", methods=['GET']) @limiter.exempt def javascript_licenses(): - return render_template('javascript-licenses.html', offline=args.offline) + return render_template('javascript-licenses.html') @app.route("/languages", methods=['GET', 'POST']) @limiter.exempt diff --git a/app/init.py b/app/init.py index 210c5fea42697d4ff080e5c0b22de9ad61c3b63e..b44c2b2fe34ce4146062e60015fa6d8c0c1b0dce 100644 --- a/app/init.py +++ b/app/init.py @@ -6,8 +6,11 @@ import app.language import polyglot def boot(load_only=None): - check_and_install_models(load_only_lang_codes=load_only) - check_and_install_transliteration() + try: + check_and_install_models(load_only_lang_codes=load_only) + check_and_install_transliteration() + except Exception as e: + print("Cannot update models (normal if you're offline): %s" % str(e)) def check_and_install_models(force=False, load_only_lang_codes=None): if len(package.get_installed_packages()) < 2 or force: diff --git a/app/main.py b/app/main.py index af60e0f9e7df379959e0f88de9f013c33b855756..21aadcda7ed753fb0d02339ef44b3c128a90e014 100644 --- a/app/main.py +++ b/app/main.py @@ -26,8 +26,6 @@ def main(): help='Set frontend default language - target (%(default)s)') parser.add_argument('--frontend-timeout', type=int, default=500, metavar="<milliseconds>", help='Set frontend translation timeout (%(default)s)') - parser.add_argument('--offline', default=False, action="store_true", - help="Use offline") parser.add_argument('--api-keys', default=False, action="store_true", help="Enable API keys database for per-user rate limits lookup") parser.add_argument('--load-only', type=operator.methodcaller('split', ','), diff --git a/app/templates/index.html b/app/templates/index.html index 163e8f8d76dfbdb20c42bbb0bff818b293e3e4ff..5d7f0d246dbb39970daf18352cd8060cd9b11c88 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -15,11 +15,11 @@ <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="{% if offline %}{{ url_for('static', filename='js/vue@2.js') }}{% else %}https://cdn.jsdelivr.net/npm/vue@2{% endif %}"></script> + <script src="{{ url_for('static', filename='js/vue@2.js') }}"></script> <!-- Compiled and minified CSS --> - <link rel="stylesheet" href="{% if offline %}{{ url_for('static', filename='css/materialize.min.css') }}{% else %}https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css{% endif %}"> - <link href="{% if offline %}{{ url_for('static', filename='css/material-icons.css') }}{% else %}https://fonts.googleapis.com/icon?family=Material+Icons{% endif %}" rel="stylesheet"> - <link href="{% if offline %}{{ url_for('static', filename='css/prism.min.css') }}{% else %}https://cdnjs.cloudflare.com/ajax/libs/prism/1.22.0/themes/prism.min.css{% endif %}" rel="stylesheet" /> + <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 href="{{ url_for('static', filename='css/prism.min.css') }}" rel="stylesheet" /> <style type="text/css"> textarea.materialize-textarea{height: 120px;} @@ -254,7 +254,7 @@ </div> </footer> -<script src="{% if offline %}{{ url_for('static', filename='js/materialize.min.js') }}{% else %}https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js{% endif %}"></script> +<script src="{{ url_for('static', filename='js/materialize.min.js') }}"></script> <script> // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0 window.Prism = window.Prism || {}; @@ -262,7 +262,7 @@ window.Prism.manual = true; // @license-end </script> -<script src="{% if offline %}{{ url_for('static', filename='js/prism.min.js') }}{% else %}https://cdnjs.cloudflare.com/ajax/libs/prism/1.22.0/prism.min.js{% endif %}"></script> +<script src="{{ url_for('static', filename='js/prism.min.js') }}"></script> <script> // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0 diff --git a/app/templates/javascript-licenses.html b/app/templates/javascript-licenses.html index 37f1a88499b5c9c3d893a7cc03d03722a61ceae6..43f011eece200592c4fd115a782b925a9a87838b 100644 --- a/app/templates/javascript-licenses.html +++ b/app/templates/javascript-licenses.html @@ -6,15 +6,15 @@ <h3>Weblabels</h3> <table id="jslicense-labels1" border="1"> <tr> - <td><a href="{% if offline %}{{ url_for('static', filename='js/vue@2.js') }}{% else %}https://cdn.jsdelivr.net/npm/vue@2{% endif %}">Vue.js</a></td> + <td><a href="{{ url_for('static', filename='js/vue@2.js') }}">Vue.js</a></td> <td><a href="http://www.jclark.com/xml/copying.txt">Expat</a></td> </tr> <tr> - <td><a href="{% if offline %}{{ url_for('static', filename='js/prism.min.js') }}{% else %}https://cdnjs.cloudflare.com/ajax/libs/prism/1.22.0/prism.min.js{% endif %}">prism.min.js</a></td> + <td><a href="{{ url_for('static', filename='js/prism.min.js') }}">prism.min.js</a></td> <td><a href="http://www.jclark.com/xml/copying.txt">Expat</a></td> </tr> <tr> - <td><a href="{% if offline %}{{ url_for('static', filename='js/materialize.min.js') }}{% else %}https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js{% endif %}">materialize.min.js</a></td> + <td><a href="{{ url_for('static', filename='js/materialize.min.js') }}">materialize.min.js</a></td> <td><a href="http://www.jclark.com/xml/copying.txt">Expat</a></td> </tr> </table>