mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-05-05 06:37:10 -04:00
Added basic support for translating, so far only on pad.html
This commit is contained in:
parent
54d51c96d9
commit
8cceeefa05
8 changed files with 192 additions and 40 deletions
47
static/js/translate.js
Normal file
47
static/js/translate.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
//trys to find a translation for the string and returns the translation or the original string
|
||||
function translate(str)
|
||||
{
|
||||
var translated = str;
|
||||
|
||||
//return translation if avaiable
|
||||
if(language != null && translation != null && translation[language][str] != null)
|
||||
{
|
||||
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
|
||||
if(language === "en")
|
||||
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");
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue