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. */
7
* Namespace: OpenLayers.Lang
8
* Internationalization namespace. Contains dictionaries in various languages
9
* and methods to set and get the current language.
15
* {String} Current language code to use in OpenLayers. Use the
16
* <setCode> method to set this value and the <getCode> method to
22
* APIProperty: defaultCode
23
* {String} Default language to use when a specific language can't be
24
* found. Default is "en".
29
* APIFunction: getCode
30
* Get the current language code.
33
* The current language code.
36
if(!OpenLayers.Lang.code) {
37
OpenLayers.Lang.setCode();
39
return OpenLayers.Lang.code;
43
* APIFunction: setCode
44
* Set the language code for string translation. This code is used by
45
* the <OpenLayers.Lang.translate> method.
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>
54
setCode: function(code) {
57
code = (OpenLayers.Util.getBrowserName() == "msie") ?
58
navigator.userLanguage : navigator.language;
60
var parts = code.split('-');
61
parts[0] = parts[0].toLowerCase();
62
if(typeof OpenLayers.Lang[parts[0]] == "object") {
66
// check for regional extensions
68
var testLang = parts[0] + '-' + parts[1].toUpperCase();
69
if(typeof OpenLayers.Lang[testLang] == "object") {
74
OpenLayers.Console.warn(
75
'Failed to find OpenLayers.Lang.' + parts.join("-") +
76
' dictionary, falling back to default language'
78
lang = OpenLayers.Lang.defaultCode;
81
OpenLayers.Lang.code = lang;
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>.
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>.
96
* {String} A internationalized string.
98
translate: function(key, context) {
99
var dictionary = OpenLayers.Lang[OpenLayers.Lang.getCode()];
100
var message = dictionary[key];
102
// Message not found, fall back to message key
106
message = OpenLayers.String.format(message, context);
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>.
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>.
127
* {String} A internationalized string.
129
OpenLayers.i18n = OpenLayers.Lang.translate;
b'\\ No newline at end of file'