diff --git a/README.md b/README.md index bb05110..80286ae 100644 --- a/README.md +++ b/README.md @@ -204,6 +204,7 @@ Arguments passed to the process or set via environment variables are split into | --disable-web-ui | Disable web ui | `Web Ui enabled` | LT_DISABLE_WEB_UI | | --update-models | Update language models at startup | `Only on if no models found` | LT_UPDATE_MODELS | | --metrics | Enable the /metrics endpoint for exporting [Prometheus](https://prometheus.io/) usage metrics | `Disabled` | LT_METRICS | +| --hide-api | Hide the API request/response section in the web UI | `Disabled` | LT_HIDE_API | ### Configuration Parameters @@ -219,6 +220,7 @@ Arguments passed to the process or set via environment variables are split into | --ga-id | Enable Google Analytics on the API client page by providing an ID | `Empty (no tracking)` | LT_GA_ID | | --frontend-language-source | Set frontend default language - source | `auto` | LT_FRONTEND_LANGUAGE_SOURCE | | --frontend-language-target | Set frontend default language - target | `locale` (match site's locale) | LT_FRONTEND_LANGUAGE_TARGET | +| --frontend-language | Set frontend web interface language | `(empty)` (auto-detect) | LT_FRONTEND_LANGUAGE | | --frontend-timeout | Set frontend translation timeout | `500` | LT_FRONTEND_TIMEOUT | | --api-keys-db-path | Use a specific path inside the container for the local database. Can be absolute or relative | `db/api_keys.db` | LT_API_KEYS_DB_PATH | | --api-keys-remote | Use this remote endpoint to query for valid API keys instead of using the local database | `Empty (use local db instead)` | LT_API_KEYS_REMOTE | diff --git a/libretranslate/app.py b/libretranslate/app.py index d30663f..7d0a427 100644 --- a/libretranslate/app.py +++ b/libretranslate/app.py @@ -429,7 +429,7 @@ def create_app(args): if args.disable_web_ui: abort(404) - langcode = request.args.get('lang') + langcode = args.frontend_language if len(args.frontend_language) > 0 else request.args.get('lang') if langcode and langcode in get_available_locale_codes(not args.debug): session.update(preferred_lang=langcode) @@ -446,6 +446,7 @@ def create_app(args): current_locale=get_locale(), alternate_locales=get_alternate_locale_links(), under_attack=args.under_attack, + hide_api=args.hide_api, )) if args.require_api_key_secret: diff --git a/libretranslate/default_values.py b/libretranslate/default_values.py index 3d2e3a8..56c1600 100644 --- a/libretranslate/default_values.py +++ b/libretranslate/default_values.py @@ -116,6 +116,11 @@ _default_options_objects = [ 'default_value': 'locale', 'value_type': 'str' }, + { + 'name': 'FRONTEND_LANGUAGE', + 'default_value': '', + 'value_type': 'str' + }, { 'name': 'FRONTEND_TIMEOUT', 'default_value': 500, @@ -161,6 +166,11 @@ _default_options_objects = [ 'default_value': False, 'value_type': 'bool' }, + { + 'name': 'HIDE_API', + 'default_value': False, + 'value_type': 'bool' + }, { 'name': 'SHARED_STORAGE', 'default_value': 'memory://', diff --git a/libretranslate/main.py b/libretranslate/main.py index ea6eb3d..2daebba 100644 --- a/libretranslate/main.py +++ b/libretranslate/main.py @@ -104,6 +104,13 @@ def get_args(): metavar="", help="Set frontend default language - target (%(default)s)", ) + parser.add_argument( + "--frontend-language", + type=str, + default=DEFARGS['FRONTEND_LANGUAGE'], + metavar="", + help="Set frontend interface language (%(default)s)", + ) parser.add_argument( "--frontend-timeout", type=int, @@ -153,6 +160,12 @@ def get_args(): action="store_true", help="Require use of an API key for programmatic access to the API, unless the client also matches a fingerprint", ) + parser.add_argument( + "--hide-api", + default=DEFARGS['HIDE_API'], + action="store_true", + help="Hide the API request/response fields in the frontend", + ) parser.add_argument( "--under-attack", default=DEFARGS['UNDER_ATTACK'], diff --git a/libretranslate/templates/index.html b/libretranslate/templates/index.html index 46c71dd..9b62414 100644 --- a/libretranslate/templates/index.html +++ b/libretranslate/templates/index.html @@ -296,6 +296,7 @@ + {% if not hide_api %}
@@ -318,6 +319,7 @@
+ {% endif %} {% if web_version %}