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>
......
......@@ -61,7 +61,7 @@
view: 'view'
}}),
// Remove the counter from the title
action_list[i].name.replace(/ \(\d+\)$/, ''),
action_list[i].name,
action_list[i].count
]));
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>954.47218.14887.48486</string> </value>
<value> <string>949.45349.17509.30190</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1476956693.83</float>
<float>1473173906.59</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -36,7 +36,7 @@
<li><a href="{{module_href}}" class="ui-btn ui-btn-icon-left ui-icon-puzzle-piece" data-i18n="Modules" accesskey="m">Modules</a></li>
<li><a href="{{worklist_href}}" class="ui-btn ui-btn-icon-left ui-icon-clipboard" data-i18n="Worklists" accesskey="w">Worklists</a></li>
<li><a href="{{history_href}}" class="ui-btn ui-btn-icon-left ui-icon-history" data-i18n="History" accesskey="h">History</a></li>
<li><a href="{{search_href}}" class="ui-btn ui-btn-icon-left ui-icon-search" data-i18n="History" accesskey="s">Search</a></li>
<li><a href="{{search_href}}" class="ui-btn ui-btn-icon-left ui-icon-search" data-i18n="Search" accesskey="s">Search</a></li>
<li><a href="{{preference_href}}" class="ui-btn ui-btn-icon-left ui-icon-gear" data-i18n="Preference">Preferences</a></li>
<!--div>
{{#if language_list}}
......
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>952.14137.61057.25617</string> </value>
<value> <string>953.6580.58198.13568</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1467279122.77</float>
<float>1473162224.39</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -78,7 +78,7 @@
"search_href": all_result[4],
"worklist_href": all_result[5]
});
return tmp;
return g.translateHtml(tmp);
})
.push(function (my_translated_or_plain_html) {
g.props.element.querySelector("div").innerHTML = my_translated_or_plain_html;
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>952.1507.19232.15035</string> </value>
<value> <string>953.6580.58198.13568</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1466524414.0</float>
<float>1473161369.59</float>
<string>UTC</string>
</tuple>
</state>
......
<!DOCTYPE html>
<html>
<head>
<!--
data-i18n=Workflow-Transitions
data-i18n=Actions
-->
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>ERP5 Page Action</title>
......
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>949.53789.19765.27784</string> </value>
<value> <string>953.48219.30595.27340</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1460378795.97</float>
<float>1474556323.96</float>
<string>UTC</string>
</tuple>
</state>
......
<!DOCTYPE html>
<html>
<!--
data-i18n=Title
-->
<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>952.43255.60632.47035</string> </value>
<value> <string>954.5909.42680.32921</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1468942516.97</float>
<float>1474563730.2</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -52,8 +52,7 @@
})
.push(function (form_gadget) {
var column_list = [
['title', 'Title']
];
['translated_title', 'Title']];
return form_gadget.render({
erp5_document: {"_embedded": {"_view": {
"listbox": {
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>952.64761.25287.18397</string> </value>
<value> <string>954.44756.57059.6894</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1475244399.84</float>
<float>1476893530.25</float>
<string>UTC</string>
</tuple>
</state>
......
<!DOCTYPE html>
<html>
<!--
data-i18n=User
data-i18n=Language
-->
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
......@@ -12,10 +16,17 @@
<!-- custom script -->
<script src="gadget_erp5_page_preference.js" type="text/javascript"></script>
</head>
<body>
Who are you?
</head>
<body>
<form class="preference">
<button type="submit" class="ui-btn ui-btn-b ui-btn-inline
ui-icon-edit ui-btn-icon-right ui-screen-hidden"></button>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="erp5_form"
data-gadget-sandbox="public">
</div>
</form>
</body>
</html>
\ No newline at end of file
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>954.45675.44850.53452</string> </value>
<value> <string>953.6663.63367.11298</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1476958219.29</float>
<float>1473246353.73</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS */
/*global window, rJS, RSVP */
/*jslint indent: 2, maxerr: 3 */
(function (window, rJS) {
(function (window, rJS, RSVP) {
"use strict";
rJS(window)
......@@ -8,22 +8,30 @@
// handle acquisition
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("translate", "translate")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("setSetting", "setSetting")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.declareAcquiredMethod("redirect", "redirect")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function () {
var gadget = this;
// XXX: Lot of DOM touches
var gadget = this,
user = "Who are you?";
return gadget.updateHeader({
page_title: 'Preference'
page_title: 'Preference',
save_action: true
})
.push(function () {
return gadget.getDeclaredGadget("erp5_form");
})
.push(function (erp5_form) {
gadget.state.erp5_form = erp5_form;
return gadget.getSetting('me');
})
.push(function (me) {
......@@ -33,17 +41,89 @@
select_list: ['title']
})
.push(function (result) {
gadget.element.textContent = result.data.rows[0].value.title;
user = result.data.rows[0].value.title;
});
}
// gadget.props.element.textContent = me;
})
.push(function () {
return gadget.translateHtml(gadget.element.innerHTML);
return RSVP.all([
gadget.getSetting("language_map"),
gadget.getSetting("selected_language"),
gadget.getSetting("default_selected_language"),
gadget.translate("User"),
gadget.translate("Language")
]);
})
.push(function (my_translated_html) {
gadget.element.innerHTML = my_translated_html;
.push(function (results) {
var selected_language = results[1] || results[2],
key,
list_item = [],
options = JSON.parse(results[0]);
gadget.state.old_selected_lang = selected_language;
for (key in options) {
if (options.hasOwnProperty(key)) {
list_item.push([options[key], key]);
}
}
return gadget.state.erp5_form.render({
erp5_document: {"_embedded": {"_view": {
'User': {
"default": user,
"editable": 0,
"key": "field_user",
"title": results[3],
"type": "StringField"
},
'Language': {
"default": selected_language,
"editable": 1,
"items": list_item,
"key": "field_language",
"title": results[4],
"type": "ListField"
}
}},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}
},
form_definition: {
group_list: [[
"left",
[["User"], ["Language"]]
]]
}
});
});
})
.declareMethod('triggerSubmit', function () {
this.element.querySelector('button').click();
})
.onEvent('submit', function () {
var gadget = this,
selected_lang;
return gadget.notifySubmitting()
.push(function () {
return gadget.state.erp5_form.getContent();
})
.push(function (data) {
selected_lang = data.field_language;
return gadget.setSetting("selected_language", selected_lang);
})
.push(function () {
if (gadget.state.old_selected_lang !== selected_lang) {
return gadget.redirect({
command: 'change_language',
options: {
language: selected_lang
}
});
}
return gadget.notifySubmitted();
});
});
}(window, rJS));
\ No newline at end of file
}(window, rJS, RSVP));
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>954.47266.11723.40516</string> </value>
<value> <string>955.20539.55071.38980</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1476958263.79</float>
<float>1479302491.62</float>
<string>UTC</string>
</tuple>
</state>
......
<!DOCTYPE html>
<html>
<!--
data-i18n=Jumps
data-i18n=Breadcrumb
-->
<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>946.44927.40202.16725</string> </value>
<value> <string>953.49748.33034.5700</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1460379644.0</float>
<float>1474563753.89</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -34,15 +34,17 @@
<li class="ui-li-static ui-body-inherit ui-icon-mail-forward ui-btn-icon-right" data-relative-url="{{id}}" data-uid="{{uid}}">{{value}}</li>
{{/each}}
{{#each type}}
<li class="ui-li-static ui-body-inherit ui-bar-inherit ui-icon-plus ui-btn-icon-right" data-create-object="{{this}}" name="{{this}}">Create New {{this}}: {{../value}}</li>
<li class="ui-li-static ui-body-inherit ui-bar-inherit ui-icon-plus ui-btn-icon-right" data-i18n="Create New" data-create-object="{{value}}" name="{{name}}">Create New
<span data-create-object="{{value}}"> {{name}}: {{../value}}</span></li>
{{/each}}
{{else}}
<!--li class="ui-autocomplete ui-li ui-li-divider ui-bar-inherit ui-first-child" role="heading">No result</li-->
{{#each type}}
<li class="ui-li-static ui-body-inherit ui-bar-inherit ui-icon-plus ui-btn-icon-right" data-create-object="{{this}}" name="{{this}}">Create New {{this}}: {{../value}}</li>
<li class="ui-li-static ui-body-inherit ui-bar-inherit ui-icon-plus ui-btn-icon-right" data-i18n="Create New" data-create-object="{{value}}" name="{{name}}">Create New
<span data-create-object="{{value}}">{{name}}: {{../value}}</span></li>
{{/each}}
{{/if}}
<li class="ui-li-static ui-body-inherit ui-last-child ui-bar-inherit ui-icon-search ui-btn-icon-right" data-explore=true >Explore the Search Result List</li>
<li class="ui-li-static ui-body-inherit ui-last-child ui-bar-inherit ui-icon-search ui-btn-icon-right" data-explore=true data-i18n="Explore the Search Result List" >Explore the Search Result List</li>
</script>
</head>
......
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>955.7622.39581.2525</string> </value>
<value> <string>954.5712.44925.37444</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1478511768.91</float>
<float>1474553624.23</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -86,6 +86,7 @@
url: options.url,
allow_creation: options.allow_creation,
portal_types: options.portal_types,
translated_portal_types: options.translated_portal_types,
has_focus: false,
relation_index: options.relation_index,
value_relative_url: options.value_relative_url,
......@@ -235,11 +236,14 @@
.push(function (result) {
var list = [],
i,
type;
if (gadget.state.allow_creation) {
type = gadget.state.portal_types;
} else {
type = [];
if (gadget.state.allow_creation) {
for (i = 0; i < gadget.state.portal_types.length; i += 1) {
type.push({
name: gadget.state.translated_portal_types[i],
value: gadget.state.portal_types[i]
});
}
}
for (i = 0; i < result.data.rows.length; i += 1) {
list.push({
......@@ -249,11 +253,14 @@
});
}
plane.className = JUMP_UNKNOWN_CLASS_STR;
ul.innerHTML = relation_listview_template({
return gadget.translateHtml(relation_listview_template({
list: list,
type: type,
value: value_text
});
}));
})
.push(function (html) {
ul.innerHTML = html;
});
});
......
......@@ -236,7 +236,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>955.17976.26191.30156</string> </value>
<value> <string>955.20665.33421.35549</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -254,7 +254,7 @@
</tuple>
<state>
<tuple>
<float>1479133107.47</float>
<float>1479294380.88</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -24,6 +24,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,
value_relative_url: field_json.relation_item_relative_url[0],
relation_index: 0,
hidden: field_json.hidden
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>955.7643.7350.21333</string> </value>
<value> <string>955.18006.50413.2645</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1479375314.48</float>
<float>1479293469.27</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -27,6 +27,8 @@
COMMAND_SELECTION_NEXT = "selection_next",
COMMAND_HISTORY_PREVIOUS = "history_previous",
COMMAND_PUSH_HISTORY = "push_history",
COMMAND_CHANGE_LANGUAGE = "change_language",
REDIRECT_TIMEOUT = 5055,
VALID_URL_COMMAND_DICT = {};
VALID_URL_COMMAND_DICT[COMMAND_DISPLAY_STATE] = null;
VALID_URL_COMMAND_DICT[COMMAND_DISPLAY_STORED_STATE] = null;
......@@ -40,6 +42,7 @@
VALID_URL_COMMAND_DICT[COMMAND_LOGIN] = null;
VALID_URL_COMMAND_DICT[COMMAND_RAW] = null;
VALID_URL_COMMAND_DICT[COMMAND_RELOAD] = null;
VALID_URL_COMMAND_DICT[COMMAND_CHANGE_LANGUAGE] = null;
function endsWith(str, suffix) {
......@@ -108,6 +111,20 @@
if (command === COMMAND_RAW) {
return options.url;
}
if (command === COMMAND_CHANGE_LANGUAGE) {
return new RSVP.Queue()
.push(function () {
return gadget.getSetting("website_url_set");
})
.push(function (result) {
var param_list = window.location.hash.split('#')[1],
new_url = JSON.parse(result)[options.language];
if (param_list) {
new_url += '#' + param_list;
}
return new_url;
});
}
var result = "#" + PREFIX_COMMAND + (command || ""),
prefix = "?",
key,
......@@ -858,7 +875,33 @@
})
.declareMethod('start', function () {
this.props.start_deferred.resolve();
var gadget = this;
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getSetting("selected_language"),
gadget.getSetting("default_selected_language")
]);
})
.push(function (results) {
if (results[1] !== results[0] && results[0]) {
return gadget.redirect({
command: 'change_language',
options: {
language: results[0]
}
});
}
})
.push(function () {
gadget.props.start_deferred.resolve();
})
.push(undefined, function (error) {
if (error instanceof RSVP.CancellationError) {
return;
}
throw error;
});
})
.declareAcquiredMethod('renderApplication', 'renderApplication')
......
......@@ -232,7 +232,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>954.57620.63396.46779</string> </value>
<value> <string>955.20572.17338.63419</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -250,7 +250,7 @@
</tuple>
<state>
<tuple>
<float>1477580291.06</float>
<float>1479288846.05</float>
<string>UTC</string>
</tuple>
</state>
......
<!DOCTYPE html>
<html>
<!--
data-i18n=All criterions (AND)
data-i18n=At least one (OR)
data-i18n=Exact Match
data-i18n=keyword
data-i18n=Contain
data-i18n=Equals To
data-i18n=Greater Than
data-i18n=Less Than
data-i18n=Not Greater Than
data-i18n=Not Less Than
data-i18n=Searchable Text
-->
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
......@@ -83,7 +96,7 @@
<fieldset class="ui-controlgroup ui-corner-all">
<select data-iconpos="left" name="heard_about">
<option data-i18n="All criterions (AND)" value="AND">All criterions (AND)</option>
<option data-i18n="At lease one (OR)" value="OR">At lease one (OR)</option>
<option data-i18n="At least one (OR)" value="OR">At least one (OR)</option>
</select>
</fieldset>
......
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>952.34496.35921.52275</string> </value>
<value> <string>954.7210.40753.48042</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1468414694.8</float>
<float>1474905528.91</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -9,7 +9,6 @@
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<script src="i18next.js"></script>
<!-- custom script -->
<script src="gadget_translation_data.js" type="text/javascript"></script>
<script src="gadget_translation.js" type="text/javascript"></script>
......
......@@ -224,7 +224,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>romain</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -238,7 +238,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>945.43799.10287.64221</string> </value>
<value> <string>949.45349.17509.30190</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -256,8 +256,8 @@
</tuple>
<state>
<tuple>
<float>1445935119.77</float>
<string>GMT</string>
<float>1467132987.54</float>
<string>UTC</string>
</tuple>
</state>
</object>
......
/*global document, window, rJS, translation_data */
/*global document, window, rJS, translation_data, RSVP */
/*jslint nomen: true, indent: 2 */
(function (document, window, rJS, translation_data) {
(function (document, window, rJS, translation_data, RSVP) {
"use strict";
function translate(string) {
// XXX i18n.t
return translation_data.en[string] || string;
function translate(string, gadget) {
return translation_data[gadget.state.language][string] || string;
}
rJS(window)
/////////////////////////////////////////////////////////////////
// ready
/////////////////////////////////////////////////////////////////
.ready(function (gadget) {
gadget.property_dict = {};
})
.declareMethod('translate', function (string) {
// XXX Allow to change the language
return translate(string);
})
// translate a list of elements passed and returned as string
function translateHtml(string, gadget) {
var temp, element_list, i, i_len, element, lookup, translate_list, target,
route_text, has_breaks, l, l_len, j, j_len;
// NOTE: <div> cannot be used for everything... (like table rows)
// XXX: currently I only update where needed. Eventually all calls to
// translateHtml should pass "their" proper wrapping element
temp = document.createElement("div");
temp.innerHTML = string;
// translate a list of elements passed and returned as string
.declareMethod('translateHtml', function (my_string) {
var temp, element_list, i, i_len, element, lookup, translate_list, target,
route_text, has_breaks, l, l_len, gadget, j, j_len;
element_list = temp.querySelectorAll("[data-i18n]");
gadget = this;
for (i = 0, i_len = element_list.length; i < i_len; i += 1) {
element = element_list[i];
lookup = element.getAttribute("data-i18n");
// skip if no translations available
if (gadget.property_dict.translation_disabled) {
return my_string;
}
// NOTE: <div> cannot be used for everything... (like table rows)
// XXX: currently I only update where needed. Eventually all calls to
// translateHtml should pass "their" proper wrapping element
temp = document.createElement("div");
temp.innerHTML = my_string;
element_list = temp.querySelectorAll("[data-i18n]");
for (i = 0, i_len = element_list.length; i < i_len; i += 1) {
element = element_list[i];
lookup = element.getAttribute("data-i18n");
if (lookup) {
translate_list = lookup.split(";");
if (lookup) {
translate_list = lookup.split(";");
for (l = 0, l_len = translate_list.length; l < l_len; l += 1) {
target = translate_list[l].split("]");
for (l = 0, l_len = translate_list.length; l < l_len; l += 1) {
target = translate_list[l].split("]");
switch (target[0]) {
case "[placeholder":
case "[alt":
case "[title":
element.setAttribute(target[0].substr(1), translate(target[1], gadget));
break;
case "[value":
has_breaks = element.previousSibling.textContent.match(/\n/g);
switch (target[0]) {
case "[placeholder":
case "[alt":
case "[title":
element.setAttribute(target[0].substr(1), translate(target[1]));
break;
case "[value":
has_breaks = element.previousSibling.textContent.match(/\n/g);
// JQM inputs > this avoids calling checkboxRadio("refresh")!
if (element.tagName === "INPUT") {
switch (element.type) {
case "submit":
case "reset":
case "button":
route_text = true;
break;
}
}
if (route_text && (has_breaks || []).length === 0) {
element.previousSibling.textContent = translate(target[1]);
// JQM inputs > this avoids calling checkboxRadio("refresh")!
if (element.tagName === "INPUT") {
switch (element.type) {
case "submit":
case "reset":
case "button":
route_text = true;
break;
}
element.value = translate(target[1]);
break;
case "[parent":
element.parentNode.childNodes[0].textContent =
translate(target[1]);
break;
case "[node":
element.childNodes[0].textContent = translate(target[1]);
break;
case "[last":
// if null, append, if textnode replace, if span, appned
if (element.lastChild && element.lastChild.nodeType === 3) {
element.lastChild.textContent = translate(target[1]);
} else {
element.appendChild(document.createTextNode(translate(target[1])));
}
break;
case "[html":
element.innerHTML = translate(target[1]);
break;
default:
if (element.hasChildNodes()) {
for (j = 0, j_len = element.childNodes.length; j < j_len; j += 1) {
if (element.childNodes[j].nodeType === 3) {
element.childNodes[j].textContent = translate(translate_list[l]);
}
}
if (route_text && (has_breaks || []).length === 0) {
element.previousSibling.textContent = translate(target[1], gadget);
}
element.value = translate(target[1], gadget);
break;
case "[parent":
element.parentNode.childNodes[0].textContent =
translate(target[1], gadget);
break;
case "[node":
element.childNodes[0].textContent = translate(target[1], gadget);
break;
case "[last":
// if null, append, if textnode replace, if span, appned
if (element.lastChild && element.lastChild.nodeType === 3) {
element.lastChild.textContent = translate(target[1], gadget);
} else {
element.appendChild(document.createTextNode(translate(target[1], gadget)));
}
break;
case "[html":
element.innerHTML = translate(target[1], gadget);
break;
default:
if (element.hasChildNodes()) {
for (j = 0, j_len = element.childNodes.length; j < j_len; j += 1) {
if (element.childNodes[j].nodeType === 3) {
element.childNodes[j].textContent = translate(translate_list[l], gadget);
}
} else {
element.textContent = translate(translate_list[l]);
}
break;
} else {
element.textContent = translate(translate_list[l], gadget);
}
break;
}
}
}
// return string
return temp.innerHTML;
}
// return string
return temp.innerHTML;
}
rJS(window)
.declareAcquiredMethod("getSetting", "getSetting")
.declareMethod('translate', function (string) {
// 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 translate(string, gadget);
})
.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 translateHtml(string, gadget);
});
}
return translateHtml(string, gadget);
});
}(document, window, rJS, translation_data));
}(document, window, rJS, translation_data, RSVP));
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>948.17388.42239.34542</string> </value>
<value> <string>955.18006.50413.2645</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1452009218.06</float>
<float>1479302155.8</float>
<string>UTC</string>
</tuple>
</state>
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -397,7 +397,7 @@
</item>
<item>
<key> <string>static_language_selection</string> </key>
<value> <int>0</int> </value>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>title</string> </key>
......
import re
import json
Base_translateString = context.Base_translateString
#(data-i18n)=["']{{((?:.(?!["']?(?:\S+)=|[>"']))+.)}}["']
attribute_filter_re = re.compile(r"""(data-i18n)=["']?((?:.(?!["']?\s+(?:\S+)=|[>"']))+.)["']?""")
tmp_re = re.compile(r"""/[{}]/g, """"")
translate_word = []
web_page_list = context.Base_getListFileFromAppcache(only_html=1)
for web_page in web_page_list:
web_page = context.web_page_module.searchFolder(portal_type='Web Page',reference=web_page)[0]
data = attribute_filter_re.findall(web_page.getTextContent())
for attribute in data:
a = re.sub(r'[{|}]', "", attribute[1])
a = re.sub(r'\[.*?\]', "", a)
if a:
translate_word.append(a)
translate_word = list(set(translate_word))
language_list = context.getAvailableLanguageSet()
content = """
/*globals window*/\n
/*jslint indent: 2, nomen: true, maxlen: 80*/\n
(function (window) {\n
"use strict";\n
"""
tmp = {}
for language in language_list:
tmp[language] = {}
for word in translate_word:
tmp[language][word] = Base_translateString(word, lang = language)
content += " window.translation_data = " + json.dumps(tmp, indent=3, ensure_ascii=False, separators=(',', ': '))
content += ";\n}(window));"
#return json.dumps(tmp, indent=3, ensure_ascii=False, separators=(',', ': '))
translation_data_file=context.web_page_module.searchFolder(portal_type='Web Script',reference=translation_data_file)[0]
translation_data_file.edit(text_content = content)
if batch_mode:
return 'done'
return context.Base_redirect('view', keep_items=dict(portal_status_message=Base_translateString("Translation Data Create")))
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string> translation_data_file, batch_mode=0</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_createTranslateData</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
appcache_file = context.getLayoutProperty("configuration_manifest_url", default="gadget_erp5.appcache")
text_content = context.web_page_module.searchFolder(
portal_type= 'Web Manifest',
reference = appcache_file)[0].getTextContent()
translation_data_file = []
file_list = []
for file in text_content.split('\n'):
file = file.split('/')[-1]
if file.endswith('.html'):
file_list.append(file)
continue
if file.endswith('.js') and not only_html:
if file.endswith('translation_data.js'):
translation_data_file = [file]
continue
file_list.append(file)
return translation_data_file + file_list
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>only_html = 0</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getListFileFromAppcache</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ERP5 Form" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>action</string> </key>
<value> <string>Base_createTranslateData</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>edit_order</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>enctype</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
<list>
<string>left</string>
<string>right</string>
<string>center</string>
<string>bottom</string>
<string>hidden</string>
</list>
</value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
<dictionary>
<item>
<key> <string>bottom</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>center</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>hidden</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>left</string> </key>
<value>
<list>
<string>your_translation_data_file</string>
</list>
</value>
</item>
<item>
<key> <string>right</string> </key>
<value>
<list/>
</value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>WebSite_createTranslationData</string> </value>
</item>
<item>
<key> <string>method</string> </key>
<value> <string>POST</string> </value>
</item>
<item>
<key> <string>name</string> </key>
<value> <string>WebSite_createTranslationData</string> </value>
</item>
<item>
<key> <string>pt</string> </key>
<value> <string>form_dialog</string> </value>
</item>
<item>
<key> <string>row_length</string> </key>
<value> <int>4</int> </value>
</item>
<item>
<key> <string>stored_encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Create Translation Data</string> </value>
</item>
<item>
<key> <string>unicode_mode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>update_action</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>update_action_title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import json
import re
if REQUEST is None:
REQUEST = context.REQUEST
if response is None:
......@@ -6,6 +9,22 @@ if response is None:
default_web_page = context
web_section = REQUEST.get("current_web_section")
available_language_set = web_section.getLayoutProperty("available_language_set", default=['en'])
portal = context.getPortalObject()
default_language = web_section.getLayoutProperty("default_available_language", default='en')
website_url_set = {}
#simplify code of Base_doLanguage, can't ues Base_doLanguage directly
root_website_url = web_section.getOriginalDocument().absolute_url()
website_url_pattern = r'^%s(?:%s)*(/|$)' % (
re.escape(root_website_url),
'|'.join('/' + re.escape(x) for x in available_language_set))
for language in available_language_set:
if language == default_language:
website_url_set[language] = re.sub(website_url_pattern, r'%s/\1' % root_website_url, web_section.absolute_url())
else:
website_url_set[language]= re.sub(website_url_pattern, r'%s/%s/\1' % (root_website_url, language), web_section.absolute_url())
return default_web_page.WebPage_viewAsWeb(mapping_dict={
"frontpage_gadget": web_section.getLayoutProperty("configuration_frontpage_gadget_url", default="worklist"),
......@@ -18,5 +37,8 @@ return default_web_page.WebPage_viewAsWeb(mapping_dict={
"header_gadget": web_section.getLayoutProperty("configuration_header_gadget_url", default="gadget_erp5_header.html"),
"jio_gadget": web_section.getLayoutProperty("configuration_jio_gadget_url", default="gadget_jio.html"),
"translation_gadget": web_section.getLayoutProperty("configuration_translation_gadget_url", default="gadget_translation.html"),
"manifest_url": web_section.getLayoutProperty("configuration_manifest_url", default="gadget_erp5.appcache")
"manifest_url": web_section.getLayoutProperty("configuration_manifest_url", default="gadget_erp5.appcache"),
"language_map": json.dumps({tmp['id']: portal.Base_translateString(tmp['title'], lang = tmp['id']) for tmp in portal.Localizer.get_languages_map() if tmp['id'] in available_language_set}),
"default_selected_language": portal.Localizer.get_selected_language(),
"website_url_set": json.dumps(website_url_set),
})
......@@ -6,7 +6,8 @@ from ZTUtils import make_query
portal = context.getPortalObject()
if (came_from is None):
came_from = context.getPermanentURL(context.getWebSiteValue())
#XXX Hardcoded for JS app's url end with '/'
came_from = "%s/" % context.getPermanentURL(context.getWebSiteValue())
portal.portal_skins.updateSkinCookie()
portal.setupCurrentSkin(REQUEST)
......
......@@ -10,7 +10,7 @@
<div data-gadget-scope='header'>
<div class="ui-header">
<h1><span>Recover your account</span></h1>
<h1><span i18n:domain="ui" i18n:translate="">Recover your account</span></h1>
</div>
</div>
......@@ -28,13 +28,13 @@
<section>
<form method="post" tal:attributes="action python: context.absolute_url()">
<div class="ui-field-contain">
<label data-i18n="Login">Login<span></span></label>
<label i18n:domain="ui" i18n:translate="">Login</label>
<div><input autofocus type="text" name="user_login" value="" required=""></div>
</div>
<br/>
<div class="ui-field-contain">
<label></label>
<div><input type="submit" data-i18n="[value]Validate" value="Validate" tal:attributes="name python: '%s:method' % (form_action, )"/></div>
<div><input type="submit" value="Validate" i18n:attributes="value" i18n:domain="ui" tal:attributes="name python: '%s:method' % (form_action, )"/></div>
</div>
<input type="hidden" name="url" tal:attributes="value python: context.absolute_url()" />
......
......@@ -10,7 +10,7 @@
<div data-gadget-scope='header'>
<div class="ui-header">
<h1><span>Connect</span></h1>
<h1><span i18n:domain="ui" i18n:translate="">Connect</span></h1>
</div>
</div>
......@@ -34,22 +34,22 @@
<form method="post" tal:attributes="action python: '%s/' % context.absolute_url()">
<div class="ui-field-contain">
<label data-i18n="Login">Login<span></span></label>
<label i18n:domain="ui" i18n:translate="" >Login</label>
<div><input autofocus type="text" name="__ac_name" value="" required=""></div>
</div>
<div class="ui-field-contain">
<label data-i18n="Password">Password<span></span></label>
<label i18n:domain="ui" i18n:translate="" >Password</label>
<div><input type="password" name="__ac_password" value="" required=""></div>
</div>
<div class="ui-field-contain">
<label></label>
<div tal:define="absolute_url python:context.absolute_url()">
<a tal:attributes="href python: '%s/WebSite_viewRecoverAccount?came_from=%s' % (absolute_url, absolute_url)">I forgot my password!</a>
<a i18n:domain="ui" i18n:translate="" tal:attributes="href python: '%s/WebSite_viewRecoverAccount?came_from=%s' % (absolute_url, absolute_url)">I forgot my password!</a>
</div>
</div><br/>
<div class="ui-field-contain">
<label></label>
<div><input type="submit" value="Login" tal:attributes="name python: '%s:method' % (form_action, )"/></div>
<div><input type="submit" value='Login' i18n:attributes="value" i18n:domain="ui" tal:attributes="name python: '%s:method' % (form_action, )"/></div>
</div>
......
......@@ -7,6 +7,7 @@ Web Script | view
Web Script | view_editor
Web Script | view_syntax
Web Script | web_view
Web Site | create_translation_data
Web Style | version_view
Web Style | view
Web Style | view_editor
......
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