Commit 74f37187 authored by Nicolas Wavrant's avatar Nicolas Wavrant

erp5_web_renderjs_ui: let gadget know the language in which the interface is rendered

parent 07fd9edc
......@@ -549,6 +549,9 @@
return route(this, 'translation_gadget', 'getTranslationList',
argument_list);
})
.allowPublicAcquisition("getSelectedLanguage", function getSelectedLanguage() {
return route(this, 'translation_gadget', 'getSelectedLanguage');
})
.allowPublicAcquisition("redirect", function redirect(param_list) {
return route(this, 'router', 'redirect', param_list);
......
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>978.22304.53878.1495</string> </value>
<value> <string>980.43952.30132.41164</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1577703410.93</float>
<float>1577760448.33</float>
<string>UTC</string>
</tuple>
</state>
......
/*global document, window, rJS, translation_data */
/*global document, window, RSVP, rJS, translation_data */
/*jslint nomen: true, indent: 2 */
(function (document, window, rJS, translation_data) {
(function (document, window, RSVP, rJS, translation_data) {
"use strict";
function getSelectedLanguage(gadget, callback) {
if (!gadget.state.language) {
return gadget.getSettingList([
"selected_language",
"default_selected_language"
])
.push(function (result_list) {
gadget.state.language = result_list[0] || result_list[1];
return callback(gadget.state.language);
});
}
return callback(gadget.state.language);
}
function translate(string, gadget) {
if (translation_data[gadget.state.language]) {
return translation_data[gadget.state.language][string] || string;
......@@ -106,20 +120,18 @@
}
function promiseTranslateList(gadget, string_list, only_first) {
// XXX Allow to change the language
if (!gadget.state.language) {
return gadget.getSettingList(["selected_language",
"default_selected_language"])
.push(function (result_list) {
gadget.state.language = result_list[0] || result_list[1];
return translateList(gadget, string_list, only_first);
});
}
return translateList(gadget, string_list, only_first);
return getSelectedLanguage(gadget, function () {
return translateList(gadget, string_list, only_first);
});
}
rJS(window)
.declareAcquiredMethod("getSettingList", "getSettingList")
.declareMethod('getSelectedLanguage', function () {
return getSelectedLanguage(this, function (language) {
return language;
});
})
.declareMethod('getTranslationList', function (string_list) {
return promiseTranslateList(this, string_list);
})
......@@ -129,15 +141,9 @@
.declareMethod('translateHtml', function (string) {
var gadget = this;
if (!gadget.state.language) {
return gadget.getSettingList(["selected_language",
"default_selected_language"])
.push(function (result_list) {
gadget.state.language = result_list[0] || result_list[1];
return translateHtml(string, gadget);
});
}
return translateHtml(string, gadget);
return getSelectedLanguage(gadget, function () {
return translateHtml(string, gadget);
});
});
}(document, window, rJS, translation_data));
}(document, window, RSVP, rJS, translation_data));
......@@ -8,6 +8,13 @@
<h3>Gadget used to translate text</h3>
<dl>
<dt>getSelectedLanguage</dt>
<dd>Return the selected language, in which the UI is displayed</dd>
<dl>
<dt></dt>
<dd></dd>
</dl>
<dt>translate</dt>
<dd>Translate a text</dd>
<dl>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment