Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 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");
4
 
5
dojo.require("dojo.i18n");
6
 
7
(function(){
8
	var setUp = function(locale){
9
		return function(){
10
			dojo.requireLocalization("tests","salutations",locale, "");
11
		}
12
	}
13
 
14
	var getTest = function(value, locale){
15
		return function(){
16
			doh.assertEqual(value, dojo.i18n.getLocalization("tests", "salutations", locale).hello);
17
		}
18
	}
19
 
20
	var getFixture = function(locale, value){
21
		return {
22
			name: "salutations-"+locale,
23
			setUp: setUp(locale),
24
			runTest: getTest(value, locale)
25
		};
26
	}
27
 
28
	var testSet = [
29
	/* needs dojo.string,
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
32
		function fun(t){
33
			var salutations_default = dojo.i18n.getLocalization("tests", "salutations");
34
			console.debug("In the local language: "+salutations_default.hello);
35
 
36
			var salutations_en = dojo.i18n.getLocalization("tests", "salutations", "en");
37
 
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)) {
45
					var RLE = "\u202b";
46
					var PDF = "\u202c";
47
					hello_dojo = RLE + hello_dojo + PDF;
48
				}
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);
53
			}
54
 
55
			t.assertTrue(true);
56
		},
57
	*/
58
 
59
		// Test on-the-fly loading of localized string bundles from different locales, and
60
		// the expected inheritance behavior
61
 
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")
80
	];
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;
84
	};
85
	tests.register("tests.i18n", testSet);
86
})();
87
 
88
}