Commit 524e5445 authored by Xiaowu Zhang's avatar Xiaowu Zhang Committed by Xiaowu Zhang

erp5_web_renderjs_ui: available to translate

parent d1085bd6
......@@ -1076,12 +1076,130 @@ class TestERP5Document_getHateoas_mode_worklist(ERP5HALJSONStyleSkinsMixin):
result_dict = json.loads(result)
self.assertEqual(result_dict['_links']['self'], {"href": "http://example.org/bar"})
work_list = [x for x in result_dict['worklist'] if x['name'].startswith('Draft To Validate (')]
work_list = [x for x in result_dict['worklist'] if x['name'].startswith('Draft To Validate')]
self.assertEqual(len(work_list), 1)
self.assertTrue(work_list[0]['count'] > 0)
self.assertEqual(work_list[0]['name'], 'Draft To Validate (%i)' % work_list[0]['count'])
self.assertEqual(work_list[0]['name'], 'Draft To Validate')
self.assertEqual(work_list[0]['module'], 'urn:jio:get:bar_module')
self.assertEqual(work_list[0]['href'], 'urn:jio:allDocs?query=portal_type%3A%28%22Bar%22%20OR%20%22Foo%22%29%20AND%20simulation_state%3A%22draft%22')
self.assertEqual(result_dict['_debug'], "worklist")
class TestERP5Document_getHateoas_translation(ERP5HALJSONStyleSkinsMixin):
code_string = "\
from Products.CMFCore.utils import getToolByName\n\
translation_service = getToolByName(context, 'Localizer', None)\n\
if translation_service is not None :\n\
try:\n\
if not encoding:\n\
return translation_service.translate(catalog, msg, lang=lang, **kw)\n\
msg = translation_service.translate(catalog, msg, lang=lang, **kw)\n\
if same_type(msg, u''):\n\
msg = msg.encode(encoding)\n\
return msg\n\
except AttributeError:\n\
pass\n\
return msg"
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@simulate('Base_translateString', 'msg, catalog="ui", encoding="utf8", lang="wo", **kw',
code_string)
@changeSkin('Hal')
def test_getHateoasBulk_default_view_translation(self):
self.portal.Base_createUITestLanguages()
param_dict = [
{ 'message': 'Title', 'translation': 'biaoti', 'language': 'wo'},
{ 'message': 'Draft To Validate', 'translation': 'daiyanzhen', 'language': 'wo'},
{ 'message': 'Foo', 'translation': 'Foo_zhongwen', 'language': 'wo'}]
for tmp in param_dict:
self.portal.Base_addUITestTranslation(message = tmp['message'], translation = tmp['translation'], language = tmp['language'])
document = self._makeDocument()
fake_request = do_fake_request("POST")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(
REQUEST=fake_request,
mode="bulk",
bulk_list=json.dumps([{"relative_url": document.getRelativeUrl(), "view": "view"}])
)
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/hal+json"
)
result_dict = json.loads(result)
self.assertEqual(result_dict['result_list'][0]['_embedded']['_view']['my_title']['title'], 'biaoti')
self.assertEqual(result_dict['result_list'][0]['_links']['type']['name'], 'Foo_zhongwen')
self.assertEqual(result_dict['result_list'][0]['_embedded']['_view']['listbox']['column_list'][1][1], 'biaoti')
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@simulate('Base_translateString', 'msg, catalog="ui", encoding="utf8", lang="wo", **kw',
code_string)
@changeSkin('Hal')
def test_getHateoasDocument_result_translation(self):
document = self._makeDocument()
fake_request = do_fake_request("GET")
result = document.ERP5Document_getHateoas(REQUEST=fake_request)
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/hal+json"
)
result_dict = json.loads(result)
self.assertEqual(result_dict['_links']['type']['href'], 'urn:jio:get:portal_types/%s' % document.getPortalType())
self.assertEqual(result_dict['_links']['type']['name'], 'Foo_zhongwen')
self.assertEqual(result_dict['title'].encode("UTF-8"), document.getTitle())
self.assertEqual(result_dict['_debug'], "root")
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@simulate('Base_translateString', 'msg, catalog="ui", encoding="utf8", lang="wo", **kw',
code_string)
@changeSkin('Hal')
def test_getHateoasWorklist_default_view_translation(self):
# self._makeDocument()
fake_request = do_fake_request("GET")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(
REQUEST=fake_request,
mode="worklist"
)
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/hal+json"
)
result_dict = json.loads(result)
self.assertEqual(result_dict['_links']['self'], {"href": "http://example.org/bar"})
work_list = [x for x in result_dict['worklist'] if x['name'].startswith('daiyanzhen')]
self.assertEqual(len(work_list), 1)
self.assertEqual(work_list[0]['name'], 'daiyanzhen')
self.assertTrue(work_list[0]['count'] > 0)
self.assertEqual(work_list[0]['module'], 'urn:jio:get:bar_module')
self.assertEqual(work_list[0]['href'], 'urn:jio:allDocs?query=portal_type%3A%28%22Bar%22%20OR%20%22Foo%22%29%20AND%20simulation_state%3A%22draft%22')
self.assertEqual(result_dict['_debug'], "worklist")
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@simulate('Base_translateString', 'msg, catalog="ui", encoding="utf8", lang="wo", **kw',
code_string)
@changeSkin('Hal')
def test_getHateoasForm_no_view(self):
fake_request = do_fake_request("GET")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(REQUEST=fake_request, mode="traverse", relative_url="portal_skins/erp5_ui_test/Foo_view")
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/hal+json"
)
result_dict = json.loads(result)
self.assertEqual(result_dict['title'], 'Foo_zhongwen')
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ActionInformation" module="Products.CMFCore.ActionInformation"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_action</string>
</tuple>
</value>
</item>
<item>
<key> <string>category</string> </key>
<value> <string>object_action</string> </value>
</item>
<item>
<key> <string>condition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>icon</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>create_translation_data</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Action Information</string> </value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>1.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Create Translation Data</string> </value>
</item>
<item>
<key> <string>visible</string> </key>
<value> <int>1</int> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Expression" module="Products.CMFCore.Expression"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/WebSite_createTranslationData</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -230,7 +230,6 @@ gadget_translation.html\n
gadget_translation.js\n
gadget_translation_data.js\n
handlebars.js\n
i18next.js\n
jiodev.js\n
renderjs.js\n
rsvp.js\n
......
......@@ -8,7 +8,7 @@
.push(function () {
var title = erp5_document.title,
portal_type = erp5_document._links.type.name;
if (/ Module$/.test(portal_type)) {
if (/ Module$/.test(erp5_document._links.type.href)) {
return portal_type;
}
return portal_type + ': ' + title;
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>950.28789.14822.18670</string> </value>
<value> <string>954.14461.31508.53930</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1460380170.56</float>
<float>1476894652.41</float>
<string>UTC</string>
</tuple>
</state>
......
<!DOCTYPE html>
<html>
<head>
<!--
data-i18n=Front
data-i18n=Previous
data-i18n=Cancel
data-i18n=Back
data-i18n=Editable
data-i18n=Viewable
data-i18n=New
data-i18n=Save
data-i18n=Proceed
data-i18n=Add
data-i18n=Filter
data-i18n=Views
data-i18n=Jump
data-i18n=Delete
data-i18n=Export
data-i18n=Actions
data-i18n=Cut
data-i18n=Add
data-i18n=Previous
data-i18n=Next
data-i18n=Loading
-->
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>ERP5 Header</title>
......
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>955.10496.5559.9130</string> </value>
<value> <string>954.5917.19875.40379</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1479462688.84</float>
<float>1474563958.55</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -15,6 +15,9 @@
<script data-renderjs-configuration="default_view_reference" type="text/x-renderjs-configuration">${default_view_reference}</script>
<script data-renderjs-configuration="hateoas_url" type="text/x-renderjs-configuration">${hateoas_url}</script>
<script data-renderjs-configuration="frontpage_gadget" type="text/x-renderjs-configuration">${frontpage_gadget}</script>
<script data-renderjs-configuration="language_map" type="text/x-renderjs-configuration">${language_map}</script>
<script data-renderjs-configuration="default_selected_language" type="text/x-renderjs-configuration">${default_selected_language}</script>
<script data-renderjs-configuration="website_url_set" type="text/x-renderjs-configuration">${website_url_set}</script>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
......
......@@ -236,7 +236,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>955.19466.27249.10478</string> </value>
<value> <string>954.5916.8255.62617</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -254,7 +254,7 @@
</tuple>
<state>
<tuple>
<float>1479222440.45</float>
<float>1475848425.64</float>
<string>UTC</string>
</tuple>
</state>
......
<!DOCTYPE html>
<html>
<head>
<!--
data-i18n=No records
data-i18n=Records
-->
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>ERP5 Listbox</title>
......
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>954.47421.47694.22459</string> </value>
<value> <string>953.48474.52969.47820</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1476967547.86</float>
<float>1474554275.61</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -36,10 +36,11 @@
error_message_source = gadget_klass.__template_element
.getElementById("error-message-template")
.innerHTML,
error_message_template = Handlebars.compile(error_message_source);
error_message_template = Handlebars.compile(error_message_source),
variable = {};
function renderListboxThead(gadget, template, head_value) {
function renderListboxThead(gadget, template) {
return gadget.translateHtml(template({
head_value: gadget.props.head_value,
show_anchor: gadget.state.show_anchor,
......@@ -189,7 +190,8 @@
field_json = options.field_json,
i,
sort_column_list = [],
search_column_list = [];
search_column_list = [],
queue;
//only display which is in listbox's column list
if (field_json.sort_column_list.length) {
......@@ -215,7 +217,21 @@
}
search_column_list.push(["searchable_text", "Searchable Text"]);
return RSVP.Queue()
queue = RSVP.Queue();
if (!variable.translated_records) {
queue
.push(function () {
return RSVP.all([
gadget.translate('Records'),
gadget.translate('No records')
]);
})
.push(function (results) {
variable.translated_records = results[0];
variable.translated_no_record = results[1];
});
}
queue
.push(function () {
// Cancel previous line rendering to not conflict with the asynchronous render for now
return gadget.renderContent(true);
......@@ -258,6 +274,7 @@
// Force line calculation in any case
return gadget.renderContent();
});
return queue;
})
.onStateChange(function () {
......@@ -467,11 +484,11 @@
foot.next_classname = "ui-btn ui-icon-carat-r ui-btn-icon-right responsive ui-last-child";
foot.next_url = url_list[1];
if ((begin_from === 0) && (counter === 0)) {
foot.record = "No records";
foot.record = variable.translated_no_record;
} else if ((dataset.data.rows.length <= lines) && (begin_from === 0)) {
foot.record = counter + " Records";
foot.record = counter + " " + variable.translated_records;
} else {
foot.record = "Records " + (((begin_from + lines) / lines - 1) * lines + 1) + " - " + (((begin_from + lines) / lines - 1) * lines + counter);
foot.record = variable.translated_records + " " + (((begin_from + lines) / lines - 1) * lines + 1) + " - " + (((begin_from + lines) / lines - 1) * lines + counter);
}
if (begin_from === 0) {
......@@ -649,4 +666,4 @@
});
}(window, document, rJS, URI, RSVP,
SimpleQuery, ComplexQuery, Query, Handlebars, console, QueryFactory));
\ No newline at end of file
SimpleQuery, ComplexQuery, Query, Handlebars, console, QueryFactory));
......@@ -236,7 +236,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>954.47559.38051.59921</string> </value>
<value> <string>955.20594.58985.30890</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -254,7 +254,7 @@
</tuple>
<state>
<tuple>
<float>1476976330.15</float>
<float>1479290108.34</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -23,6 +23,7 @@
url: gadget.state.url,
allow_creation: gadget.state.allow_creation,
portal_types: gadget.state.portal_types,
translated_portal_types: gadget.state.translated_portal_types,
value_relative_url: value_relative_url,
value_text: value_text,
value_uid: value_uid,
......@@ -55,6 +56,7 @@
url: field_json.url,
allow_creation: field_json.allow_creation,
portal_types: field_json.portal_types,
translated_portal_types: field_json.translated_portal_types,
relation_field_id: field_json.relation_field_id,
hidden: field_json.hidden
};
......@@ -233,4 +235,4 @@
return final_result;
});
}(window, rJS, RSVP, document));
\ No newline at end of file
}(window, rJS, RSVP, document));
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>955.7644.28099.443</string> </value>
<value> <string>955.20651.19230.8738</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1479375486.58</float>
<float>1479293669.46</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -47,7 +47,7 @@
}
return gadget.jio_allDocs({
query: Query.objectToSearchText(new ComplexQuery({operator: 'OR', query_list: query_list})),
select_list: ["title", "portal_type"],
select_list: ["title", "translated_portal_type"],
limit: id_list.length
});
})
......@@ -72,7 +72,7 @@
for (i = 0; i < result_list.length; i += 1) {
document_dict[result_list[i][2]] = {
link: result_list[i][0],
title: (result_list[i][1].title || result_list[i][2]) + " (" + result_list[i][1].portal_type + ")"
title: (result_list[i][1].title || result_list[i][2]) + " (" + result_list[i][1].translated_portal_type + ")"
};
}
// Sort by access time
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>954.45675.44850.53452</string> </value>
<value> <string>953.52380.29788.47923</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1476952911.66</float>
<float>1473419443.85</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -50,6 +50,7 @@
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("translateHtml", "translateHtml")
/////////////////////////////////////////////////////////////////
// declared methods
......@@ -120,6 +121,12 @@
]]
}
});
})
.push(function () {
return gadget.translateHtml(gadget.props.element.querySelector(".left").innerHTML);
})
.push(function (html) {
gadget.props.element.querySelector(".left").innerHTML = html;
});
})
.declareMethod("triggerSubmit", function () {
......
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>954.27036.35871.42001</string> </value>
<value> <string>954.5791.20424.25736</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1475744573.87</float>
<float>1474556136.49</float>
<string>UTC</string>
</tuple>
</state>
......
<!DOCTYPE html>
<html>
<!--
data-i18n=Type
data-i18n=Reference
data-i18n=Description
data-i18n=State
-->
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
......
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>950.28765.38539.13653</string> </value>
<value> <string>953.56663.27739.23483</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1460378755.69</float>
<float>1474563707.59</float>
<string>UTC</string>
</tuple>
</state>
......
<!DOCTYPE html>
<html>
<!--
data-i18n=Worklist
-->
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
......
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>954.45675.44850.53452</string> </value>
<value> <string>953.56732.44606.43468</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1476955713.49</float>
<float>1474556302.46</float>
<string>UTC</string>
</tuple>
</state>
......