diff options
| author | Alexandre Flament <alex@al-f.net> | 2022-11-06 11:29:28 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-06 11:29:28 +0100 |
| commit | 2dc5c0e1d61ea2d86f14af2cb6e1edfc4bfea20d (patch) | |
| tree | bcbe3f01688d75f030cf5b6fde3bef626ec50f78 /searx/locales.py | |
| parent | 4fe54636710288000e851d9c2d8879f40f6572f7 (diff) | |
| parent | d8dee2127772333964a19ddf3eca3aa1cb2b9bd4 (diff) | |
Merge pull request #1928 from searxng/translations_update
Update translations
Diffstat (limited to 'searx/locales.py')
| -rw-r--r-- | searx/locales.py | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/searx/locales.py b/searx/locales.py index 620132340..8547e7fa7 100644 --- a/searx/locales.py +++ b/searx/locales.py @@ -35,6 +35,7 @@ RTL_LOCALES: Set[str] = set() :py:obj:`locales_initialize`).""" ADDITIONAL_TRANSLATIONS = { + "dv": "ދިވެހި (Dhivehi)", "oc": "Occitan", "szl": "Ślōnski (Silesian)", "pap": "Papiamento", @@ -43,6 +44,7 @@ ADDITIONAL_TRANSLATIONS = { python-babel (see :py:obj:`locales_initialize`).""" LOCALE_BEST_MATCH = { + "dv": "si", "oc": 'fr-FR', "szl": "pl", "nl-BE": "nl", @@ -80,15 +82,11 @@ def localeselector(): def get_translations(): """Monkey patch of :py:obj:`flask_babel.get_translations`""" - if has_request_context() and flask.request.form.get('use-translation') == 'oc': - babel_ext = flask_babel.current_app.extensions['babel'] - return Translations.load(next(babel_ext.translation_directories), 'oc') - if has_request_context() and flask.request.form.get('use-translation') == 'szl': - babel_ext = flask_babel.current_app.extensions['babel'] - return Translations.load(next(babel_ext.translation_directories), 'szl') - if has_request_context() and flask.request.form.get('use-translation') == 'pap': - babel_ext = flask_babel.current_app.extensions['babel'] - return Translations.load(next(babel_ext.translation_directories), 'pap') + if has_request_context(): + use_translation = flask.request.form.get('use-translation') + if use_translation in ADDITIONAL_TRANSLATIONS: + babel_ext = flask_babel.current_app.extensions['babel'] + return Translations.load(next(babel_ext.translation_directories), use_translation) return _flask_babel_get_translations() @@ -136,13 +134,18 @@ def locales_initialize(directory=None): flask_babel.get_translations = get_translations for tag, descr in ADDITIONAL_TRANSLATIONS.items(): + locale = Locale.parse(LOCALE_BEST_MATCH[tag], sep='-') LOCALE_NAMES[tag] = descr + if locale.text_direction == 'rtl': + RTL_LOCALES.add(tag) for tag in LOCALE_BEST_MATCH: descr = LOCALE_NAMES.get(tag) if not descr: locale = Locale.parse(tag, sep='-') LOCALE_NAMES[tag] = get_locale_descr(locale, tag.replace('-', '_')) + if locale.text_direction == 'rtl': + RTL_LOCALES.add(tag) for dirname in sorted(os.listdir(directory)): # Based on https://flask-babel.tkte.ch/_modules/flask_babel.html#Babel.list_translations |