make search language handling less strict

languages.py can change, so users may query on a language that is not
on the list anymore, even if it is still recognized by a few engines.

also made no and nb the same because they seem to return the same,
though most engines will only support one or the other.
This commit is contained in:
marc 2017-03-01 17:11:51 -06:00 committed by Adam Tauber
parent 805fb02ed1
commit fd65c12921
8 changed files with 17 additions and 15 deletions

View file

@ -24,7 +24,7 @@ from searx.engines import (
import string
import re
VALID_LANGUAGE_CODE = re.compile(r'^[a-z]{2,3}(\-[A-Z]{2})?$')
VALID_LANGUAGE_CODE = re.compile(r'^[a-z]{2,3}(-[a-zA-Z]{2})?$')
class RawTextQuery(object):
@ -68,7 +68,7 @@ class RawTextQuery(object):
# this force a language
if query_part[0] == ':':
lang = query_part[1:].lower()
lang = query_part[1:].lower().replace('_', '-')
# user may set a valid, yet not selectable language
if VALID_LANGUAGE_CODE.match(lang):
@ -86,7 +86,7 @@ class RawTextQuery(object):
or lang_id.startswith(lang)\
or lang == lang_name\
or lang == english_name\
or lang.replace('_', ' ') == country:
or lang.replace('-', ' ') == country:
parse_next = True
self.languages.append(lang_id)
# to ensure best match (first match is not necessarily the best one)