~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/lib/OpenLayers/Lang.js

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
 
2
 * license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
 
3
 * full text of the license. */
 
4
 
 
5
 
 
6
/**
 
7
 * Namespace: OpenLayers.Lang
 
8
 * Internationalization namespace.  Contains dictionaries in various languages
 
9
 *     and methods to set and get the current language.
 
10
 */
 
11
OpenLayers.Lang = {
 
12
    
 
13
    /** 
 
14
     * Property: code
 
15
     * {String}  Current language code to use in OpenLayers.  Use the
 
16
     *     <setCode> method to set this value and the <getCode> method to
 
17
     *     retrieve it.
 
18
     */
 
19
    code: null,
 
20
 
 
21
    /** 
 
22
     * APIProperty: defaultCode
 
23
     * {String} Default language to use when a specific language can't be
 
24
     *     found.  Default is "en".
 
25
     */
 
26
    defaultCode: "en",
 
27
        
 
28
    /**
 
29
     * APIFunction: getCode
 
30
     * Get the current language code.
 
31
     *
 
32
     * Returns:
 
33
     * The current language code.
 
34
     */
 
35
    getCode: function() {
 
36
        if(!OpenLayers.Lang.code) {
 
37
            OpenLayers.Lang.setCode();
 
38
        }
 
39
        return OpenLayers.Lang.code;
 
40
    },
 
41
    
 
42
    /**
 
43
     * APIFunction: setCode
 
44
     * Set the language code for string translation.  This code is used by
 
45
     *     the <OpenLayers.Lang.translate> method.
 
46
     *
 
47
     * Parameters-
 
48
     * code - {String} These codes follow the IETF recommendations at
 
49
     *     http://www.ietf.org/rfc/rfc3066.txt.  If no value is set, the
 
50
     *     browser's language setting will be tested.  If no <OpenLayers.Lang>
 
51
     *     dictionary exists for the code, the <OpenLayers.String.defaultLang>
 
52
     *     will be used.
 
53
     */
 
54
    setCode: function(code) {
 
55
        var lang;
 
56
        if(!code) {
 
57
            code = (OpenLayers.Util.getBrowserName() == "msie") ?
 
58
                navigator.userLanguage : navigator.language;
 
59
        }
 
60
        var parts = code.split('-');
 
61
        parts[0] = parts[0].toLowerCase();
 
62
        if(typeof OpenLayers.Lang[parts[0]] == "object") {
 
63
            lang = parts[0];
 
64
        }
 
65
 
 
66
        // check for regional extensions
 
67
        if(parts[1]) {
 
68
            var testLang = parts[0] + '-' + parts[1].toUpperCase();
 
69
            if(typeof OpenLayers.Lang[testLang] == "object") {
 
70
                lang = testLang;
 
71
            }
 
72
        }
 
73
        if(!lang) {
 
74
            OpenLayers.Console.warn(
 
75
                'Failed to find OpenLayers.Lang.' + parts.join("-") +
 
76
                ' dictionary, falling back to default language'
 
77
            );
 
78
            lang = OpenLayers.Lang.defaultCode;
 
79
        }
 
80
        
 
81
        OpenLayers.Lang.code = lang;
 
82
    },
 
83
 
 
84
    /**
 
85
     * APIMethod: translate
 
86
     * Looks up a key from a dictionary based on the current language string.
 
87
     *     The value of <getCode> will be used to determine the appropriate
 
88
     *     dictionary.  Dictionaries are stored in <OpenLayers.Lang>.
 
89
     *
 
90
     * Parameters:
 
91
     * key - {String} The key for an i18n string value in the dictionary.
 
92
     * context - {Object} Optional context to be used with
 
93
     *     <OpenLayers.String.format>.
 
94
     * 
 
95
     * Returns:
 
96
     * {String} A internationalized string.
 
97
     */
 
98
    translate: function(key, context) {
 
99
        var dictionary = OpenLayers.Lang[OpenLayers.Lang.getCode()];
 
100
        var message = dictionary[key];
 
101
        if(!message) {
 
102
            // Message not found, fall back to message key
 
103
            message = key;
 
104
        }
 
105
        if(context) {
 
106
            message = OpenLayers.String.format(message, context);
 
107
        }
 
108
        return message;
 
109
    }
 
110
    
 
111
};
 
112
 
 
113
 
 
114
/**
 
115
 * APIMethod: OpenLayers.i18n
 
116
 * Alias for <OpenLayers.Lang.translate>.  Looks up a key from a dictionary
 
117
 *     based on the current language string. The value of
 
118
 *     <OpenLayers.Lang.getCode> will be used to determine the appropriate
 
119
 *     dictionary.  Dictionaries are stored in <OpenLayers.Lang>.
 
120
 *
 
121
 * Parameters:
 
122
 * key - {String} The key for an i18n string value in the dictionary.
 
123
 * context - {Object} Optional context to be used with
 
124
 *     <OpenLayers.String.format>.
 
125
 * 
 
126
 * Returns:
 
127
 * {String} A internationalized string.
 
128
 */
 
129
OpenLayers.i18n = OpenLayers.Lang.translate;
 
 
b'\\ No newline at end of file'