3
<script src="../lib/OpenLayers.js"></script>
4
<script src="../lib/OpenLayers/Lang/en-CA.js" type="text/javascript"></script>
5
<script src="../lib/OpenLayers/Lang/fr.js" type="text/javascript"></script>
6
<script type="text/javascript">
8
function test_setCode(t) {
10
OpenLayers.Lang.code = null;
12
// test with no argument - this could result in the default or the
13
// browser language if a dictionary exists
14
OpenLayers.Lang.setCode();
15
t.ok(OpenLayers.Lang.code != null,
16
"code set when no argument is sent");
20
var code = primary + "-" + subtag;
21
OpenLayers.Lang[code] = {};
23
// test code for dictionary that exists
24
OpenLayers.Lang.setCode(code);
25
t.eq(OpenLayers.Lang.code, code,
26
"code properly set for existing dictionary");
28
// test code for dictionary that doesn't exist
29
OpenLayers.Lang.setCode(primary + "-YY");
30
t.eq(OpenLayers.Lang.code, OpenLayers.Lang.defaultCode,
31
"code set to default for non-existing dictionary");
33
// test code for existing primary but missing subtag
34
OpenLayers.Lang[primary] = {};
35
OpenLayers.Lang.setCode(primary + "-YY");
36
t.eq(OpenLayers.Lang.code, primary,
37
"code set to primary when subtag dictionary is missing");
40
delete OpenLayers.Lang[code];
41
delete OpenLayers.Lang[primary];
42
OpenLayers.Lang.code = null;
45
function test_getCode(t) {
47
OpenLayers.Lang.code = null;
49
// test that a non-null value is retrieved - could be browser language
51
var code = OpenLayers.Lang.getCode();
52
t.ok(code != null, "returns a non-null code");
53
t.ok(OpenLayers.Lang.code != null, "sets the code to a non-null value");
55
// test that the code is returned if non-null
56
OpenLayers.Lang.code = "foo";
57
t.eq(OpenLayers.Lang.getCode(), "foo", "returns the code if non-null");
60
OpenLayers.Lang.code = null;
63
function test_i18n(t) {
65
t.ok(OpenLayers.i18n === OpenLayers.Lang.translate,
66
"i18n is an alias for OpenLayers.Lang.translate");
69
function test_translate(t) {
70
var keys = ['test1', 'test3', 'noKey'];
71
var codes = ['en', 'en-CA', 'fr', 'fr-CA', 'sw'];
73
'en': {'overlays':'Overlays',
74
'unhandledRequest':'Unhandled request return foo',
76
'en-CA': {'overlays':'Overlays',
77
'unhandledRequest':'Unhandled request return foo',
79
'fr': {'overlays':'Calques',
80
'unhandledRequest':'Requête non gérée, retournant foo',
82
'fr-CA': {'overlays':'Calques', //this should result in 'fr'
83
'unhandledRequest':'Requête non gérée, retournant foo',
85
'sw': {'overlays':'Overlays', //this should result in 'en'
86
'unhandledRequest':'Unhandled request return foo',
90
t.plan(keys.length*codes.length);
92
for (var i=0; i<codes.length; ++i) {
94
OpenLayers.Lang.setCode(code);
95
t.eq(OpenLayers.Lang.translate('overlays'), result[code]['overlays'], "simple key lookup in "+code);
96
t.eq(OpenLayers.Lang.translate('unhandledRequest',{'statusText':'foo'}),
97
result[code]['unhandledRequest'], "lookup with argument substitution in "+code);
98
t.eq(OpenLayers.Lang.translate('noKey'), result[code]['noKey'], "invalid key returns the key in "+code);