2feb7757525c597f50dc34730e7e051e31c5e2ce.svn-base 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. if (!dojo._hasResource["tests.i18n"]) { // _hasResource checks added by build.
  2. // Do not use _hasResource directly in
  3. // your code.
  4. dojo._hasResource["tests.i18n"] = true;
  5. dojo.provide("tests.i18n");
  6. dojo.require("dojo.i18n");
  7. (function() {
  8. var setUp = function(locale) {
  9. return function() {
  10. dojo.requireLocalization("tests", "salutations", locale, "");
  11. }
  12. }
  13. var getTest = function(value, locale) {
  14. return function() {
  15. doh.assertEqual(value, dojo.i18n.getLocalization("tests",
  16. "salutations", locale).hello);
  17. }
  18. }
  19. var getFixture = function(locale, value) {
  20. return {
  21. name : "salutations-" + locale,
  22. setUp : setUp(locale),
  23. runTest : getTest(value, locale)
  24. };
  25. }
  26. var testSet = [
  27. /*
  28. * needs dojo.string, // This doesn't actually test anything, it
  29. * just gives an impressive list of translated output to the
  30. * console // See the 'salutations' test for something
  31. * verifyable function fun(t){ var salutations_default =
  32. * dojo.i18n.getLocalization("tests", "salutations");
  33. * console.debug("In the local language:
  34. * "+salutations_default.hello);
  35. *
  36. * var salutations_en = dojo.i18n.getLocalization("tests",
  37. * "salutations", "en");
  38. *
  39. * for (i in tests.nls.salutations) { var loc = i.replace('_',
  40. * '-'); var salutations = dojo.i18n.getLocalization("tests",
  41. * "salutations", loc); var language_as_english =
  42. * salutations_en[loc]; var language_as_native =
  43. * salutations[loc]; var hello_dojo =
  44. * dojo.string.substitute(salutations.hello_dojo, salutations);
  45. * if (!dojo.i18n.isLeftToRight(loc)) { var RLE = "\u202b"; var
  46. * PDF = "\u202c"; hello_dojo = RLE + hello_dojo + PDF; }
  47. * hello_dojo += "\t[" + loc + "]";
  48. * if(language_as_english){hello_dojo += " " +
  49. * language_as_english;} if(language_as_native){hello_dojo += " (" +
  50. * language_as_native + ")";} console.debug(hello_dojo); }
  51. *
  52. * t.assertTrue(true); },
  53. */
  54. // Test on-the-fly loading of localized string bundles from
  55. // different locales, and
  56. // the expected inheritance behavior
  57. // Locale which overrides root translation
  58. getFixture("de", "Hallo"),
  59. // Locale which does not override root translation
  60. getFixture("en", "Hello"),
  61. // Locale which overrides its parent
  62. getFixture("en-au", "G'day"),
  63. // Locale which does not override its parent
  64. getFixture("en-us", "Hello"),
  65. // Locale which overrides its parent
  66. getFixture("en-us-texas", "Howdy"),
  67. // 3rd level variant which overrides its parent
  68. getFixture("en-us-new_york", "Hello"),
  69. // Locale which overrides its grandparent
  70. getFixture("en-us-new_york-brooklyn", "Yo"),
  71. // Locale which does not have any translation available
  72. getFixture("xx", "Hello"),
  73. // A double-byte string. Everything should be read in as UTF-8
  74. // and treated as unicode within Javascript.
  75. getFixture("zh-cn", "\u4f60\u597d")];
  76. testSet[testSet.length - 1].tearDown = function() {
  77. // Clean up bundles that should not exist if the test is re-run.
  78. delete tests.nls.salutations;
  79. };
  80. tests.register("tests.i18n", testSet);
  81. })();
  82. }