mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-11-25 09:21:04 +00:00
Match target translation to site's locale
This commit is contained in:
parent
5bf7a80932
commit
9fe372f58f
3 changed files with 34 additions and 18 deletions
|
@ -183,8 +183,8 @@ docker-compose -f docker-compose.cuda.yml up -d --build
|
||||||
| --ga-id | Enable Google Analytics on the API client page by providing an ID | `No tracking` | LT_GA_ID |
|
| --ga-id | Enable Google Analytics on the API client page by providing an ID | `No tracking` | LT_GA_ID |
|
||||||
| --debug | Enable debug environment | `False` | LT_DEBUG |
|
| --debug | Enable debug environment | `False` | LT_DEBUG |
|
||||||
| --ssl | Whether to enable SSL | `False` | LT_SSL |
|
| --ssl | Whether to enable SSL | `False` | LT_SSL |
|
||||||
| --frontend-language-source | Set frontend default language - source | `en` | LT_FRONTEND_LANGUAGE_SOURCE |
|
| --frontend-language-source | Set frontend default language - source | `auto` | LT_FRONTEND_LANGUAGE_SOURCE |
|
||||||
| --frontend-language-target | Set frontend default language - target | `es` | LT_FRONTEND_LANGUAGE_TARGET |
|
| --frontend-language-target | Set frontend default language - target | `locale` (match site's locale) | LT_FRONTEND_LANGUAGE_TARGET |
|
||||||
| --frontend-timeout | Set frontend translation timeout | `500` | LT_FRONTEND_TIMEOUT |
|
| --frontend-timeout | Set frontend translation timeout | `500` | LT_FRONTEND_TIMEOUT |
|
||||||
| --api-keys | Enable API keys database for per-user rate limits lookup | `Don't use API keys` | LT_API_KEYS |
|
| --api-keys | Enable API keys database for per-user rate limits lookup | `Don't use API keys` | LT_API_KEYS |
|
||||||
| --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-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 |
|
||||||
|
|
|
@ -132,10 +132,33 @@ def create_app(args):
|
||||||
iter([l for l in languages if l.code == args.frontend_language_source]),
|
iter([l for l in languages if l.code == args.frontend_language_source]),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
if frontend_argos_language_source is None:
|
||||||
|
frontend_argos_language_source = languages[0]
|
||||||
|
|
||||||
frontend_argos_language_target = next(
|
|
||||||
iter([l for l in languages if l.code == args.frontend_language_target]), None
|
if len(languages) >= 2:
|
||||||
)
|
language_target_fallback = languages[1]
|
||||||
|
else:
|
||||||
|
language_target_fallback = languages[0]
|
||||||
|
|
||||||
|
if args.frontend_language_target == "locale":
|
||||||
|
def resolve_language_locale():
|
||||||
|
loc = get_locale()
|
||||||
|
language_target = next(
|
||||||
|
iter([l for l in languages if l.code == loc]), None
|
||||||
|
)
|
||||||
|
if language_target is None:
|
||||||
|
language_target = language_target_fallback
|
||||||
|
return language_target
|
||||||
|
|
||||||
|
frontend_argos_language_target = resolve_language_locale
|
||||||
|
else:
|
||||||
|
language_target = next(
|
||||||
|
iter([l for l in languages if l.code == args.frontend_language_target]), None
|
||||||
|
)
|
||||||
|
if language_target is None:
|
||||||
|
language_target = language_target_fallback
|
||||||
|
frontend_argos_language_target = lambda: language_target
|
||||||
|
|
||||||
frontend_argos_supported_files_format = []
|
frontend_argos_supported_files_format = []
|
||||||
|
|
||||||
|
@ -143,15 +166,6 @@ def create_app(args):
|
||||||
for ff in file_format.supported_file_extensions:
|
for ff in file_format.supported_file_extensions:
|
||||||
frontend_argos_supported_files_format.append(ff)
|
frontend_argos_supported_files_format.append(ff)
|
||||||
|
|
||||||
# Raise AttributeError to prevent app startup if user input is not valid.
|
|
||||||
if frontend_argos_language_source is None:
|
|
||||||
frontend_argos_language_source = languages[0]
|
|
||||||
if frontend_argos_language_target is None:
|
|
||||||
if len(languages) >= 2:
|
|
||||||
frontend_argos_language_target = languages[1]
|
|
||||||
else:
|
|
||||||
frontend_argos_language_target = languages[0]
|
|
||||||
|
|
||||||
api_keys_db = None
|
api_keys_db = None
|
||||||
|
|
||||||
if args.req_limit > 0 or args.api_keys or args.daily_req_limit > 0:
|
if args.req_limit > 0 or args.api_keys or args.daily_req_limit > 0:
|
||||||
|
@ -896,6 +910,8 @@ def create_app(args):
|
||||||
type: string
|
type: string
|
||||||
description: Human-readable language name (in English)
|
description: Human-readable language name (in English)
|
||||||
"""
|
"""
|
||||||
|
target_lang = frontend_argos_language_target()
|
||||||
|
|
||||||
return jsonify(
|
return jsonify(
|
||||||
{
|
{
|
||||||
"charLimit": args.char_limit,
|
"charLimit": args.char_limit,
|
||||||
|
@ -911,8 +927,8 @@ def create_app(args):
|
||||||
"name": _lazy(frontend_argos_language_source.name),
|
"name": _lazy(frontend_argos_language_source.name),
|
||||||
},
|
},
|
||||||
"target": {
|
"target": {
|
||||||
"code": frontend_argos_language_target.code,
|
"code": target_lang.code,
|
||||||
"name": _lazy(frontend_argos_language_target.name),
|
"name": _lazy(target_lang.name),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,12 +93,12 @@ _default_options_objects = [
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': 'FRONTEND_LANGUAGE_SOURCE',
|
'name': 'FRONTEND_LANGUAGE_SOURCE',
|
||||||
'default_value': 'en',
|
'default_value': 'auto',
|
||||||
'value_type': 'str'
|
'value_type': 'str'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': 'FRONTEND_LANGUAGE_TARGET',
|
'name': 'FRONTEND_LANGUAGE_TARGET',
|
||||||
'default_value': 'es',
|
'default_value': 'locale',
|
||||||
'value_type': 'str'
|
'value_type': 'str'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue