User:Proteins/translateinterwikicodes.js: Difference between revisions

Content deleted Content added
Proteins (talk | contribs)
m extra space
Proteins (talk | contribs)
add code for translating the interwiki links at the bottom of the Main Page
Line 368:
function translateInterwikiCodes() {
var alert_string;
var on_main_page = false;
 
var parent_node;
Line 380 ⟶ 381:
var language_code;
var English_translation;
 
 
// Check whether we're on the Main Page
 
on_main_page = false;
if (document.getElementById("mp-topbanner")) {
on_main_page = true;
// window.alert("We're reading the Main Page.");
}
 
// Loop over the interwiki links
Line 433 ⟶ 443:
window.alert(alert_string);
 
// Translate other interwiki links, but only on the Main Page
 
if (on_main_page) {
num_hyperlinks = 0;
wikipedia_languages = document.getElementById("mp-lang");
if (!wikipedia_languages) {
alert_string += "The Wikipedia languages section of the Main Page is undefined.\n";
} else {
hyperlinks = wikipedia_languages.getElementsByTagName("A");
if (!hyperlinks) {
alert_string += "Interwiki hyperlinks are undefined.\n";
} else {
num_hyperlinks = hyperlinks.length;
}
}
alert_string += "The bottom of the Main Page has " + num_hyperlinks + " potential interwiki links.\n\n";
// window.alert(alert_string); alert_string = "";
 
hyperlink_counter = 0;
for (hyperlink_index=0; hyperlink_index<num_hyperlinks; hyperlink_index++) {
temp_hyperlink = hyperlinks[hyperlink_index];
 
if (temp_hyperlink.className != "extiw") { continue; }
language_code = temp_hyperlink.title.replace(/:/, "");
English_translation = interwiki_English_names[language_code];
if (!English_translation) {
alert_string += "No English translation for " + language_code + " in hyperlink " + hyperlink_index + "\n";
continue;
}
hyperlink_counter++;
if (hyperlink_counter < 41) {
alert_string += "Interwiki link " + hyperlink_counter + " : " + language_code + " => " + English_translation + "\n";
}
temp_hyperlink.innerHTML = English_translation;
} // closes loop over interwiki links
alert_string += "\nTranslated " + hyperlink_counter + " more interwiki links into English.";
window.alert(alert_string);
} // closes check for being on the Main Page
} // closes function translateInterwikiCodes()