@@ -4,6 +4,7 @@ from sys import version
5from searx import settings, autocomplete
5from searx import settings, autocomplete
6from searx.languages import language_codes as languages
6from searx.languages import language_codes as languages
7+from searx.utils import match_language
7from searx.url_utils import parse_qs, urlencode
8from searx.url_utils import parse_qs, urlencode
9if version[0] == '3':
10if version[0] == '3':
@@ -11,7 +12,7 @@ if version[0] == '3':
13COOKIE_MAX_AGE = 60 * 60 * 24 * 365 * 5 # 5 years
14COOKIE_MAX_AGE = 60 * 60 * 24 * 365 * 5 # 5 years
14−LANGUAGE_CODES = [l[0].split('-')[0] for l in languages]
15+LANGUAGE_CODES = [l[0] for l in languages]
15LANGUAGE_CODES.append('all')
16LANGUAGE_CODES.append('all')
16DISABLED = 0
17DISABLED = 0
17ENABLED = 1
18ENABLED = 1
@@ -132,6 +133,10 @@ class SetSetting(Setting):
132class SearchLanguageSetting(EnumStringSetting):
133class SearchLanguageSetting(EnumStringSetting):
133 """Available choices may change, so user's value may not be in choices anymore"""
134 """Available choices may change, so user's value may not be in choices anymore"""
136+ def _validate_selection(self, selection):
137+ if not match_language(selection, self.choices, fallback=None) and selection != "":
138+ raise ValidationException('Invalid language code: "{0}"'.format(selection))
135 def parse(self, data):
140 def parse(self, data):
136 if data not in self.choices and data != self.value:
141 if data not in self.choices and data != self.value:
137 # hack to give some backwards compatibility with old language cookies
142 # hack to give some backwards compatibility with old language cookies
@@ -268,7 +273,7 @@ class Preferences(object):
268 super(Preferences, self).__init__()
273 super(Preferences, self).__init__()
270 self.key_value_settings = {'categories': MultipleChoiceSetting(['general'], choices=categories + ['none']),
275 self.key_value_settings = {'categories': MultipleChoiceSetting(['general'], choices=categories + ['none']),
271− 'language': SearchLanguageSetting(settings['ui']['default_locale'],
276+ 'language': SearchLanguageSetting(settings['search']['default_lang'],
272 choices=list(LANGUAGE_CODES) + ['']),
277 choices=list(LANGUAGE_CODES) + ['']),
273 'locale': EnumStringSetting(settings['ui']['default_locale'],
278 'locale': EnumStringSetting(settings['ui']['default_locale'],
274 choices=list(settings['locales'].keys()) + ['']),
279 choices=list(settings['locales'].keys()) + ['']),