diff options
author | Marc Abonce Seguin <marc-abonce@mailbox.org> | 2020-02-23 02:03:42 -0700 |
---|---|---|
committer | Marc Abonce Seguin <marc-abonce@mailbox.org> | 2020-02-23 02:03:42 -0700 |
commit | c0006cadf70f0ee457d881bbd4ec40e30b0acd8f (patch) | |
tree | b8fa3a7bcc6c9bc1bfbc95c450a13575b6c05632 /searx/preferences.py | |
parent | 2ade2ce10abda68043f1dd11f9d976941296d2e8 (diff) | |
download | searxng-c0006cadf70f0ee457d881bbd4ec40e30b0acd8f.tar.gz searxng-c0006cadf70f0ee457d881bbd4ec40e30b0acd8f.zip |
fix default locale and language issues
Diffstat (limited to 'searx/preferences.py')
-rw-r--r-- | searx/preferences.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/searx/preferences.py b/searx/preferences.py index 37d4f13a8..6e31aa187 100644 --- a/searx/preferences.py +++ b/searx/preferences.py @@ -4,6 +4,7 @@ from sys import version from searx import settings, autocomplete from searx.languages import language_codes as languages +from searx.utils import match_language from searx.url_utils import parse_qs, urlencode if version[0] == '3': @@ -11,7 +12,7 @@ if version[0] == '3': COOKIE_MAX_AGE = 60 * 60 * 24 * 365 * 5 # 5 years -LANGUAGE_CODES = [l[0].split('-')[0] for l in languages] +LANGUAGE_CODES = [l[0] for l in languages] LANGUAGE_CODES.append('all') DISABLED = 0 ENABLED = 1 @@ -132,6 +133,10 @@ class SetSetting(Setting): class SearchLanguageSetting(EnumStringSetting): """Available choices may change, so user's value may not be in choices anymore""" + def _validate_selection(self, selection): + if not match_language(selection, self.choices, fallback=None) and selection != "": + raise ValidationException('Invalid language code: "{0}"'.format(selection)) + def parse(self, data): if data not in self.choices and data != self.value: # hack to give some backwards compatibility with old language cookies @@ -268,7 +273,7 @@ class Preferences(object): super(Preferences, self).__init__() self.key_value_settings = {'categories': MultipleChoiceSetting(['general'], choices=categories + ['none']), - 'language': SearchLanguageSetting(settings['ui']['default_locale'], + 'language': SearchLanguageSetting(settings['search']['default_lang'], choices=list(LANGUAGE_CODES) + ['']), 'locale': EnumStringSetting(settings['ui']['default_locale'], choices=list(settings['locales'].keys()) + ['']), |