diff options
author | Markus Heiser <markus.heiser@darmarIT.de> | 2022-07-02 17:13:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-02 17:13:17 +0200 |
commit | 8e155b40bc86854b151e152ca4570515eb531e91 (patch) | |
tree | 7c1f7963a207183ecf64b125f651a3f71593685e /searx | |
parent | 69a6d994e1a471eb35a8adb7d75c753ca7dc3704 (diff) | |
parent | 5831c15b49fb6ffeb19566deb37a0e470fd261e3 (diff) | |
download | searxng-8e155b40bc86854b151e152ca4570515eb531e91.tar.gz searxng-8e155b40bc86854b151e152ca4570515eb531e91.zip |
Merge pull request #1381 from dalf/fix-upd-osm
openstreetmap: localized results.
Diffstat (limited to 'searx')
-rw-r--r-- | searx/engines/openstreetmap.py | 12 | ||||
-rw-r--r-- | searx/templates/simple/result_templates/map.html | 2 |
2 files changed, 9 insertions, 5 deletions
diff --git a/searx/engines/openstreetmap.py b/searx/engines/openstreetmap.py index c619ce98e..d44792077 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 @@ -202,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: @@ -223,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 + 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', {}): @@ -241,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 ( 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 @@ <tr><th scope="row">{{ info.label }}</th><td>{{ info.value|safe }}</td></tr> {%- endfor -%} {%- for link in result.links -%} - <tr><th scope="row">{{ link.label }}</th><td><a class="text-info cursor-pointer" href="{{ link.url }}">{{ link.url|safe }}</a></td></tr> + <tr><th scope="row">{{ link.label }}</th><td><a class="text-info cursor-pointer" href="{{ link.url }}">{{ link.url_label|safe }}</a></td></tr> {%- endfor -%} </table> |