1 2 3 4 5 6 7 8 9 10 11 12 13 | <script> function initMessages(){ $.when( $.get( "/messages.json" ), $.get( "/cldr/supplemental/likelySubtags.json" ) ).done(function(messages, likelySubtags) { // Load all the required CLDR data Globalize.load(likelySubtags[0]); Globalize.loadMessages(messages[0]); $('#enHello')[0].value = Globalize("en").messageFormatter( "greetings/hello" )("World"); $('#ptHello')[0].value = Globalize("pt").messageFormatter( "greetings/hello" )("World"); }); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | { "en": { "greetings": { "hello": "hello, {0}", "bye": "bye" } }, "pt": { "greetings": { "hello": "Ola, {0}", "bye": "Tchau" } } } |
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 46 47 48 | <script> var globalize; var locale="en"; function displaynew(){ $.when( $.get( "/cldr/main/" + locale + "/ca-gregorian.json"), $.get( "/cldr/main/" + locale + "/timeZoneNames.json"), $.get( "/cldr/main/" + locale + "/numbers.json"), $.get( "/cldr/main/" + locale + "/currencies.json"), $.get( "/cldr/supplemental/timeData.json" ), $.get( "/cldr/supplemental/weekData.json" ), $.get( "/cldr/supplemental/numberingSystems.json" ), $.get( "/cldr/supplemental/currencyData.json" ), $.get( "/cldr/supplemental/likelySubtags.json"), $.get( "/cldr/supplemental/plurals.json" ), $.get( "/cldr/supplemental/ordinals.json" ) ).done(function(result1,result2,result3,result4,result5, result6, result7, result8, result9, result10, result11) { /*载入所有函数库*/ Globalize.load(result1 [0]); …… globalize = Globalize(locale); var plural=globalize.pluralGenerator(); var pluralordinal=globalize.pluralGenerator({ type: "ordinal" }); var numFormatter = Globalize(locale).numberFormatter({ maximumFractionDigits: 5} ); var dateFormatter = Globalize(locale).dateFormatter({datetime: "medium"}); var currencyFormatter=Globalize(locale).currencyFormatter("CNY",{style:"name"}); var content = "<p>"; content = content + "***** Number format *****<br>"; content = content + "Number(1234.5678): "+numFormatter(1234.5678) +"<p>"; content = content + "***** Currency format *****<br>"; content = content + "Currency(1234.5678): "+currencyFormatter(1234.5678) +"<p>"; content = content + "***** Time format *****<br>"; content = content + "Current Time: "+dateFormatter(new Date()) +"<p>"; content = content + "***** Plural format *****<br>"; content = content + "<table border='1' width='400'>"; content = content + "<tr><td>Number</td><td>Cardinals</td><td>Ordinal</td></tr>"; /*传入不同数值, 观察在不同语言下复数的格式*/ content = content + "<tr><td>3.5</td><td>" + plural(3.5) + "</td><td>"; …… content = content + pluralordinal(3.5)+ "</td></tr>"; content = content + "<tr><td>0</td><td>" + plural(0) + "</td><td>"; content = content + "</p>" $("div#test").empty(); $("div#test").append(content); }); } |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |