1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title id="titleId"></title> <script type="text/javascript"> var djConfig = { modulePaths: {sampleApp: "../../sample/application"}, parseOnLoad: true, locale:'en-us'}; </script> <script type="text/javascript" src="dojoBase/dojo/dojo.js"></script> <script type="text/javascript"> dojo.require("dojo.string"); dojo.requireLocalization("sampleApp", "greeting"); function init() { var nlsStrings = dojo.i18n.getLocalization("sampleApp","greeting"); var greetingString = nlsStrings.GREETING; var personString = nlsStrings.PERSON; var greetingTemplate = nlsStrings.GREETING_SENTENCE; var finalGreeting = dojo.string.substitute(greetingTemplate, {greeting:greetingString, personTitle:personString}); dojo.byId("helloDiv").innerHTML = finalGreeting; dojo.byId("titleId").text = finalGreeting; } dojo.addOnLoad(init); </script> </head> <body> <div id="helloDiv"></div> </body> </html> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | dojo.require("dojo.i18n"); dojo.require("dojo.string"); dojo.requireLocalization("sampleApp", "greeting"); dojo.provide("sampleApp.widget.NlsMixin"); dojo.declare("sampleApp.widget.NlsMixin",null, { data: {__initialized: false}, constructor: function() { if(!this.data.__initialized) { this.data.nlsStrings = dojo.i18n.getLocalization("sampleApp", "greeting"); this.data.__initialized = true; } }, /** * * @param {String} key - the name of the key in the translation file * @param {Object or Array?} substitutes - in cases where the translated * string is a template for string substitution, this parameter * holds the values to be used by dojo.string.substitute on that * template */ getString: function(/*String*/ key, /*Object or Array?*/ substitutes) { var str = this.data.nlsStrings[key]; return (substituteValues)? dojo.string.substitute(str,substitutes): str; }, postMixInProperties: function() { this.inherited('postMixInProperties', arguments); this.initializeStrings(); }, initializeStrings: function(){} } ); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | dojo.provide("sampleApp.widget.Greeting"); dojo.require("dijit._Widget"); dojo.require("dijit._Templated"); dojo.require("sampleApp.widget.NlsMixin"); dojo.declare("sampleApp.widget.Greeting", [dijit._Widget,dijit._Templated ,sampleApp.widget.NlsMixin], { templateString: "<div>${greeting}</div>", greeting:””, initializeStrings: function() { var greetingString = this.getString("GREETING"); var personString = this.getString("PERSON"); this.greeting = this.getString("GREETING_SENTENCE", {greeting:greetingString, personTitle:personString}); } } ); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <script type="text/javascript"> var djConfig = { isDebug: false, modulePaths: { sampleApp: "../../sample/application" }, parseOnLoad: true, locale:'en-au' }; </script> <script type="text/javascript" src="dojoBase/dojo/dojo.js.uncompressed.js"></script> <script type="text/javascript"> dojo.require("sampleApp.widget.Greeting"); </script> </head> <body> <div dojoType="sampleApp.widget.Greeting" id="helloDiv"></div> </body> </html> |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |