2010-01-14 18:33:05 +00:00
|
|
|
/*
|
2009-11-25 13:51:42 +00:00
|
|
|
* Localizing script for SVG-edit UI
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2
|
|
|
|
*
|
|
|
|
* Copyright(c) 2009 Narendra Sisodya
|
|
|
|
*
|
|
|
|
*/
|
2009-11-10 21:31:47 +00:00
|
|
|
var put_locale = function(svgCanvas, given_param){
|
|
|
|
var lang_param;
|
2010-01-08 20:36:39 +00:00
|
|
|
// TODO: Make this array be based on entries in svg-editor.html
|
2010-01-30 11:41:10 +00:00
|
|
|
var good_langs = ['ar','cs','de','en','es','fa','fr','fy','hi','nl','ro','ru','sk','zh-TW'];
|
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;
|
|
|
|
}
|
2009-11-12 21:43:19 +00:00
|
|
|
lang_param = String(lang_param);
|
2009-12-22 21:24:58 +00:00
|
|
|
|
|
|
|
// Set to English if language is not in list of good langs
|
|
|
|
if($.inArray(lang_param, good_langs) == -1) {
|
|
|
|
lang_param = "en";
|
|
|
|
}
|
|
|
|
|
|
|
|
// don't bother on first run if language is English
|
2009-11-12 21:43:19 +00:00
|
|
|
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";
|
2010-01-12 08:07:50 +00:00
|
|
|
|
|
|
|
var processFile = function(data){
|
2009-11-10 21:31:47 +00:00
|
|
|
var LangData = eval(data), js_strings;
|
2010-02-01 18:40:57 +00:00
|
|
|
var more = svgCanvas.runExtensions("addLangData", lang_param, true);
|
2010-02-02 19:24:17 +00:00
|
|
|
$.each(more, function(i, m) {
|
|
|
|
if(m.data) {
|
2010-02-01 18:40:57 +00:00
|
|
|
LangData = $.merge(LangData, m.data);
|
2010-02-02 19:24:17 +00:00
|
|
|
}
|
|
|
|
});
|
2009-11-12 16:00:50 +00:00
|
|
|
$.each(LangData, function(i, data) {
|
|
|
|
if(data.id) {
|
2010-02-01 18:40:57 +00:00
|
|
|
var elem = $('#svg_editor').parent().find('#'+data.id)[0];
|
2009-11-12 16:00:50 +00:00
|
|
|
if(elem) {
|
|
|
|
if(data.title)
|
|
|
|
elem.title = data.title;
|
|
|
|
if(data.textContent) {
|
2010-01-14 16:05:05 +00:00
|
|
|
// Only replace non-empty text nodes, not elements
|
2009-11-12 16:00:50 +00:00
|
|
|
$.each(elem.childNodes, function(j, node) {
|
2010-01-14 16:05:05 +00:00
|
|
|
if(node.nodeType == 3 && $.trim(node.textContent)) {
|
2009-11-12 16:00:50 +00:00
|
|
|
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);
|
2010-01-12 08:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
'url': url,
|
|
|
|
'dataType': "text",
|
|
|
|
success: processFile,
|
|
|
|
error: function(xhr) {
|
|
|
|
if(xhr.responseText) {
|
|
|
|
processFile(xhr.responseText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2009-10-04 20:47:25 +00:00
|
|
|
};
|