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