Commit 9d0b0878 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_web_renderjs_ui] Translate: add getTranslationList method

parent e61e0c87
...@@ -410,6 +410,11 @@ ...@@ -410,6 +410,11 @@
.allowPublicAcquisition("translate", function translate(argument_list) { .allowPublicAcquisition("translate", function translate(argument_list) {
return route(this, 'translation_gadget', 'translate', argument_list); return route(this, 'translation_gadget', 'translate', argument_list);
}) })
.allowPublicAcquisition("getTranslationList",
function getTranslationList(argument_list) {
return route(this, 'translation_gadget', 'getTranslationList',
argument_list);
})
.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);
......
...@@ -230,7 +230,7 @@ ...@@ -230,7 +230,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>968.42891.16664.21862</string> </value> <value> <string>968.42891.50280.153</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -248,7 +248,7 @@ ...@@ -248,7 +248,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1530622785.99</float> <float>1530622831.54</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global document, window, rJS, translation_data, RSVP */ /*global document, window, rJS, translation_data */
/*jslint nomen: true, indent: 2 */ /*jslint nomen: true, indent: 2 */
(function (document, window, rJS, translation_data, RSVP) { (function (document, window, rJS, translation_data) {
"use strict"; "use strict";
function translate(string, gadget) { function translate(string, gadget) {
...@@ -93,43 +93,51 @@ ...@@ -93,43 +93,51 @@
return temp.innerHTML; return temp.innerHTML;
} }
function translateList(gadget, string_list, only_first) {
var i,
result_list = [];
for (i = 0; i < string_list.length; i += 1) {
result_list.push(translate(string_list[i], gadget));
}
if (only_first) {
return result_list[0];
}
return result_list;
}
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);
}
rJS(window) rJS(window)
.declareAcquiredMethod("getSetting", "getSetting") .declareAcquiredMethod("getSettingList", "getSettingList")
.declareMethod('getTranslationList', function (string_list) {
return promiseTranslateList(this, string_list);
})
.declareMethod('translate', function (string) { .declareMethod('translate', function (string) {
// XXX Allow to change the language return promiseTranslateList(this, [string], true);
var gadget = this;
if (!gadget.state.language) {
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getSetting("selected_language"),
gadget.getSetting("default_selected_language")
]);
})
.push(function (results) {
gadget.state.language = results[0] || results[1];
return translate(string, gadget);
});
}
return translate(string, gadget);
}) })
.declareMethod('translateHtml', function (string) { .declareMethod('translateHtml', function (string) {
var gadget = this; var gadget = this;
if (!gadget.state.language) { if (!gadget.state.language) {
return new RSVP.Queue() return gadget.getSettingList(["selected_language",
.push(function () { "default_selected_language"])
return RSVP.all([ .push(function (result_list) {
gadget.getSetting("selected_language"), gadget.state.language = result_list[0] || result_list[1];
gadget.getSetting("default_selected_language")
]);
})
.push(function (results) {
gadget.state.language = results[0] || results[1];
return translateHtml(string, gadget); return translateHtml(string, gadget);
}); });
} }
return translateHtml(string, gadget); return translateHtml(string, gadget);
}); });
}(document, window, rJS, translation_data, RSVP)); }(document, window, rJS, translation_data));
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>955.20795.60990.42035</string> </value> <value> <string>968.42890.13273.63180</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>1479833218.18</float> <float>1530622707.63</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
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