Commit 67fb3719 authored by Sven Franck's avatar Sven Franck Committed by Xiaowu Zhang

erp5_web_renderjs_ui: add translation gadget first version (not functional)

parent c458bc6c
......@@ -148,6 +148,10 @@
<section data-gadget-url="gadget_jio.html"\n
data-gadget-scope="jio_gadget"\n
data-gadget-sandbox="public"></section>\n
\n
<div data-gadget-sandbox="public" \n
data-gadget-url="gadget_translate.html"\n
data-gadget-scope="translate"></div>\n
</body>\n
</html>
......@@ -272,7 +276,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>sven</string> </value>
<value> <string>super_sven</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -286,7 +290,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>938.26262.19465.39389</string> </value>
<value> <string>939.43978.9403.31744</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -304,7 +308,7 @@
</tuple>
<state>
<tuple>
<float>1414049137.38</float>
<float>1418909214.15</float>
<string>GMT</string>
</tuple>
</state>
......
......@@ -248,6 +248,36 @@
// handle acquisition\n
/////////////////////////////////////////////////////////////////\n
.declareAcquiredMethod("pleaseRedirectMyHash", "pleaseRedirectMyHash")\n
\n
// bridge translation gadget\n
.allowPublicAcquisition("translateRender", function (param_list) {\n
return this.getDeclaredGadget("translate")\n
.push(function (translation_gadget) {\n
return translation_gadget.render.apply(\n
translation_gadget,\n
param_list\n
);\n
});\n
})\n
.allowPublicAcquisition("changeLanguage", function (param_list) {\n
return this.getDeclaredGadget("translate")\n
.push(function (translation_gadget) {\n
return translation_gadget.changeLanguage.apply(\n
translation_gadget,\n
param_list\n
);\n
});\n
})\n
.allowPublicAcquisition("translateElementList", function (param_list) {\n
return this.getDeclaredGadget("translate")\n
.push(function (translation_gadget) {\n
return translation_gadget.translateElementList.apply(\n
translation_gadget,\n
param_list\n
);\n
});\n
})\n
\n
// Bridge to jio gadget\n
.allowPublicAcquisition("jio_allDocs", function (param_list) {\n
return this.getDeclaredGadget("jio_gadget")\n
......@@ -612,7 +642,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>sven</string> </value>
<value> <string>super_sven</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -626,7 +656,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>938.39279.27944.4147</string> </value>
<value> <string>939.45541.57768.39543</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -644,7 +674,7 @@
</tuple>
<state>
<tuple>
<float>1414687653.36</float>
<float>1418913351.61</float>
<string>GMT</string>
</tuple>
</state>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Web Page" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Change_local_roles_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>content_md5</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_translate.html</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>rjs_gadget_translate_html</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value> <string>en</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Page</string> </value>
</item>
<item>
<key> <string>short_title</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content</string> </key>
<value> <string encoding="cdata"><![CDATA[
<!DOCTYPE html>\n
<html>\n
<head>\n
<meta charset="utf-8" />\n
<meta name="viewport" content="width=device-width, user-scalable=no" />\n
<title>Jio Gadget</title>\n
\n
<script src="RSVP.js"></script>\n
<script src="renderjs.js"></script>\n
<script src="i18next.js"></script>\n
\n
<!-- custom script -->\n
<script src="gadget_translate.js"></script>\n
\n
</head>\n
<body></body>\n
</html>
]]></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Gadget Translate</string> </value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>001</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>document_publication_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>edit_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>processing_status_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAU=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>publish_alive</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>super_sven</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1418835833.87</float>
<string>GMT</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>published_alive</string> </value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>edit</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>super_sven</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>939.45272.15892.529</string> </value>
</item>
<item>
<key> <string>state</string> </key>
<value> <string>current</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1418892983.83</float>
<string>GMT</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>detect_converted_file</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>super_sven</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_processing_state</string> </key>
<value> <string>converted</string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>0.0.0.0</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1418835393.41</float>
<string>GMT</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Web Script" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Change_local_roles_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignee</string>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>content_md5</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_translate.js</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>rjs_gadget_translate_js</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value> <string>en</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Script</string> </value>
</item>
<item>
<key> <string>short_title</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content</string> </key>
<value> <string encoding="cdata"><![CDATA[
/*jslint indent: 2, maxlen: 80, nomen: true, todo: true */\n
/*global window, rJS, document, i18n */\n
(function (window, rJS, i18n) {\n
"use strict";\n
\n
/////////////////////////////////////////////////////////////////\n
// Gadget behaviour\n
/////////////////////////////////////////////////////////////////\n
rJS(window)\n
\n
/////////////////////////////////////////////////////////////////\n
// ready\n
/////////////////////////////////////////////////////////////////\n
\n
// Init local properties\n
.ready(function (my_gadget) {\n
my_gadget.property_dict = {};\n
})\n
\n
/////////////////////////////////////////////////////////////////\n
// acquired methods\n
/////////////////////////////////////////////////////////////////\n
.declareAcquiredMethod("jio_ajax", "jio_ajax")\n
\n
/////////////////////////////////////////////////////////////////\n
// declared methods\n
/////////////////////////////////////////////////////////////////\n
.declareMethod(\'changeLanguage\', function (my_new_language) {\n
var translation_gadget = this,\n
current_language = i18n.lng();\n
\n
if (current_language !== my_new_language) {\n
return RSVP.Queue()\n
.push(function () {\n
return Promise.resolve(i18n.setLng(my_new_language));\n
})\n
.push(function () {\n
console.log("translating")\n
return translation_gadget.translateElementList()\n
});\n
}\n
\n
return translation_gadget;\n
})\n
\n
.declareMethod(\'translateLookup\', function (my_lookup) {\n
return i18n.t(my_lookup);\n
})\n
\n
.declareMethod(\'translateElementList\', function (my_list) {\n
var i, l, element, lookup, targets, target, route_text, base, len,\n
has_breaks, elements;\n
\n
if (my_list === undefined || typeof my_list === "function" ||\n
typeof my_list === "object") {\n
base = document;\n
} else {\n
base = my_list[0][0];\n
}\n
elements = base.querySelectorAll("[data-i18n]");\n
\n
for (i = 0, len = elements.length; i < len; i += 1) {\n
element = elements[i];\n
lookup = element.getAttribute("data-i18n");\n
\n
if (lookup) {\n
targets = lookup.split(";");\n
\n
for (l = 0; l < targets.length; l += 1) {\n
target = targets[l].split("]");\n
\n
switch (target[0]) {\n
case "[placeholder":\n
case "[alt":\n
case "[title":\n
element.setAttribute(target[0].substr(1), i18n.t(target[1]));\n
break;\n
case "[value":\n
has_breaks = element.previousSibling.textContent.match(/\\n/g);\n
\n
// JQM inputs > this avoids calling checkboxRadio("refresh")!\n
if (element.tagName === "INPUT") {\n
switch (element.type) {\n
case "submit":\n
case "reset":\n
case "button":\n
route_text = true;\n
break;\n
}\n
}\n
if (route_text && (has_breaks || []).length === 0) {\n
element.previousSibling.textContent = i18n.t(target[1]);\n
}\n
element.value = i18n.t(target[1]);\n
break;\n
case "[parent":\n
element.parentNode.childNodes[0].textContent =\n
i18n.t(target[1]);\n
break;\n
case "[node":\n
element.childNodes[0].textContent = i18n.t(target[1]);\n
break;\n
case "[last":\n
// if null, append, if textnode replace, if span, appned\n
if (element.lastChild && element.lastChild.nodeType === 3) {\n
element.lastChild.textContent = i18n.t(target[1]);\n
} else {\n
element.appendChild(document.createTextNode(i18n.t(target[1])));\n
}\n
break;\n
case "[html":\n
element.innerHTML = i18n.t(target[1]);\n
break;\n
default:\n
// NOTE: be careful of emptying elements with children!\n
while (element.hasChildNodes()) {\n
element.removeChild(element.lastChild);\n
}\n
element.appendChild(document.createTextNode(i18n.t(target[0])));\n
break;\n
}\n
}\n
}\n
}\n
\n
return base;\n
})\n
\n
.declareMethod(\'render\', function (my_option_dict) {\n
var param,\n
lang,\n
ns,\n
path,\n
props,\n
translation_gadget = this;\n
\n
function parseRespomse(my_response) {\n
if (typeof my_response === \'string\') {\n
return JSON.parse(my_response);\n
}\n
return my_response;\n
}\n
\n
for (param in my_option_dict) {\n
if (my_option_dict.hasOwnProperty(param)) {\n
translation_gadget.property_dict[param] = my_option_dict[param];\n
} \n
}\n
\n
// TODO: must follow translation plugin API\n
i18n.init({\n
"customLoad": function (my_lng, my_ns, my_option_dict, my_callback) {\n
\n
props = translation_gadget.property_dict;\n
lang = my_lng || props.language_list[0];\n
// XXX: there seems to be a bug in customLoad, set to "translation"\n
ns = props.language_ns;\n
path = props.language_src + "?language=" + lang + "&namespace=" + ns;\n
\n
return new RSVP.Queue()\n
.then(function () {\n
return translation_gadget.jio_ajax({\n
"method": "GET",\n
"url": path,\n
"xhrFields": {"withCredentials": true}\n
});\n
})\n
.then(function (my_event) {\n
return my_event.target.responseText;\n
})\n
.then(function (my_translation_dict) {\n
console.log("so...")\n
console.log(my_callback)\n
return my_callback(null, parseRespomse(my_translation_dict));\n
})\n
.then(function () {\n
return translation_gadget;\n
});\n
},\n
"use_browser_language": true,\n
"lng": lang,\n
"load": "current",\n
"fallbackLng": false,\n
"ns": ns\n
});\n
\n
return translation_gadget;\n
});\n
\n
\n
}(window, rJS, i18n));
]]></string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Gadget Translate JS</string> </value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>001</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>document_publication_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>edit_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>processing_status_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAU=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>publish_alive</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>super_sven</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1418835927.52</float>
<string>GMT</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>published_alive</string> </value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>edit</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>super_sven</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>939.45588.4119.48810</string> </value>
</item>
<item>
<key> <string>state</string> </key>
<value> <string>current</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1418912045.34</float>
<string>GMT</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>detect_converted_file</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>super_sven</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_processing_state</string> </key>
<value> <string>converted</string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>0.0.0.0</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1418835843.83</float>
<string>GMT</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
</ZopeData>
This source diff could not be displayed because it is too large. You can view the blob instead.
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