diff --git a/searx/static/themes/oscar/js/searx.js b/searx/static/themes/oscar/js/searx.js index 159344b28..163009481 100644 --- a/searx/static/themes/oscar/js/searx.js +++ b/searx/static/themes/oscar/js/searx.js @@ -25,7 +25,8 @@ window.searx = (function(d) { return { autocompleter: script.getAttribute('data-autocompleter') === 'true', - method: script.getAttribute('data-method') + method: script.getAttribute('data-method'), + translations: JSON.parse(script.getAttribute('data-translations')) }; })(document); ;/** @@ -302,7 +303,7 @@ $(document).ready(function(){ } }) .fail(function() { - $(result_table_loadicon).html($(result_table_loadicon).html() + "

"+could_not_load+"

"); + $(result_table_loadicon).html($(result_table_loadicon).html() + "

"+searx.translations.could_not_load+"

"); }); } } diff --git a/searx/static/themes/oscar/js/searx.min.js b/searx/static/themes/oscar/js/searx.min.js index 71d67ae7f..0021f599c 100644 Binary files a/searx/static/themes/oscar/js/searx.min.js and b/searx/static/themes/oscar/js/searx.min.js differ diff --git a/searx/static/themes/oscar/js/searx.min.js.map b/searx/static/themes/oscar/js/searx.min.js.map index 11b3a9102..13e949a74 100644 Binary files a/searx/static/themes/oscar/js/searx.min.js.map and b/searx/static/themes/oscar/js/searx.min.js.map differ diff --git a/searx/static/themes/oscar/src/js/01_init.js b/searx/static/themes/oscar/src/js/01_init.js index 690365c7f..dd8de4ddb 100644 --- a/searx/static/themes/oscar/src/js/01_init.js +++ b/searx/static/themes/oscar/src/js/01_init.js @@ -25,6 +25,7 @@ window.searx = (function(d) { return { autocompleter: script.getAttribute('data-autocompleter') === 'true', - method: script.getAttribute('data-method') + method: script.getAttribute('data-method'), + translations: JSON.parse(script.getAttribute('data-translations')) }; })(document); diff --git a/searx/static/themes/oscar/src/js/leaflet_map.js b/searx/static/themes/oscar/src/js/leaflet_map.js index d1e102ff6..83364b0c3 100644 --- a/searx/static/themes/oscar/src/js/leaflet_map.js +++ b/searx/static/themes/oscar/src/js/leaflet_map.js @@ -90,7 +90,7 @@ $(document).ready(function(){ } }) .fail(function() { - $(result_table_loadicon).html($(result_table_loadicon).html() + "

"+could_not_load+"

"); + $(result_table_loadicon).html($(result_table_loadicon).html() + "

"+searx.translations.could_not_load+"

"); }); } } diff --git a/searx/static/themes/simple/js/searx.head.js b/searx/static/themes/simple/js/searx.head.js index 3ac61c8ae..e6964400b 100644 --- a/searx/static/themes/simple/js/searx.head.js +++ b/searx/static/themes/simple/js/searx.head.js @@ -32,7 +32,7 @@ search_on_category_select: script.getAttribute('data-search-on-category-select') === 'true', infinite_scroll: script.getAttribute('data-infinite-scroll') === 'true', static_path: script.getAttribute('data-static-path'), - no_item_found: script.getAttribute('data-no-item-found') + translations: JSON.parse(script.getAttribute('data-translations')), } // update the css diff --git a/searx/static/themes/simple/js/searx.head.min.js b/searx/static/themes/simple/js/searx.head.min.js index 19de1e498..5c87d749b 100644 Binary files a/searx/static/themes/simple/js/searx.head.min.js and b/searx/static/themes/simple/js/searx.head.min.js differ diff --git a/searx/static/themes/simple/js/searx.head.min.js.map b/searx/static/themes/simple/js/searx.head.min.js.map index d19ad5a44..a233d297b 100644 Binary files a/searx/static/themes/simple/js/searx.head.min.js.map and b/searx/static/themes/simple/js/searx.head.min.js.map differ diff --git a/searx/static/themes/simple/js/searx.js b/searx/static/themes/simple/js/searx.js index 8fb2471b0..1abe81e4d 100644 --- a/searx/static/themes/simple/js/searx.js +++ b/searx/static/themes/simple/js/searx.js @@ -1529,7 +1529,7 @@ module.exports = AutoComplete; if (searx.autocompleter) { searx.autocomplete = AutoComplete.call(w, { Url: "./autocompleter", - EmptyMessage: searx.no_item_found, + EmptyMessage: searx.translations.no_item_found, HttpMethod: searx.method, HttpHeaders: { "Content-type": "application/x-www-form-urlencoded", diff --git a/searx/static/themes/simple/js/searx.min.js b/searx/static/themes/simple/js/searx.min.js index 731e9ca7c..3b2b9d762 100644 Binary files a/searx/static/themes/simple/js/searx.min.js and b/searx/static/themes/simple/js/searx.min.js differ diff --git a/searx/static/themes/simple/js/searx.min.js.map b/searx/static/themes/simple/js/searx.min.js.map index fafc9644b..efce15142 100644 Binary files a/searx/static/themes/simple/js/searx.min.js.map and b/searx/static/themes/simple/js/searx.min.js.map differ diff --git a/searx/static/themes/simple/js/searx_head/00_init.js b/searx/static/themes/simple/js/searx_head/00_init.js index 3ac61c8ae..e6964400b 100644 --- a/searx/static/themes/simple/js/searx_head/00_init.js +++ b/searx/static/themes/simple/js/searx_head/00_init.js @@ -32,7 +32,7 @@ search_on_category_select: script.getAttribute('data-search-on-category-select') === 'true', infinite_scroll: script.getAttribute('data-infinite-scroll') === 'true', static_path: script.getAttribute('data-static-path'), - no_item_found: script.getAttribute('data-no-item-found') + translations: JSON.parse(script.getAttribute('data-translations')), } // update the css diff --git a/searx/static/themes/simple/js/searx_src/searx_search.js b/searx/static/themes/simple/js/searx_src/searx_search.js index 7b652fa92..0e498717c 100644 --- a/searx/static/themes/simple/js/searx_src/searx_search.js +++ b/searx/static/themes/simple/js/searx_src/searx_search.js @@ -73,7 +73,7 @@ if (searx.autocompleter) { searx.autocomplete = AutoComplete.call(w, { Url: "./autocompleter", - EmptyMessage: searx.no_item_found, + EmptyMessage: searx.translations.no_item_found, HttpMethod: searx.method, HttpHeaders: { "Content-type": "application/x-www-form-urlencoded", diff --git a/searx/templates/__common__/translations.js.tpl b/searx/templates/__common__/translations.js.tpl deleted file mode 100644 index 8453aba69..000000000 --- a/searx/templates/__common__/translations.js.tpl +++ /dev/null @@ -1 +0,0 @@ -var could_not_load = '{{ _('could not load data') }}!'; diff --git a/searx/templates/oscar/base.html b/searx/templates/oscar/base.html index f8345d9a7..b5c6ed258 100644 --- a/searx/templates/oscar/base.html +++ b/searx/templates/oscar/base.html @@ -9,7 +9,6 @@ {% block meta %}{% endblock %} - {% block title %}{% endblock %}{{ instance_name }} {% if preferences.get_value('oscar-style') -%} @@ -99,7 +98,8 @@ + data-autocompleter="{% if autocomplete %}true{% else %}false{% endif %}" + data-translations="{{ translations }}"> {% for script in scripts %} {{""}} {% endfor %} diff --git a/searx/templates/simple/base.html b/searx/templates/simple/base.html index a7255e672..17c9785e7 100644 --- a/searx/templates/simple/base.html +++ b/searx/templates/simple/base.html @@ -12,7 +12,6 @@ {% block title %}{% endblock %}{{ instance_name }} {% block meta %}{% endblock %} - {% if rtl %} {% else %} @@ -26,7 +25,7 @@ data-search-on-category-select="{{ 'true' if 'plugins/js/search_on_category_select.js' in scripts else 'false'}}" data-infinite-scroll="{{ 'true' if 'plugins/js/infinite_scroll.js' in scripts else 'false' }}" data-static-path="{{ url_for('static', filename='themes/simple') }}/" - data-no-item-found="{{ _('No item found') }}"> + data-translations="{{ translations }}"> {% block head %} diff --git a/searx/webapp.py b/searx/webapp.py index 062077292..6f0297a99 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -362,6 +362,15 @@ def image_proxify(url): urlencode(dict(url=url.encode(), h=h))) +def get_translations(): + return { + # when overpass AJAX request fails (on a map result) + 'could_not_load': gettext('could not load data'), + # when there is autocompletion + 'no_item_found': gettext('No item found') + } + + def render(template_name, override_theme=None, **kwargs): disabled_engines = request.preferences.engines.get_disabled() @@ -421,6 +430,8 @@ def render(template_name, override_theme=None, **kwargs): kwargs['brand'] = brand + kwargs['translations'] = json.dumps(get_translations(), separators=(',', ':')) + kwargs['scripts'] = set() kwargs['endpoint'] = 'results' if 'q' in kwargs else request.endpoint for plugin in request.user_plugins: @@ -1084,14 +1095,6 @@ def config(): }) -@app.route('/translations.js') -def js_translations(): - return render( - 'translations.js.tpl', - override_theme='__common__', - ), {'Content-Type': 'text/javascript; charset=UTF-8'} - - @app.errorhandler(404) def page_not_found(e): return render('404.html'), 404