locale.js
1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
define([
'./locales/de.js',
'./locales/fr.js',
'./locales/nl.js',
'./locales/pl.js',
'./locales/pt_br.js',
'./locales/ru.js',
'./locales/zh.js'
], function() {
var langId = (navigator.language || navigator.userLanguage).toLowerCase();
var language = langId.substr(0, 2);
var locales = {};
for (index in arguments) {
for (property in arguments[index])
locales[property] = arguments[index][property];
}
if ( ! locales['en'])
locales['en'] = {};
if ( ! locales[langId] && ! locales[language])
language = 'en';
var locale = (locales[langId] ? locales[langId] : locales[language]);
function __(text) {
var index = locale[text];
if (index === undefined)
return text;
return index;
};
function setLanguage(language) {
locale = locales[language];
}
return {
__ : __,
locales : locales,
locale : locale,
setLanguage: setLanguage
};
});