From 7f30ac37e918279f0030069d251b1bacc0266090 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Wed, 29 Jun 2022 20:13:05 +0200 Subject: [PATCH 1/3] map.html: display the intended text for the links instead of the URL For example display "Tokyo (en)" instead of https://en.wikipedia.org/wiki/Tokyo --- searx/templates/simple/result_templates/map.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/searx/templates/simple/result_templates/map.html b/searx/templates/simple/result_templates/map.html index e1223cbc0..3bdc378d6 100644 --- a/searx/templates/simple/result_templates/map.html +++ b/searx/templates/simple/result_templates/map.html @@ -35,7 +35,7 @@ {{ info.label }}{{ info.value|safe }} {%- endfor -%} {%- for link in result.links -%} - {{ link.label }}{{ link.url|safe }} + {{ link.label }}{{ link.url_label|safe }} {%- endfor -%} From 6716c6b0c310425872e3c182f8428f623760bec9 Mon Sep 17 00:00:00 2001 From: Alexandre Flament Date: Wed, 29 Jun 2022 20:14:04 +0200 Subject: [PATCH 2/3] openstreetmap engine: return the localized named. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For example: display "Tokyo" instead of "東京都" when the language is English. --- searx/engines/openstreetmap.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/searx/engines/openstreetmap.py b/searx/engines/openstreetmap.py index c619ce98e..ecef9b60b 100644 --- a/searx/engines/openstreetmap.py +++ b/searx/engines/openstreetmap.py @@ -29,6 +29,7 @@ about = { # engine dependent config categories = ['map'] paging = False +language_support = True # search-url base_url = 'https://nominatim.openstreetmap.org/' @@ -141,6 +142,9 @@ def request(query, params): params['url'] = base_url + search_string.format(query=urlencode({'q': query})) params['route'] = route_re.match(query) params['headers']['User-Agent'] = searx_useragent() + + accept_language = 'en' if params['language'] == 'all' else params['language'] + params['headers']['Accept-Language'] = accept_language return params @@ -223,7 +227,7 @@ def fetch_wikidata(nominatim_json, user_langage): wd_to_results.setdefault(wd_id, []).append(result) if wikidata_ids: - user_langage = 'en' if user_langage == 'all' else user_langage + user_langage = 'en' if user_langage == 'all' else user_langage.split('-')[0] wikidata_ids_str = " ".join(wikidata_ids) query = wikidata_image_sparql.replace('%WIKIDATA_IDS%', sparql_string_escape(wikidata_ids_str)).replace( '%LANGUAGE%', sparql_string_escape(user_langage) From 5831c15b49fb6ffeb19566deb37a0e470fd261e3 Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Sat, 2 Jul 2022 16:49:25 +0200 Subject: [PATCH 3/3] [fix] engines/openstreetmap.py typo: user_langage --> user_language Signed-off-by: Markus Heiser --- searx/engines/openstreetmap.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/searx/engines/openstreetmap.py b/searx/engines/openstreetmap.py index ecef9b60b..d44792077 100644 --- a/searx/engines/openstreetmap.py +++ b/searx/engines/openstreetmap.py @@ -206,7 +206,7 @@ def get_wikipedia_image(raw_value): return get_external_url('wikimedia_image', raw_value) -def fetch_wikidata(nominatim_json, user_langage): +def fetch_wikidata(nominatim_json, user_language): """Update nominatim_json using the result of an unique to wikidata For result in nominatim_json: @@ -227,10 +227,10 @@ def fetch_wikidata(nominatim_json, user_langage): wd_to_results.setdefault(wd_id, []).append(result) if wikidata_ids: - user_langage = 'en' if user_langage == 'all' else user_langage.split('-')[0] + user_language = 'en' if user_language == 'all' else user_language.split('-')[0] wikidata_ids_str = " ".join(wikidata_ids) query = wikidata_image_sparql.replace('%WIKIDATA_IDS%', sparql_string_escape(wikidata_ids_str)).replace( - '%LANGUAGE%', sparql_string_escape(user_langage) + '%LANGUAGE%', sparql_string_escape(user_language) ) wikidata_json = send_wikidata_query(query) for wd_result in wikidata_json.get('results', {}).get('bindings', {}): @@ -245,7 +245,7 @@ def fetch_wikidata(nominatim_json, user_langage): # overwrite wikipedia link wikipedia_name = wd_result.get('wikipediaName', {}).get('value') if wikipedia_name: - result['extratags']['wikipedia'] = user_langage + ':' + wikipedia_name + result['extratags']['wikipedia'] = user_language + ':' + wikipedia_name # get website if not already defined website = wd_result.get('website', {}).get('value') if (