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

[erp5_web_renderjs_ui] Translate: add getTranslationList method

parent e61e0c87
......@@ -410,6 +410,11 @@
.allowPublicAcquisition("translate", function 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) {
return route(this, 'router', 'redirect', param_list);
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>968.42891.16664.21862</string> </value>
<value> <string>968.42891.50280.153</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1530622785.99</float>
<float>1530622831.54</float>
<string>UTC</string>
</tuple>
</state>
......
/*global document, window, rJS, translation_data, RSVP */
/*global document, window, rJS, translation_data */
/*jslint nomen: true, indent: 2 */
(function (document, window, rJS, translation_data, RSVP) {
(function (document, window, rJS, translation_data) {
"use strict";
function translate(string, gadget) {
......@@ -93,43 +93,51 @@
return temp.innerHTML;
}
rJS(window)
.declareAcquiredMethod("getSetting", "getSetting")
.declareMethod('translate', function (string) {
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
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 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 translate(string, gadget);
return translateList(gadget, string_list, only_first);
}
rJS(window)
.declareAcquiredMethod("getSettingList", "getSettingList")
.declareMethod('getTranslationList', function (string_list) {
return promiseTranslateList(this, string_list);
})
.declareMethod('translate', function (string) {
return promiseTranslateList(this, [string], true);
})
.declareMethod('translateHtml', function (string) {
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 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);
});
}(document, window, rJS, translation_data, RSVP));
}(document, window, rJS, translation_data));
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>955.20795.60990.42035</string> </value>
<value> <string>968.42890.13273.63180</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1479833218.18</float>
<float>1530622707.63</float>
<string>UTC</string>
</tuple>
</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