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 @@ ...@@ -549,6 +549,9 @@
return route(this, 'translation_gadget', 'getTranslationList', return route(this, 'translation_gadget', 'getTranslationList',
argument_list); argument_list);
}) })
.allowPublicAcquisition("getSelectedLanguage", function getSelectedLanguage() {
return route(this, 'translation_gadget', 'getSelectedLanguage');
})
.allowPublicAcquisition("redirect", function redirect(param_list) { .allowPublicAcquisition("redirect", function redirect(param_list) {
return route(this, 'router', 'redirect', param_list); return route(this, 'router', 'redirect', param_list);
......
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>978.22304.53878.1495</string> </value> <value> <string>980.43952.30132.41164</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -252,7 +252,7 @@ ...@@ -252,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1577703410.93</float> <float>1577760448.33</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global document, window, rJS, translation_data */ /*global document, window, RSVP, rJS, translation_data */
/*jslint nomen: true, indent: 2 */ /*jslint nomen: true, indent: 2 */
(function (document, window, rJS, translation_data) { (function (document, window, RSVP, rJS, translation_data) {
"use strict"; "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) { function translate(string, gadget) {
if (translation_data[gadget.state.language]) { if (translation_data[gadget.state.language]) {
return translation_data[gadget.state.language][string] || string; return translation_data[gadget.state.language][string] || string;
...@@ -106,20 +120,18 @@ ...@@ -106,20 +120,18 @@
} }
function promiseTranslateList(gadget, string_list, only_first) { function promiseTranslateList(gadget, string_list, only_first) {
// XXX Allow to change the language return getSelectedLanguage(gadget, function () {
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 translateList(gadget, string_list, only_first);
}
rJS(window) rJS(window)
.declareAcquiredMethod("getSettingList", "getSettingList") .declareAcquiredMethod("getSettingList", "getSettingList")
.declareMethod('getSelectedLanguage', function () {
return getSelectedLanguage(this, function (language) {
return language;
});
})
.declareMethod('getTranslationList', function (string_list) { .declareMethod('getTranslationList', function (string_list) {
return promiseTranslateList(this, string_list); return promiseTranslateList(this, string_list);
}) })
...@@ -129,15 +141,9 @@ ...@@ -129,15 +141,9 @@
.declareMethod('translateHtml', function (string) { .declareMethod('translateHtml', function (string) {
var gadget = this; var gadget = this;
if (!gadget.state.language) { return getSelectedLanguage(gadget, function () {
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 translateHtml(string, gadget);
}); });
}(document, window, rJS, translation_data)); }(document, window, RSVP, rJS, translation_data));
...@@ -152,11 +152,13 @@ ...@@ -152,11 +152,13 @@
</record> </record>
<record id="3" aka="AAAAAAAAAAM="> <record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -200,16 +202,20 @@ ...@@ -200,16 +202,20 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -232,7 +238,7 @@ ...@@ -232,7 +238,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>968.42890.13273.63180</string> </value> <value> <string>981.1053.43706.60842</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -250,7 +256,7 @@ ...@@ -250,7 +256,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1530622707.63</float> <float>1578453690.65</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
...@@ -259,16 +265,20 @@ ...@@ -259,16 +265,20 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
<record id="5" aka="AAAAAAAAAAU="> <record id="5" aka="AAAAAAAAAAU=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -316,7 +326,9 @@ ...@@ -316,7 +326,9 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
</ZopeData> </ZopeData>
...@@ -8,6 +8,13 @@ ...@@ -8,6 +8,13 @@
<h3>Gadget used to translate text</h3> <h3>Gadget used to translate text</h3>
<dl> <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> <dt>translate</dt>
<dd>Translate a text</dd> <dd>Translate a text</dd>
<dl> <dl>
......
...@@ -152,11 +152,13 @@ ...@@ -152,11 +152,13 @@
</record> </record>
<record id="3" aka="AAAAAAAAAAM="> <record id="3" aka="AAAAAAAAAAM=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -200,16 +202,20 @@ ...@@ -200,16 +202,20 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
<record id="4" aka="AAAAAAAAAAQ="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -232,7 +238,7 @@ ...@@ -232,7 +238,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>969.42104.25183.61832</string> </value> <value> <string>980.55319.6399.26880</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -250,7 +256,7 @@ ...@@ -250,7 +256,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1534507750.94</float> <float>1578361034.9</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
...@@ -259,16 +265,20 @@ ...@@ -259,16 +265,20 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
<record id="5" aka="AAAAAAAAAAU="> <record id="5" aka="AAAAAAAAAAU=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
<pickle> <pickle>
<tuple> <dictionary>
<none/> <item>
<key> <string>_log</string> </key>
<value>
<list> <list>
<dictionary> <dictionary>
<item> <item>
...@@ -316,7 +326,9 @@ ...@@ -316,7 +326,9 @@
</item> </item>
</dictionary> </dictionary>
</list> </list>
</tuple> </value>
</item>
</dictionary>
</pickle> </pickle>
</record> </record>
</ZopeData> </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