Locales¶
Initialize LOCALE_NAMES
, RTL_LOCALES
.
- searx.locales.ADDITIONAL_TRANSLATIONS = {'dv': 'ދިވެހި (Dhivehi)', 'oc': 'Occitan', 'pap': 'Papiamento', 'szl': 'Ślōnski (Silesian)'}¶
Additional languages SearXNG has translations for but not supported by python-babel (see
locales_initialize
).
- searx.locales.LOCALE_BEST_MATCH = {'dv': 'si', 'nl-BE': 'nl', 'oc': 'fr-FR', 'pap': 'pt-BR', 'szl': 'pl', 'zh-HK': 'zh-Hant-TW'}¶
Map a locale we do not have a translations for to a locale we have a translation for. By example: use Taiwan version of the translation for Hong Kong.
- searx.locales.LOCALE_NAMES¶
Mapping of locales and their description. Locales e.g. ‘fr’ or ‘pt-BR’ (see
locales_initialize
).
- searx.locales.RTL_LOCALES: Set[str] = {'ar', 'fa-IR', 'he'}¶
List of Right-To-Left locales e.g. ‘he’ or ‘fa-IR’ (see
locales_initialize
).
- searx.locales.get_engine_locale(searxng_locale, engine_locales, default=None)[source]¶
Return engine’s language (aka locale) string that best fits to argument
searxng_locale
.Argument
engine_locales
is a python dict that maps SearXNG locales to corresponding engine locales:<engine>: { # SearXNG string : engine-string 'ca-ES' : 'ca_ES', 'fr-BE' : 'fr_BE', 'fr-CA' : 'fr_CA', 'fr-CH' : 'fr_CH', 'fr' : 'fr_FR', ... 'pl-PL' : 'pl_PL', 'pt-PT' : 'pt_PT' }
Hint
The SearXNG locale string has to be known by babel!
If there is no direct 1:1 mapping, this functions tries to narrow down engine’s language (locale). If no value can be determined by these approximation attempts the
default
value is returned.Assumptions:
When user select a language the results should be optimized according to the selected language.
When user select a language and a territory the results should be optimized with first priority on terrirtory and second on language.
First approximation rule (by territory):
When the user selects a locale with terrirtory (and a language), the territory has priority over the language. If any of the offical languages in the terrirtory is supported by the engine (
engine_locales
) it will be used.Second approximation rule (by language):
If “First approximation rule” brings no result or the user selects only a language without a terrirtory. Check in which territories the language has an offical status and if one of these territories is supported by the engine.
- searx.locales.get_locale_descr(locale, locale_name)[source]¶
Get locale name e.g. ‘Français - fr’ or ‘Português (Brasil) - pt-BR’
- Parameters:
locale – instance of
Locale
locale_name – name e.g. ‘fr’ or ‘pt_BR’ (delimiter is underscore)
- searx.locales.get_translations()[source]¶
Monkey patch of
flask_babel.get_translations
- searx.locales.locales_initialize(directory=None)[source]¶
Initialize locales environment of the SearXNG session.
monkey patch
flask_babel.get_translations
byget_translations
init global names
LOCALE_NAMES
,RTL_LOCALES