i18n.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  2. "http://www.w3.org/TR/html4/strict.dtd">
  3. <html>
  4. <head>
  5. <title>Dijit I18N Demo</title>
  6. <script>
  7. var djConfig = {parseOnLoad: true, isDebug: true},
  8. locale,
  9. lang,
  10. bidi;
  11. // read in HREF arguments
  12. if(window.location.href.indexOf("?") > -1){
  13. var str = window.location.href.substr(window.location.href.indexOf("?")+1);
  14. var ary = str.split(/&/);
  15. for(var i=0; i<ary.length; i++){
  16. var split = ary[i].split(/=/),
  17. key = split[0],
  18. value = split[1];
  19. switch(key){
  20. case "locale":
  21. djConfig.locale = locale = value;
  22. lang = locale.replace(/-.*/, "");
  23. break;
  24. case "dir":
  25. document.getElementsByTagName("html")[0].dir = value;
  26. bidi = value;
  27. break;
  28. }
  29. }
  30. }
  31. </script>
  32. <style type="text/css">
  33. @import "../../dojo/resources/dojo.css";
  34. @import "../themes/tundra/tundra.css";
  35. @import "../themes/tundra/tundra_rtl.css";
  36. @import "../tests/css/dijitTests.css";
  37. @import "i18n/flags.css";
  38. </style>
  39. <script type="text/javascript" src="../../dojo/dojo.js"></script>
  40. <script language="JavaScript" type="text/javascript">
  41. dojo.require("dojo.data.ItemFileReadStore");
  42. dojo.require("dijit.Tree");
  43. dojo.require("dijit._Calendar");
  44. dojo.require("dijit.form.DateTextBox");
  45. dojo.require("dijit.form.CurrencyTextBox");
  46. dojo.require("dijit.form.NumberSpinner");
  47. dojo.require("dijit.form.ComboBox");
  48. dojo.require("dijit.Menu");
  49. dojo.require("dojo.parser");
  50. dojo.addOnLoad(function(){
  51. dojo.byId("locale").innerHTML = locale || "default";
  52. dojo.byId("dir").innerHTML = bidi || "default";
  53. });
  54. </script>
  55. </head>
  56. <body class="tundra">
  57. <div dojoType="dojo.data.ItemFileReadStore" jsId="store"
  58. url="i18n/data.json"></div>
  59. <h1 class="testTitle" dir="ltr">Dijit I18N Demo (locale=<span id="locale"></span> dir=<span id="dir"></span>)</h1>
  60. <table width="100%">
  61. <tr>
  62. <td width="30%" style="vertical-align: top;">
  63. <div dojoType="dijit.Tree" id="mytree" store="store" label="Continents" childrenAttr="languages">
  64. <!-- Override all the data access functions to work from the I18N data store -->
  65. <script type="dojo/method" event="getItemChildren" args="item, onComplete">
  66. switch(item ? store.getValue(item, "type") : "top"){
  67. case "top":
  68. return store.fetch({query: {type:'continent'}, onComplete: onComplete});
  69. case "continent":
  70. return store.fetch({query: {continent: store.getValue(item, "iso")}, onComplete: onComplete});
  71. case "country":
  72. return dijit.Tree.prototype.getItemChildren.apply(this, arguments);
  73. }
  74. </script>
  75. <script type="dojo/method" event="mayHaveChildren" args="item">
  76. if(!item){ return true; } // top level
  77. var type = store.getValue(item, "type");
  78. return (type == "continent" || type == "country");
  79. </script>
  80. <!-- override functions for display of each node -->
  81. <script type="dojo/method" event="getIconClass" args="item">
  82. var icon =
  83. (item && store.getValue(item, "type") == "country") ?
  84. ("countryIcon country" + store.getValue(item, "iso") + "Icon") :
  85. null;
  86. return icon;
  87. </script>
  88. <script type="dojo/method" event="getLabel" args="item">
  89. var localizedName = lang && store.getValue(item, lang);
  90. return localizedName || (store.getLabel(item) + " \u202b" + "(" + store.getIdentity(item) + ")\u202c");
  91. </script>
  92. <!-- clicking a node refreshes the page with new locale setting -->
  93. <script type="dojo/method" event="onClick" args="item, node">
  94. var type = store.getValue(item, "type");
  95. if(type == "language"){
  96. var lang = store.getIdentity(item),
  97. locale = lang + "-" + store.getIdentity(node.getParent().item).toLowerCase(),
  98. dir = /ar|fa|he|ps|ur|yi/i.test(lang) ? "rtl" : "ltr";
  99. window.location.href = window.location.href.replace(/\?.*/, "") + "?locale=" + locale + "&dir=" + dir;
  100. }else{
  101. alert("Please click a language, not a country or continent.");
  102. }
  103. </script>
  104. </div>
  105. </td>
  106. <td style="vertical-align: top;">
  107. <p dir="ltr">
  108. Use the tree to select a language or a language/country combo; the page will reload
  109. in the specified locale. Note that tree is also rerendered using the specified language for top level tree items.
  110. Arabic and Hebrew display right-to-left so be sure to try those.
  111. </p>
  112. <input dojoType="dijit._Calendar"/>
  113. <p>Some form controls:</p>
  114. <label for="date">Date:</label>
  115. <input id="date" dojoType="dijit.form.DateTextBox" value="2006-07-04"/>
  116. <br/>
  117. <label for="spinner">Number spinner:</label>
  118. <input id="spinner" dojoType="dijit.form.NumberSpinner" value="123456789"/>
  119. <br/>
  120. <label for="currency">Currency:</label>
  121. <input id="currency" type="text" name="income1" value="54775.53"
  122. dojoType="dijit.form.CurrencyTextBox"
  123. required="true"
  124. constraints="{fractional:true}"
  125. currency="USD"/>
  126. <br/>
  127. <label for="combo1">Simple Combo:</label>
  128. <select id="combo1" dojoType="dijit.form.ComboBox">
  129. <option>option #1</option>
  130. <option>option #2</option>
  131. <option>option #3</option>
  132. </select>
  133. <br/>
  134. <label for="combo2">Combo on languages and countries:</label>
  135. <input id="combo2" dojoType="dijit.form.ComboBox"
  136. value=""
  137. store="store"
  138. searchAttr="name"
  139. name="anything"/>
  140. </td>
  141. </tr>
  142. </table>
  143. </body>
  144. </html>