mirror of
https://github.com/searxng/searxng.git
synced 2024-11-27 13:21:04 +00:00
Merge pull request #2660 from dalf/upd-translations
[mod] replace /translations.js with an embedded JSON
This commit is contained in:
commit
30c950a2c7
17 changed files with 30 additions and 27 deletions
|
@ -25,7 +25,8 @@ window.searx = (function(d) {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
autocompleter: script.getAttribute('data-autocompleter') === 'true',
|
autocompleter: script.getAttribute('data-autocompleter') === 'true',
|
||||||
method: script.getAttribute('data-method')
|
method: script.getAttribute('data-method'),
|
||||||
|
translations: JSON.parse(script.getAttribute('data-translations'))
|
||||||
};
|
};
|
||||||
})(document);
|
})(document);
|
||||||
;/**
|
;/**
|
||||||
|
@ -302,7 +303,7 @@ $(document).ready(function(){
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.fail(function() {
|
.fail(function() {
|
||||||
$(result_table_loadicon).html($(result_table_loadicon).html() + "<p class=\"text-muted\">"+could_not_load+"</p>");
|
$(result_table_loadicon).html($(result_table_loadicon).html() + "<p class=\"text-muted\">"+searx.translations.could_not_load+"</p>");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
searx/static/themes/oscar/js/searx.min.js
vendored
2
searx/static/themes/oscar/js/searx.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -25,6 +25,7 @@ window.searx = (function(d) {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
autocompleter: script.getAttribute('data-autocompleter') === 'true',
|
autocompleter: script.getAttribute('data-autocompleter') === 'true',
|
||||||
method: script.getAttribute('data-method')
|
method: script.getAttribute('data-method'),
|
||||||
|
translations: JSON.parse(script.getAttribute('data-translations'))
|
||||||
};
|
};
|
||||||
})(document);
|
})(document);
|
||||||
|
|
|
@ -90,7 +90,7 @@ $(document).ready(function(){
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.fail(function() {
|
.fail(function() {
|
||||||
$(result_table_loadicon).html($(result_table_loadicon).html() + "<p class=\"text-muted\">"+could_not_load+"</p>");
|
$(result_table_loadicon).html($(result_table_loadicon).html() + "<p class=\"text-muted\">"+searx.translations.could_not_load+"</p>");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
search_on_category_select: script.getAttribute('data-search-on-category-select') === 'true',
|
search_on_category_select: script.getAttribute('data-search-on-category-select') === 'true',
|
||||||
infinite_scroll: script.getAttribute('data-infinite-scroll') === 'true',
|
infinite_scroll: script.getAttribute('data-infinite-scroll') === 'true',
|
||||||
static_path: script.getAttribute('data-static-path'),
|
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
|
// update the css
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/*! simple/searx.min.js | 16-03-2021 | */
|
/*! simple/searx.min.js | 16-03-2021 | */
|
||||||
|
|
||||||
(function(t,e){"use strict";var a=e.currentScript||function(){var t=e.getElementsByTagName("script");return t[t.length-1]}();t.searx={touch:"ontouchstart"in t||t.DocumentTouch&&document instanceof DocumentTouch||false,method:a.getAttribute("data-method"),autocompleter:a.getAttribute("data-autocompleter")==="true",search_on_category_select:a.getAttribute("data-search-on-category-select")==="true",infinite_scroll:a.getAttribute("data-infinite-scroll")==="true",static_path:a.getAttribute("data-static-path"),no_item_found:a.getAttribute("data-no-item-found")};e.getElementsByTagName("html")[0].className=t.searx.touch?"js touch":"js"})(window,document);
|
(function(t,e){"use strict";var a=e.currentScript||function(){var t=e.getElementsByTagName("script");return t[t.length-1]}();t.searx={touch:"ontouchstart"in t||t.DocumentTouch&&document instanceof DocumentTouch||false,method:a.getAttribute("data-method"),autocompleter:a.getAttribute("data-autocompleter")==="true",search_on_category_select:a.getAttribute("data-search-on-category-select")==="true",infinite_scroll:a.getAttribute("data-infinite-scroll")==="true",static_path:a.getAttribute("data-static-path"),translations:JSON.parse(a.getAttribute("data-translations"))};e.getElementsByTagName("html")[0].className=t.searx.touch?"js touch":"js"})(window,document);
|
||||||
//# sourceMappingURL=searx.head.min.js.map
|
//# sourceMappingURL=searx.head.min.js.map
|
|
@ -1 +1 @@
|
||||||
{"version":3,"sources":["searx.head.js"],"names":["w","d","script","currentScript","scripts","getElementsByTagName","length","searx","touch","DocumentTouch","document","method","getAttribute","autocompleter","search_on_category_select","infinite_scroll","static_path","no_item_found","className","window"],"mappings":";;CAiBA,SAAUA,EAAGC,GACT,aAGA,IAAIC,EAASD,EAAEE,eAAkB,WAC7B,IAAIC,EAAUH,EAAEI,qBAAqB,UACrC,OAAOD,EAAQA,EAAQE,OAAS,GAFH,GAMjCN,EAAEO,MAAQ,CACNC,MAAS,iBAAkBR,GAAMA,EAAES,eAAiBC,oBAAoBD,eAAkB,MAC1FE,OAAQT,EAAOU,aAAa,eAC5BC,cAAeX,EAAOU,aAAa,wBAA0B,OAC7DE,0BAA2BZ,EAAOU,aAAa,oCAAsC,OACrFG,gBAAiBb,EAAOU,aAAa,0BAA4B,OACjEI,YAAad,EAAOU,aAAa,oBACjCK,cAAef,EAAOU,aAAa,uBAIvCX,EAAEI,qBAAqB,QAAQ,GAAGa,UAAalB,EAAEO,MAAW,MAAE,WAAW,MArB7E,CAsBGY,OAAQT","file":"searx.head.min.js"}
|
{"version":3,"sources":["searx.head.js"],"names":["w","d","script","currentScript","scripts","getElementsByTagName","length","searx","touch","DocumentTouch","document","method","getAttribute","autocompleter","search_on_category_select","infinite_scroll","static_path","translations","JSON","parse","className","window"],"mappings":";;CAiBA,SAAUA,EAAGC,GACT,aAGA,IAAIC,EAASD,EAAEE,eAAkB,WAC7B,IAAIC,EAAUH,EAAEI,qBAAqB,UACrC,OAAOD,EAAQA,EAAQE,OAAS,GAFH,GAMjCN,EAAEO,MAAQ,CACNC,MAAS,iBAAkBR,GAAMA,EAAES,eAAiBC,oBAAoBD,eAAkB,MAC1FE,OAAQT,EAAOU,aAAa,eAC5BC,cAAeX,EAAOU,aAAa,wBAA0B,OAC7DE,0BAA2BZ,EAAOU,aAAa,oCAAsC,OACrFG,gBAAiBb,EAAOU,aAAa,0BAA4B,OACjEI,YAAad,EAAOU,aAAa,oBACjCK,aAAcC,KAAKC,MAAMjB,EAAOU,aAAa,uBAIjDX,EAAEI,qBAAqB,QAAQ,GAAGe,UAAapB,EAAEO,MAAW,MAAE,WAAW,MArB7E,CAsBGc,OAAQX","file":"searx.head.min.js"}
|
|
@ -1529,7 +1529,7 @@ module.exports = AutoComplete;
|
||||||
if (searx.autocompleter) {
|
if (searx.autocompleter) {
|
||||||
searx.autocomplete = AutoComplete.call(w, {
|
searx.autocomplete = AutoComplete.call(w, {
|
||||||
Url: "./autocompleter",
|
Url: "./autocompleter",
|
||||||
EmptyMessage: searx.no_item_found,
|
EmptyMessage: searx.translations.no_item_found,
|
||||||
HttpMethod: searx.method,
|
HttpMethod: searx.method,
|
||||||
HttpHeaders: {
|
HttpHeaders: {
|
||||||
"Content-type": "application/x-www-form-urlencoded",
|
"Content-type": "application/x-www-form-urlencoded",
|
||||||
|
|
2
searx/static/themes/simple/js/searx.min.js
vendored
2
searx/static/themes/simple/js/searx.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -32,7 +32,7 @@
|
||||||
search_on_category_select: script.getAttribute('data-search-on-category-select') === 'true',
|
search_on_category_select: script.getAttribute('data-search-on-category-select') === 'true',
|
||||||
infinite_scroll: script.getAttribute('data-infinite-scroll') === 'true',
|
infinite_scroll: script.getAttribute('data-infinite-scroll') === 'true',
|
||||||
static_path: script.getAttribute('data-static-path'),
|
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
|
// update the css
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
if (searx.autocompleter) {
|
if (searx.autocompleter) {
|
||||||
searx.autocomplete = AutoComplete.call(w, {
|
searx.autocomplete = AutoComplete.call(w, {
|
||||||
Url: "./autocompleter",
|
Url: "./autocompleter",
|
||||||
EmptyMessage: searx.no_item_found,
|
EmptyMessage: searx.translations.no_item_found,
|
||||||
HttpMethod: searx.method,
|
HttpMethod: searx.method,
|
||||||
HttpHeaders: {
|
HttpHeaders: {
|
||||||
"Content-type": "application/x-www-form-urlencoded",
|
"Content-type": "application/x-www-form-urlencoded",
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
var could_not_load = '{{ _('could not load data') }}!';
|
|
|
@ -9,7 +9,6 @@
|
||||||
<meta name="referrer" content="no-referrer">
|
<meta name="referrer" content="no-referrer">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1 , maximum-scale=2.0, user-scalable=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1 , maximum-scale=2.0, user-scalable=1" />
|
||||||
{% block meta %}{% endblock %}
|
{% block meta %}{% endblock %}
|
||||||
<script src="{{ url_for('js_translations') }}"></script>
|
|
||||||
<title>{% block title %}{% endblock %}{{ instance_name }}</title>
|
<title>{% block title %}{% endblock %}{{ instance_name }}</title>
|
||||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css') }}" type="text/css" />
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css') }}" type="text/css" />
|
||||||
{% if preferences.get_value('oscar-style') -%}
|
{% if preferences.get_value('oscar-style') -%}
|
||||||
|
@ -99,7 +98,8 @@
|
||||||
|
|
||||||
<script src="{{ url_for('static', filename='js/searx.min.js') }}"
|
<script src="{{ url_for('static', filename='js/searx.min.js') }}"
|
||||||
data-method="{{ method or 'POST' }}"
|
data-method="{{ method or 'POST' }}"
|
||||||
data-autocompleter="{% if autocomplete %}true{% else %}false{% endif %}"></script>
|
data-autocompleter="{% if autocomplete %}true{% else %}false{% endif %}"
|
||||||
|
data-translations="{{ translations }}"></script>
|
||||||
{% for script in scripts %}
|
{% for script in scripts %}
|
||||||
{{""}}<script src="{{ url_for('static', filename=script) }}"></script>
|
{{""}}<script src="{{ url_for('static', filename=script) }}"></script>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
|
||||||
<title>{% block title %}{% endblock %}{{ instance_name }}</title>
|
<title>{% block title %}{% endblock %}{{ instance_name }}</title>
|
||||||
{% block meta %}{% endblock %}
|
{% block meta %}{% endblock %}
|
||||||
<script src="{{ url_for('js_translations') }}"></script>
|
|
||||||
{% if rtl %}
|
{% if rtl %}
|
||||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/searx-rtl.min.css') }}" type="text/css" media="screen" />
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/searx-rtl.min.css') }}" type="text/css" media="screen" />
|
||||||
{% else %}
|
{% else %}
|
||||||
|
@ -26,7 +25,7 @@
|
||||||
data-search-on-category-select="{{ 'true' if 'plugins/js/search_on_category_select.js' in scripts else 'false'}}"
|
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-infinite-scroll="{{ 'true' if 'plugins/js/infinite_scroll.js' in scripts else 'false' }}"
|
||||||
data-static-path="{{ url_for('static', filename='themes/simple') }}/"
|
data-static-path="{{ url_for('static', filename='themes/simple') }}/"
|
||||||
data-no-item-found="{{ _('No item found') }}"></script>
|
data-translations="{{ translations }}"></script>
|
||||||
<!--<![endif]-->
|
<!--<![endif]-->
|
||||||
{% block head %}
|
{% block head %}
|
||||||
<link title="{{ instance_name }}" type="application/opensearchdescription+xml" rel="search" href="{{ opensearch_url }}"/>
|
<link title="{{ instance_name }}" type="application/opensearchdescription+xml" rel="search" href="{{ opensearch_url }}"/>
|
||||||
|
|
|
@ -362,6 +362,15 @@ def image_proxify(url):
|
||||||
urlencode(dict(url=url.encode(), h=h)))
|
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):
|
def render(template_name, override_theme=None, **kwargs):
|
||||||
disabled_engines = request.preferences.engines.get_disabled()
|
disabled_engines = request.preferences.engines.get_disabled()
|
||||||
|
|
||||||
|
@ -421,6 +430,8 @@ def render(template_name, override_theme=None, **kwargs):
|
||||||
|
|
||||||
kwargs['brand'] = brand
|
kwargs['brand'] = brand
|
||||||
|
|
||||||
|
kwargs['translations'] = json.dumps(get_translations(), separators=(',', ':'))
|
||||||
|
|
||||||
kwargs['scripts'] = set()
|
kwargs['scripts'] = set()
|
||||||
kwargs['endpoint'] = 'results' if 'q' in kwargs else request.endpoint
|
kwargs['endpoint'] = 'results' if 'q' in kwargs else request.endpoint
|
||||||
for plugin in request.user_plugins:
|
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)
|
@app.errorhandler(404)
|
||||||
def page_not_found(e):
|
def page_not_found(e):
|
||||||
return render('404.html'), 404
|
return render('404.html'), 404
|
||||||
|
|
Loading…
Reference in a new issue