2011-08-24 18:37:22 +01:00
|
|
|
//trys to find a translation for the string and returns the translation or the original string
|
|
|
|
function translate(str)
|
|
|
|
{
|
|
|
|
var translated = str;
|
|
|
|
|
2011-08-26 19:47:54 +01:00
|
|
|
//skip if there is no language defined
|
|
|
|
if(typeof language === "undefined")
|
|
|
|
return;
|
|
|
|
|
2011-08-24 18:37:22 +01:00
|
|
|
//return translation if avaiable
|
2011-08-26 19:47:54 +01:00
|
|
|
if(translation != null && translation[language][str] != null)
|
2011-08-24 18:37:22 +01:00
|
|
|
{
|
|
|
|
translated = translation[language][str];
|
|
|
|
}
|
|
|
|
else if(window.console)
|
|
|
|
{
|
|
|
|
window.console.log("No " + language + " translation for '" + str + "'");
|
|
|
|
}
|
|
|
|
|
|
|
|
return translated;
|
|
|
|
}
|
|
|
|
|
|
|
|
function DOMTranslate(selector, attribute)
|
|
|
|
{
|
|
|
|
//skip translation if its english
|
2011-08-26 19:47:54 +01:00
|
|
|
if(typeof language === "undefined")
|
2011-08-24 18:37:22 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
//loop trough all elements
|
|
|
|
$(selector).each(function(index, element)
|
|
|
|
{
|
|
|
|
//make a jquery object
|
|
|
|
element = $(element);
|
|
|
|
|
|
|
|
//thats a attribute translation
|
|
|
|
if(attribute != null)
|
|
|
|
{
|
|
|
|
element.attr(attribute, translate(element.attr(attribute)));
|
|
|
|
}
|
|
|
|
//thats a text translation
|
|
|
|
else
|
|
|
|
{
|
|
|
|
element.text(translate(element.text()));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready(function()
|
|
|
|
{
|
|
|
|
DOMTranslate(".translate");
|
|
|
|
});
|