Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
searx-engine
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
searx-engine
Commits
90d23e7e
Unverified
Commit
90d23e7e
authored
Feb 23, 2020
by
Markus Heiser
Committed by
GitHub
Feb 23, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1860 from MarcAbonce/fix-default-locale
Fix default locale and language issues
parents
2ade2ce1
c0006cad
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
13 deletions
+19
-13
preferences.py
searx/preferences.py
+7
-2
settings.yml
searx/settings.yml
+1
-0
webapp.py
searx/webapp.py
+11
-11
No files found.
searx/preferences.py
View file @
90d23e7e
...
...
@@ -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
())
+
[
''
]),
...
...
searx/settings.yml
View file @
90d23e7e
...
...
@@ -5,6 +5,7 @@ general:
search
:
safe_search
:
0
# Filter results. 0: None, 1: Moderate, 2: Strict
autocomplete
:
"
"
# Existing autocomplete backends: "dbpedia", "duckduckgo", "google", "startpage", "wikipedia" - leave blank to turn it off by default
default_lang
:
"
"
# Default search language - leave blank to detect from browser information or use codes from 'languages.py'
ban_time_on_fail
:
5
# ban time in seconds after engine errors
max_ban_time_on_fail
:
120
# max ban time in seconds after engine errors
...
...
searx/webapp.py
View file @
90d23e7e
...
...
@@ -157,14 +157,16 @@ _category_names = (gettext('files'),
outgoing_proxies
=
settings
[
'outgoing'
]
.
get
(
'proxies'
)
or
None
def
_get_browser_language
(
request
,
lang_list
):
for
lang
in
request
.
headers
.
get
(
"Accept-Language"
,
"en"
)
.
split
(
","
):
locale
=
match_language
(
lang
,
lang_list
,
fallback
=
None
)
if
locale
is
not
None
:
return
locale
@
babel
.
localeselector
def
get_locale
():
locale
=
"en-US"
for
lang
in
request
.
headers
.
get
(
"Accept-Language"
,
locale
)
.
split
(
","
):
locale
=
match_language
(
lang
,
settings
[
'locales'
]
.
keys
(),
fallback
=
None
)
if
locale
is
not
None
:
break
locale
=
_get_browser_language
(
request
,
settings
[
'locales'
]
.
keys
())
logger
.
debug
(
"default locale from browser info is `
%
s`"
,
locale
)
...
...
@@ -372,8 +374,7 @@ def render(template_name, override_theme=None, **kwargs):
kwargs
[
'language_codes'
]
=
languages
if
'current_language'
not
in
kwargs
:
kwargs
[
'current_language'
]
=
match_language
(
request
.
preferences
.
get_value
(
'language'
),
LANGUAGE_CODES
,
fallback
=
locale
)
LANGUAGE_CODES
)
# override url_for function in templates
kwargs
[
'url_for'
]
=
url_for_theme
...
...
@@ -444,11 +445,10 @@ def pre_request():
request
.
errors
.
append
(
gettext
(
'Invalid settings'
))
# init search language and locale
locale
=
get_locale
()
if
not
preferences
.
get_value
(
"language"
):
preferences
.
parse_dict
({
"language"
:
locale
})
preferences
.
parse_dict
({
"language"
:
_get_browser_language
(
request
,
LANGUAGE_CODES
)
})
if
not
preferences
.
get_value
(
"locale"
):
preferences
.
parse_dict
({
"locale"
:
locale
})
preferences
.
parse_dict
({
"locale"
:
get_locale
()
})
# request.user_plugins
request
.
user_plugins
=
[]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment