Commit 8b4be062 authored by Nicolas Wavrant's avatar Nicolas Wavrant

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

parent 0573083e
......@@ -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) {
var queue = new RSVP.Queue();
if (!gadget.state.language) {
queue.push(function () {
return gadget.getSettingList([
"selected_language",
"default_selected_language"
]);
})
.push(function (result_list) {
gadget.state.language = result_list[0] || result_list[1];
});
}
return queue.push(function () {
return gadget.state.language;
});
}
function translate(string, gadget) {
if (translation_data[gadget.state.language]) {
return translation_data[gadget.state.language][string] || string;
......@@ -106,20 +126,17 @@
}
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 getSelectedLanguage(gadget)
.push(function () {
return translateList(gadget, string_list, only_first);
});
}
return translateList(gadget, string_list, only_first);
}
rJS(window)
.declareAcquiredMethod("getSettingList", "getSettingList")
.declareMethod('getSelectedLanguage', function () {
return getSelectedLanguage(this);
})
.declareMethod('getTranslationList', function (string_list) {
return promiseTranslateList(this, string_list);
})
......@@ -129,15 +146,10 @@
.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 getSelectedLanguage(gadget)
.push(function (language) {
return translateHtml(string, gadget);
});
}
return translateHtml(string, gadget);
});
}(document, window, rJS, translation_data));
}(document, window, RSVP, rJS, translation_data));
......@@ -152,11 +152,13 @@
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -200,16 +202,20 @@
</item>
</dictionary>
</list>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -232,7 +238,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>968.42890.13273.63180</string> </value>
<value> <string>980.48186.1859.61969</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -250,7 +256,7 @@
</tuple>
<state>
<tuple>
<float>1530622707.63</float>
<float>1577760469.24</float>
<string>UTC</string>
</tuple>
</state>
......@@ -259,16 +265,20 @@
</item>
</dictionary>
</list>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<tuple>
<none/>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<list>
<dictionary>
<item>
......@@ -316,7 +326,9 @@
</item>
</dictionary>
</list>
</tuple>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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