[open-ils-commits] r15249 - trunk/Open-ILS/web/js/dojo/openils (miker)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Dec 30 12:09:25 EST 2009
Author: miker
Date: 2009-12-30 12:09:22 -0500 (Wed, 30 Dec 2009)
New Revision: 15249
Modified:
trunk/Open-ILS/web/js/dojo/openils/I18N.js
Log:
simple (minded?) dojo NLS page translator
Modified: trunk/Open-ILS/web/js/dojo/openils/I18N.js
===================================================================
--- trunk/Open-ILS/web/js/dojo/openils/I18N.js 2009-12-30 16:33:28 UTC (rev 15248)
+++ trunk/Open-ILS/web/js/dojo/openils/I18N.js 2009-12-30 17:09:22 UTC (rev 15249)
@@ -56,6 +56,48 @@
return obj_list;
}
+ openils.I18N.translatePage = function () {
+
+ dojo.require('dojo.query');
+
+ var elements = dojo.query('*[i18n]');
+ if (!elements.length) return null;
+
+ dojo.forEach(elements, function(e){
+
+ var what = e.getAttribute('i18n');
+ var parts = what.match(/^(.+)\.([^.]+)$/);
+ var app = parts[0]; var bundle = parts[1];
+ if (!app || !bundle) return null;
+
+ if (!openils.I18N.translatePage.NLSCache[app][bundle]) {
+ dojo.requireLocalization(app,bundle);
+ openils.I18N.translatePage.NLSCache[app][bundle] = dojo.i18n.getLocalization(app,bundle);
+
+ if (!openils.I18N.translatePage.NLSCache[app][bundle]) return null;
+ }
+
+ dojo.require('dojo.string');
+
+ var template = e.innerHTML;
+ var finalHTML = dojo.string.substitute( template, openils.I18N.translatePage.NLSCache[app][bundle] );
+
+ if (template == finalHTML) { // no subsititution occurred
+ dojo.require("dojox.jsonPath");
+ var transString = e.getAttribute('string') || template;
+ finalHTML = dojox.jsonPath.query(
+ openils.I18N.translatePage.NLSCache[app][bundle],
+ '$.'+transString,
+ {evalType:"RESULT"}
+ );
+ }
+
+ if (finalHTML) e.innerHTML = finalHTML;
+
+ });
+ }
+ openils.I18N.translatePage.NLSCache = {}; // stash this on the function .. WHEEEE
+
}
More information about the open-ils-commits
mailing list