/**
  * Translate some string
  *
**/


/* Markdonw translations */
function locate_wmd() {
    if ($("#wmd-button-bar").length == 0) {
        // exit if there's no wmd bar
        return;
    }

    help_button = $("#wmd-help-button a")[0];
    help_button.href = "/markdown_help/";
    help_button.title = "Aiuto su sintassi Markdown";

    buttons = Array()
    buttons["bold"]     = ["Strong", "Grassetto"]
    buttons["italic"]   = ["Emphasis", "Corsivo"]
    buttons["link"]     = ["Hyperlink", "Collegamento"]
    buttons["quote"]    = ["Blockquote", "Citazione"]
    buttons["code"]     = ["Code Sample", "Codice sorgente"]
    buttons["image"]    = ["Image", "Immagine"]
    buttons["olist"]    = ["Numbered List", "Elenco numerato"]
    buttons["ulist"]    = ["Bulleted List", "Elenco puntato"]
    buttons["heading"]  = ["Heading", "Titolo"]
    buttons["hr"]       = ["Horizontal Rule", "Linea orizzontale"]
    buttons["undo"]     = ["Undo", "Annulla"]
    buttons["redo"]     = ["Redo", "Ripeti"]


    for (key in buttons) {
        id = "#wmd-" + key + "-button"
        en = buttons[key][0]
        it = buttons[key][1]

        button = $(id)[0]
        button.title = button.title.replace(en,it)
    }
}


function translate_string(id, en, it) {
    if ($(id).length < 1)
        return;
    element = $($(id)[0])
    element.html(element.html().replace(en,it))

}

$(window).load(function () {
    t = translate_string
   
    // When no related question are found
    $($("#ask-related-questions")[0]).bind('DOMSubtreeModified', function () { 
        t("#ask-related-questions div[align=center]", 
            "No questions like this have been found", 
            "Non &egrave; stata trovata alcuna domanda simile"
          )
    })

    
    locate_wmd();

})
