2009-11-10 21:31:47 +00:00
|
|
|
var put_locale = function(svgCanvas, given_param){
|
|
|
|
var lang_param;
|
2009-11-11 18:13:26 +00:00
|
|
|
if(given_param) {
|
2009-11-10 21:31:47 +00:00
|
|
|
lang_param = given_param;
|
2009-11-11 18:13:26 +00:00
|
|
|
} else {
|
|
|
|
lang_param = $.pref('lang');
|
|
|
|
if(!lang_param) {
|
|
|
|
if (navigator.userLanguage) // Explorer
|
|
|
|
lang_param = navigator.userLanguage;
|
|
|
|
else if (navigator.language) // FF, Opera, ...
|
|
|
|
lang_param = navigator.language;
|
|
|
|
if (lang_param == "")
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// don't bother on first run if language is English
|
2009-11-12 21:43:19 +00:00
|
|
|
lang_param = String(lang_param);
|
|
|
|
if(lang_param.indexOf("en") == 0) return;
|
2009-11-10 21:31:47 +00:00
|
|
|
}
|
|
|
|
|
2009-10-03 05:54:40 +00:00
|
|
|
var url = "locale/lang." + lang_param + ".js";
|
2009-10-04 20:47:25 +00:00
|
|
|
$.get(url, function(data){
|
2009-11-10 21:31:47 +00:00
|
|
|
var LangData = eval(data), js_strings;
|
2009-11-12 16:00:50 +00:00
|
|
|
$.each(LangData, function(i, data) {
|
|
|
|
if(data.id) {
|
|
|
|
var elem = $('#'+data.id)[0];
|
|
|
|
if(elem) {
|
|
|
|
if(data.title)
|
|
|
|
elem.title = data.title;
|
|
|
|
if(data.textContent) {
|
|
|
|
// Only replace text nodes, not elements
|
|
|
|
$.each(elem.childNodes, function(j, node) {
|
|
|
|
if(node.nodeType == 3) {
|
|
|
|
node.textContent = data.textContent;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2009-11-10 21:31:47 +00:00
|
|
|
}
|
2009-11-12 16:00:50 +00:00
|
|
|
} else if(data.js_strings) {
|
|
|
|
js_strings = data.js_strings;
|
2009-10-04 20:47:25 +00:00
|
|
|
}
|
2009-11-12 16:00:50 +00:00
|
|
|
});
|
2009-11-10 21:31:47 +00:00
|
|
|
svgCanvas.setLang(lang_param, js_strings);
|
2009-10-03 05:54:40 +00:00
|
|
|
},"json");
|
2009-10-04 20:47:25 +00:00
|
|
|
};
|