~zack-krejci/healthscapes-dsp/trunk

« back to all changes in this revision

Viewing changes to static/scripts/OpenLayers/tests/Lang.html

  • Committer: Zack
  • Date: 2011-02-28 21:37:27 UTC
  • Revision ID: zack@zack-laptop-20110228213727-tqig2kgx9vz0uhq9
Updated pages

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html>
 
2
<head>
 
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">
 
7
    
 
8
    function test_setCode(t) {
 
9
        t.plan(4);
 
10
        OpenLayers.Lang.code = null;
 
11
        
 
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");
 
17
        
 
18
        var primary = "xx";
 
19
        var subtag = "XX";
 
20
        var code = primary + "-" + subtag;
 
21
        OpenLayers.Lang[code] = {};
 
22
        
 
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");
 
27
        
 
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");
 
32
        
 
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");
 
38
        
 
39
        // clean up
 
40
        delete OpenLayers.Lang[code];
 
41
        delete OpenLayers.Lang[primary];
 
42
        OpenLayers.Lang.code = null;
 
43
    }
 
44
    
 
45
    function test_getCode(t) {
 
46
        t.plan(3);
 
47
        OpenLayers.Lang.code = null;
 
48
        
 
49
        // test that a non-null value is retrieved - could be browser language
 
50
        // or defaultCode
 
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");
 
54
        
 
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");
 
58
        
 
59
        // clean up
 
60
        OpenLayers.Lang.code = null;        
 
61
    }
 
62
    
 
63
    function test_i18n(t) {
 
64
        t.plan(1);        
 
65
        t.ok(OpenLayers.i18n === OpenLayers.Lang.translate,
 
66
             "i18n is an alias for OpenLayers.Lang.translate");
 
67
    }
 
68
    
 
69
    function test_translate(t) {
 
70
        var keys = ['test1', 'test3', 'noKey'];
 
71
        var codes = ['en', 'en-CA', 'fr', 'fr-CA', 'sw'];
 
72
        var result = {
 
73
            'en': {'overlays':'Overlays', 
 
74
                   'unhandledRequest':'Unhandled request return foo', 
 
75
                   'noKey':'noKey'},
 
76
            'en-CA': {'overlays':'Overlays',
 
77
                   'unhandledRequest':'Unhandled request return foo', 
 
78
                      'noKey':'noKey'},
 
79
            'fr': {'overlays':'Calques', 
 
80
                   'unhandledRequest':'Requête non gérée, retournant foo',
 
81
                  'noKey':'noKey'},
 
82
            'fr-CA': {'overlays':'Calques', //this should result in 'fr'
 
83
                   'unhandledRequest':'Requête non gérée, retournant foo',
 
84
                  'noKey':'noKey'},
 
85
            'sw': {'overlays':'Overlays', //this should result in 'en'
 
86
                   'unhandledRequest':'Unhandled request return foo', 
 
87
                  'noKey':'noKey'}
 
88
        };
 
89
        
 
90
        t.plan(keys.length*codes.length);
 
91
 
 
92
        for (var i=0; i<codes.length; ++i) {
 
93
            var code = codes[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);
 
99
        }
 
100
    }
 
101
 
 
102
  </script>
 
103
</head>
 
104
<body>
 
105
</body>
 
106
</html>