Commit 2b79140a authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_travel_expense: available to change language

parent 93066800
......@@ -125,8 +125,6 @@ gadget_erp5.css\n
gadget_global.js\n
gadget_jio.html\n
gadget_jio.js\n
gadget_translate.html\n
gadget_translate.js\n
handlebars.js\n
jiodev.js\n
jquery.js\n
......@@ -140,7 +138,7 @@ gadget_officejs_page_add_document.html\n
gadget_officejs_page_login.html\n
gadget_officejs_page_logout.html\n
gadget_officejs_page_sync.html\n
gadget_translation.html\n
gadget_hr_translation.html\n
gadget_officejs_widget_listbox.html\n
gadget_erp5_editor_panel.html\n
gadget_erp5_editor_panel.js\n
......@@ -151,8 +149,8 @@ gadget_officejs_page_login.js\n
gadget_officejs_page_logout.js\n
gadget_officejs_page_sync.js\n
gadget_officejs_router.js\n
gadget_translation.js\n
gadget_translation_data.js\n
gadget_hr_translation.js\n
gadget_hr_translation_data.js\n
gadget_officejs_widget_listbox.js\n
erp5_launcher.js\n
erp5_launcher.html\n
......@@ -350,7 +348,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.54357.20081.48708</string> </value>
<value> <string>956.54751.3513.37683</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -368,7 +366,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1485185223.06</float>
<float>1486474400.78</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -114,6 +114,7 @@ gadget_officejs_calendar.html/renderjs.js\n
gadget_officejs_calendar.html/jquery.js\n
gadget_officejs_calendar.html/fullcalendar.min.js\n
gadget_officejs_calendar.html/fullcalendar.min.css\n
gadget_officejs_calendar.html/locale-all.js\n
\n
NETWORK:\n
*</string> </value>
......@@ -251,7 +252,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.35742.5405.23739</string> </value>
<value> <string>956.44329.14852.21316</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -269,7 +270,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1484044752.92</float>
<float>1486481468.06</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -12,6 +12,7 @@
<script src='jquery.js'></script>
<script src='moment.min.js'></script>
<script src='fullcalendar.min.js'></script>
<script src='locale-all.js'></script>
<script src="gadget_officejs_calendar.js" type="text/javascript"></script>
</head>
<body>
......
......@@ -234,7 +234,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.35778.19451.60962</string> </value>
<value> <string>957.10458.912.55483</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1484052072.72</float>
<float>1486464485.44</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -13,40 +13,56 @@
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("changeUrl", "changeUrl")
.declareAcquiredMethod("getSetting", "getSetting")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function (options) {
var gadget = this;
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'listDay,listWeek,month'
},
height: "auto",
aspectRatio: 0.7,
contentHeight: "auto",
// customize the button names,
// otherwise they'd all just say "list"
views: {
listDay: { buttonText: 'list day' },
listWeek: { buttonText: 'list week' }
},
eventClick: function(event) {
if (event.url) {
//xxx should return false to prevent url change
//https://fullcalendar.io/docs/mouse/eventClick/
gadget.changeUrl({jio_key: event.url});
return false;
}
},
defaultView: 'month',
navLinks: true, // can click day/week names to navigate views
editable: true,
eventLimit: true, // allow "more" link when too many events
events: options.events
});
var gadget = this,
data = {
fr: {
listDay: 'Jour',
listWeek:'Semaine'},
en: {
listDay: 'Day',
listWeek:'Week'
}
},
calendar_options = {
header: {
left: 'prev,next today',
center: 'title',
right: 'listDay,listWeek,month'
},
height: "auto",
aspectRatio: 0.7,
contentHeight: "auto",
// customize the button names,
// otherwise they'd all just say "list"
views: {
listDay: { buttonText: 'listDay' },
listWeek: { buttonText: 'listWeek' }
},
eventClick: function(event) {
if (event.url) {
//xxx should return false to prevent url change
//https://fullcalendar.io/docs/mouse/eventClick/
gadget.changeUrl({jio_key: event.url});
return false;
}
},
defaultView: 'month',
navLinks: true, // can click day/week names to navigate views
editable: true,
eventLimit: true, // allow "more" link when too many events
events: options.events
};
return gadget.getSetting('selected_language')
.push(function (lang) {
calendar_options.locale = lang;
calendar_options.buttonText = data[lang] || data.en;
$('#calendar').fullCalendar(calendar_options);
});
});
}(window, rJS, RSVP));
\ No newline at end of file
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.35891.33118.11844</string> </value>
<value> <string>957.10550.15266.24593</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -248,7 +248,7 @@
</tuple>
<state>
<tuple>
<float>1484054059.9</float>
<float>1486465349.95</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -227,7 +227,7 @@
} else {
ops.state = state.sync_state;
}
return template(ops);
return gadget.translateHtml(template(ops));
})
.push(function (html) {
var discussion_div;
......
......@@ -228,7 +228,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>supercedriclen</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.57543.33928.60006</string> </value>
<value> <string>956.58658.21925.32853</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1485352808.19</float>
<float>1486473658.84</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -113,7 +113,7 @@
select_options: select_options,
not_readonly: !state.readonly
};
return template(ops);
return gadget.translateHtml(template(ops));
})
.push(function (html) {
gadget.props.element.innerHTML = html;
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>supercedriclen</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.57517.36246.49305</string> </value>
<value> <string>956.58658.21925.32853</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -262,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>1485352429.99</float>
<float>1486473882.26</float>
<string>UTC</string>
</tuple>
</state>
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -108,7 +108,7 @@
} else {
ops.state = state.sync_state;
}
return template(ops);
return gadget.translateHtml(template(ops));
})
.push(function (html) {
var discussion_div;
......
......@@ -230,7 +230,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>supercedriclen</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.57502.32307.34304</string> </value>
<value> <string>956.58658.21925.32853</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -262,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>1485351571.43</float>
<float>1486473814.12</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -8,21 +8,20 @@
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<script src="handlebars.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_officejs_page_hr_front.js" type="text/javascript"></script>
</head>
<body>
<article class="ui-body-c document-access">
<script class="front-template" type="text/x-handlebars-template">
<article class="ui-body-c document-access">
<section class="ui-body-c ui-content-section">
<div class="ui-controlgroup ui-controlgroup-horizontal">
<div class="ui-grid-b ui-responsive">
<div class="ui-block-a">
<form class="synchro-form view-web-page-form">
<button type="submit" data-i18n="Send & Receive" data-theme="c" class=" ui-btn ui-btn-c ui-shadow ui-corner-all">Send & Receive</button>
<span>Last Synchronization Date:</span>
<span data-i18n='Last Synchronization Date:'>Last Synchronization Date:</span>
<span class="last_sync_date" style='color: red;'></span>
</form>
</div>
......@@ -33,7 +32,7 @@
<section class="">
<h3 class="ui-body-c">
<span class="ui-icon ui-icon-custom ui-icon-plus">&nbsp;</span>
Add
<span data-i18n='Add'>Add</span>
</h3>
</section>
<section class="ui-body-c ui-content-section">
......@@ -54,22 +53,26 @@
<section class="">
<h3 class="ui-body-c">
<span class="ui-icon ui-icon-custom ui-icon-exchange">&nbsp;</span>
Elements to Answer
<span data-i18n='Elements to Answer'>Elements to Answer</span>
</h3>
</section>
<section class="ui-body-c ui-content-section">
<div data-gadget-url="gadget_officejs_widget_listbox.html" data-gadget-scope="listbox-suspended"></div>
<div class="listbox-suspended"></div>
</section>
<section class="">
<h3 class="ui-body-c">
<span class="ui-icon ui-icon-custom ui-icon-exchange">&nbsp;</span>
Elements to Post
<span data-i18n='Elements to Post'>Elements to Post</span>
</h3>
</section>
<section class="ui-body-c ui-content-section">
<div data-gadget-url="gadget_officejs_widget_listbox.html" data-gadget-scope="listbox-draft"></div>
<div class="listbox-draft"></div>
</section>
</article>
</script>
</head>
<body>
</body>
</html>
\ No newline at end of file
......@@ -228,7 +228,7 @@
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>supercedriclen</string> </value>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.57534.1636.37307</string> </value>
<value> <string>957.10731.56466.35430</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1485352210.95</float>
<float>1486476459.13</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -2,8 +2,12 @@
/*jslint indent: 2, nomen: true, maxlen: 80*/
(function (window, RSVP, rJS) {
"use strict";
rJS(window)
var gadget_klass = rJS(window),
source = gadget_klass.__template_element
.querySelector(".front-template")
.innerHTML,
template = Handlebars.compile(source);
gadget_klass
.ready(function (g) {
g.props = {};
return g.getElement()
......@@ -31,6 +35,7 @@
});
})
.declareAcquiredMethod("translate", "translate")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod('getSetting', 'getSetting')
......@@ -60,6 +65,10 @@
var gadget = this;
return new RSVP.Queue()
.push(function () {
return gadget.translateHtml(template());
})
.push(function (html) {
gadget.props.element.innerHTML = html;
return gadget.getSetting('last_sync_date');
})
.push(function (result) {
......@@ -67,8 +76,8 @@
gadget.props.portal_type = "Expense Record";
gadget.props.document_title_plural = "Expense Requests";
return RSVP.all([
gadget.getDeclaredGadget("listbox-suspended"),
gadget.getDeclaredGadget("listbox-draft")
gadget.declareGadget("gadget_officejs_widget_listbox.html", {element: gadget.props.element.querySelector(".listbox-suspended")}),
gadget.declareGadget("gadget_officejs_widget_listbox.html", {element: gadget.props.element.querySelector(".listbox-draft")})
]);
})
.push(function (listbox_gadget_list) {
......
......@@ -270,7 +270,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.58972.41616.25838</string> </value>
<value> <string>957.10736.21518.26248</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -288,7 +288,7 @@
</tuple>
<state>
<tuple>
<float>1485438762.42</float>
<float>1486476551.71</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -44,6 +44,7 @@
<li><a href="#page=localisation" data-i18n="Map">Map</a></li>
<li><a href="#page=expense_report" data-i18n="Reports">Reports</a></li>
<!-- li><a href="#page=jio_configurator" data-i18n="Storage Configuration">Storage Configuration</a></li -->
<li><a href="#page=preference" data-i18n="Preferences">PReferences</a></li>
<li><a href="#page=sync&auto_repair=true" data-i18n="Synchronize">Synchronize</a></li>
</ul>
</div>
......
......@@ -269,7 +269,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.58658.21925.32853</string> </value>
<value> <string>957.9325.31917.28330</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -287,7 +287,7 @@
</tuple>
<state>
<tuple>
<float>1486391849.21</float>
<float>1486477634.11</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" />
<title>ERP5 Page Preferences</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_officejs_page_preference.js" type="text/javascript"></script>
</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
/*global window, rJS, RSVP */
/*jslint indent: 2, maxerr: 3 */
(function (window, rJS, RSVP) {
"use strict";
rJS(window)
/////////////////////////////////////////////////////////////////
// handle acquisition
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.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("reload", "reload")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.allowPublicAcquisition("notifyChange", function (argument_list) {
return;
})
.declareMethod("render", function () {
var gadget = this,
user = "Who are you?";
return gadget.updateHeader({
page_title: 'Preferences',
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) {
if (me !== undefined) {
return gadget.jio_allDocs({
query: 'portal_type: Person' ,
select_list: ['first_name', 'last_name'],
limit: [0, 1]
})
.push(function (result) {
if (result.data.rows.length) {
user = result.data.rows[0].value.first_name + " " + result.data.rows[0].value.last_name;
} else {
user = 'unknown';
}
});
}
})
.push(function () {
return RSVP.all([
gadget.getSetting("language_map"),
gadget.getSetting("selected_language"),
gadget.getSetting("default_selected_language"),
gadget.translate("User"),
gadget.translate("Language")
]);
})
.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.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.reload();
}
});
});
}(window, rJS, RSVP));
/*globals window*/
/*jslint indent: 2, nomen: true, maxlen: 80*/
(function (window) {
"use strict";
window.translation_data = {
"fr": {
"Preferences": "Préférences",
"Confirm": "Confirmer",
"Menu": "Menu",
"Discussion": "Discussion",
"Destination": "Destination",
"Mission": "Mission",
"Download XLSX": "Download XLSX",
"Add": "Ajouter",
"Mission Requests": "Demandes de Mission",
"Related Mission": "Mission Liée",
"Preview": "Aperçu",
"Type": "Type",
"Stop Date": "Date de fin",
"Total Price": "Montant",
"Send & Receive": "Envoyer & Recevoir\r\n",
"Map": "Map",
"Save": "Enregistrer",
"Description": "Description",
"Montant": "Montant",
"title": "title",
"header-submit": "header-submit",
"User": "Utilisateur",
"Elements to Answer": "Éléments à répondre",
"Last Synchronization Date:": "Dernière synchronisation Date:",
"Password": "Mot de passe",
"Log In": "Log In",
"End Date": "Date de fin",
"Input Date": "Date d'entrée",
"Elements to Post": "Éléments à publier",
"Expense Records": "Dossiers de dépenses",
"Language": "Langue",
"Sync Method": "Methode de Sync",
"Leaves": "Congé",
"Reports": "Rapports",
"Leave": "Congée",
"Report": "Rapport",
"Rapports": "Rapports",
"Longitude": "Longitude",
"Close": "Clôturer",
"Ready To Sync": "Prêt à synchroniser",
"Login": "Connexion",
"Expense": "Charges",
"Storage Configuration": "Storage Configuration",
"Calendar": "Calendrier",
"Comment": "Commentaire",
"Travels": "Voyages",
"Launch Synchronization": "Launch Synchronization",
"Do Not Sync": "Ne pas synchroniser",
"State": "État",
"Synchronize": "Synchroniser",
"Devise": "Devise",
"Photo": "Photo",
"Latitude": "Latitude",
"Leave Type": "Type de congé",
"Expenses": "Dépenses",
"Currency": "Devise",
"Mission Type": "Type de Mission",
"Leave Requests": "Demandes de Congé",
"Home": "Accueil",
"Start Date": "Date de début",
"Animation Center": "Animation Center"
},
"en": {
"Preferences": "Preferences",
"Confirm": "Confirm",
"Menu": "Menu",
"Discussion": "Discussion",
"Destination": "Destination",
"Mission": "Mission",
"Download XLSX": "Download XLSX",
"Add": "Add",
"Mission Requests": "Mission Requests",
"Related Mission": "Related Mission",
"Preview": "Preview",
"Type": "Type",
"Stop Date": "Stop Date",
"Total Price": "Total Price",
"Send & Receive": "Send & Receive",
"Map": "Map",
"Save": "Save",
"Description": "Description",
"Montant": "Montant",
"title": "title",
"header-submit": "header-submit",
"User": "User",
"Elements to Answer": "Elements to Answer",
"Last Synchronization Date:": "Last Synchronization Date:",
"Password": "Password",
"Log In": "Log In",
"End Date": "End Date",
"Input Date": "Input Date",
"Elements to Post": "Elements to Post",
"Expense Records": "Expense Records",
"Language": "Language",
"Sync Method": "Sync Method",
"Leaves": "Leaves",
"Reports": "Reports",
"Leave": "Leave",
"Report": "Report",
"Rapports": "Rapports",
"Longitude": "Longitude",
"Close": "Close",
"Ready To Sync": "Ready To Sync",
"Login": "Login",
"Expense": "Expense",
"Storage Configuration": "Storage Configuration",
"Calendar": "Calendar",
"Comment": "Comment",
"Travels": "Travels",
"Launch Synchronization": "Launch Synchronization",
"Do Not Sync": "Do Not Sync",
"State": "State",
"Synchronize": "Synchronize",
"Devise": "Devise",
"Photo": "Photo",
"Latitude": "Latitude",
"Leave Type": "Leave Type",
"Expenses": "Expenses",
"Currency": "Currency",
"Mission Type": "Mission Type",
"Leave Requests": "Leave Requests",
"Home": "Home",
"Start Date": "Start Date",
"Animation Center": "Animation Center"
}
};
}(window));
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<!-- data-i18n='Description'
data-i18n='Type'
data-i18n='Montant'
data-i18n='Devise'
data-i18n='Input Date'
data-i18n='Expense Records'
data-i18n='Add'
data-i18n='Menu'
data-i18n='Travels'
data-i18n='Leave'
data-i18n='Calendar'
data-i18n='Map'
data-i18n='Rapports'
data-i18n='Preferences'
data-i18n='Synchronize'
data-i18n='Mission Type'
data-i18n='Destination'
data-i18n='End Date'
data-i18n='Animation Center'
data-i18n='Start Date'
data-i18n='Comment'
data-i18n='Discussion'
data-i18n='Language'
data-i18n='User'
data-i18n='Leave Requests'
data-i18n='Expense Records'
data-i18n='Mission Requests'
data-i18n='Related Mission'
data-i18n='Report
data-i18n='Sync Method'
data-i18n='Ready To Sync'
data-i18n='Do Not Sync'
data-i18n='Expense'
data-i18n='Leave'
data-i18n='Mission'
data-i18n='Elements to Answer'
data-i18n='Elements to Post'
-->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>Translation Gadget</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_hr_translation_data.js" type="text/javascript"></script>
<script src="gadget_hr_translation.js" type="text/javascript"></script>
</head>
<body>
</body>
</html>
/*global document, window, rJS, translation_data, RSVP */
/*jslint nomen: true, indent: 2 */
(function (document, window, rJS, translation_data, RSVP) {
"use strict";
function translate(string, gadget) {
if (translation_data[gadget.state.language]) {
return translation_data[gadget.state.language][string] || string;
}
return 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;
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(";");
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);
// 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], 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], gadget);
}
break;
}
}
}
}
// 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, RSVP));
......@@ -379,7 +379,7 @@
</item>
<item>
<key> <string>configuration_translation_gadget_url</string> </key>
<value> <string>gadget_translation.html</string> </value>
<value> <string>gadget_hr_translation.html</string> </value>
</item>
<item>
<key> <string>configuration_view_action_category</string> </key>
......@@ -565,7 +565,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>956.57506.23984.60142</string> </value>
<value> <string>957.10753.62758.1638</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -583,7 +583,7 @@
</tuple>
<state>
<tuple>
<float>1485350678.17</float>
<float>1486477789.33</float>
<string>UTC</string>
</tuple>
</state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment