User:Proteins/translateinterwikicodes.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Proteins/translateinterwikicodes. |
//<pre>
// Translate interwiki codes such as "simple" and "ar"
//
// To use this script, add "importScript('User:Proteins/translateinterwikicodes.js');" to your monobook.js subpage
// under your user page, as you can see at User:Proteins/monobook.js
var interwiki_English_names = {
"aa" : "Afar",
"ab" : "Abkhazian", // or Abkhaz
"ace" : "Achinese",
"ae" : "Avestan",
"af" : "Afrikaans",
"ak" : "Akan",
"aln" : "Gheg Albanian",
"als" : "Alemannic", // same as gsw
"am" : "Amharic",
"an" : "Aragonese",
"ang" : "Old English",
"ar" : "Arabic",
"arc" : "Aramaic", // or Assyrian Neo-Aramaic
"arn" : "Mapudungun", // or Araucanian (Araucano), Mapuche, Mapudungu
"arv" : "Kotava",
"arz" : "Egyptian Spoken Arabic",
"as" : "Assamese",
"ast" : "Asturian",
"av" : "Avar", // or Avaric
"avk" : "Kotava",
"ay" : "Aymara",
"az" : "Azerbaijani",
"ba" : "Bashkir",
"bar" : "Bavarian", // Austro-Bavarian and South Tyrolean
"bat-smg" : "Samogitian", // 639-2: bat
"bcc" : "Southern Balochi",
"bcl" : "Central Bicolano", // or Bikol
"bcr" : "Babine",
"be" : "Belarusian",
"be-x-old" : "Belarusian (Tarashkevitsa)",
"be-tarask" : "Belarusian (Tarashkevitsa)", // same as be-x-old; 639-3: bel
"bg" : "Bulgarian",
"bh" : "Bihari",
"bi" : "Bislama",
"bm" : "Bambara",
"bn" : "Bengali",
"bo" : "Tibetan",
"bpy" : "Bishnupriya Manipuri",
"br" : "Breton",
"bs" : "Bosnian",
"bto" : "Iriga Bicolano",
"bug" : "Buginese", // or Bugis
"byp" : "Bumaji",
"bxr" : "Buryat (Russia)",
"ca" : "Catalan",
"cbk-zam" : "Zamboanga Chavacano", // or Zamboangueño; cbk is the 639-3 code for Chavacano
"cdo" : "Min Dong Chinese",
"ce" : "Chechen",
"ceb" : "Cebuano",
"ch" : "Chamorro",
"cho" : "Choctaw",
"chr" : "Cherokee",
"chy" : "Cheyenne",
"co" : "Corsican",
"cop" : "Coptic",
"cr" : "Cree",
"crh" : "Crimean Turkish", // or Crimean Tatar
"crh-cyrl" : "Crimean Turkish (Cyrillic)",
"crh-latn" : "Crimean Turkish (Latin)",
"cs" : "Czech",
"csb" : "Kashubian",
"cu" : "Church Slavic", // or Old Church Slavonic
"cv" : "Chuvash",
"cy" : "Welsh",
"da" : "Danish",
"de" : "German",
"de-formal" : "Formal German",
"diq" : "Dimli",
"dsb" : "Lower Sorbian",
"dv" : "Divehi",
"dz" : "Dzongkha",
"ee" : "Ewe",
"el" : "Greek",
"eml" : "Emilian-Romagnol", // or Emiliano-Romagnolo
"en" : "English",
"en-gb" : "British English",
"eo" : "Esperanto",
"es" : "Spanish",
"et" : "Estonian",
"eu" : "Basque",
"ext" : "Extremaduran",
"fa" : "Persian",
"ff" : "Fulah",
"fi" : "Finnish",
"fiu-vro" : "Võro", // fiu is the 639-2 code for Baltic-Finnic
"fj" : "Fijian",
"fo" : "Faroese",
"fr" : "French",
"frc" : "Cajun French",
"frp" : "Franco-Provençal",
"fur" : "Friulian",
"fy" : "Frisian", // or Western Frisian
"ga" : "Irish",
"gag" : "Gagauz",
"gan" : "Gan", // or Gan Chinese
"gd" : "Scottish Gaelic",
"gl" : "Galician",
"glk" : "Gilaki",
"gn" : "Guaraní",
"got" : "Gothic",
"grc" : "Ancient Greek",
"gsw" : "Alemannic", // same as als
"gu" : "Gujarati",
"gv" : "Manx",
"ha" : "Hausa",
"hak" : "Hakka Chinese",
"haw" : "Hawaiian",
"he" : "Hebrew",
"hi" : "Hindi",
"hif" : "Fiji Hindi", // or Fijian Hindustani
"hif-deva" : "Fiji Hindi (Devangari)",
"hif-latn" : "Fiji Hindi (Latin)",
"hil" : "Hiligaynon",
"ho" : "Hiri Motu",
"hr" : "Croatian",
"hsb" : "Upper Sorbian",
"ht" : "Haitian", // or Haitian Creole French
"hu" : "Hungarian",
"hy" : "Armenian",
"hz" : "Herero",
"ia" : "Interlingua", // IALA
"id" : "Indonesian",
"ie" : "Interlingue",
"ig" : "Igbo",
"ii" : "Sichuan Yi",
"ik" : "Inupiak", // or Inupiatun
"ike-cans" : "Eastern Canadian", // or Inuit (Unified Canadian Aboriginal Syllabics)
"ike-latn" : "Eastern Canadian Inuktitut (Latin)", // 639-3: ike; 639-1: iu and 639-2: iku for Inuktitut
"ikt" : "Western Canadian Inuktitut",
"ilo" : "Iloko",
"inh" : "Ingush",
"io" : "Ido",
"is" : "Icelandic",
"it" : "Italian",
"iu" : "Inuktitut",
"ja" : "Japanese",
"jbo" : "Lojban",
"jut" : "Jutish", // or Jutlandic
"jv" : "Javanese",
"ka" : "Georgian",
"kaa" : "Kara-Kalpak",
"kab" : "Kabyle",
"kg" : "Kongo",
"ki" : "Kikuyu",
"kj" : "Kwanyama",
"kk" : "Kazakh",
"kk-arab" : "Kazakh (Arabic script)",
"kk-cyrl" : "Kazakh (Cyrillic script)",
"kk-latn" : "Kazakh (Latin script)",
"kk-cn" : "Kazakh (China)",
"kk-kz" : "Kazakh (Kazakhstan)",
"kk-tr" : "Kazakh (Turkey)",
"kl" : "Greenlandic", // or Kalaallisut iso 639-3 is kal
"km" : "Khmer",
"kn" : "Kannada",
"ko" : "Korean",
"kr" : "Kanuri",
"kri" : "Krio",
"krj" : "Kinaray-A",
"ks" : "Kashmiri",
"ksh" : "Kölsch",
"ku" : "Kurdish",
"ku-arab" : "Northern Kurdish Arabic",
"ku-latn" : "Northern Kurdish Latin",
"kv" : "Komi",
"kw" : "Cornish",
"ky" : "Kirghiz",
"la" : "Latin",
"lad" : "Ladino",
"lb" : "Luxembourgish",
"lbe" : "Lak",
"lez" : "Lezghian",
"lfn" : "Lingua Franca Nova", // 639-2: art
"lg" : "Ganda",
"li" : "Limburgish",
"lij" : "Ligurian",
"lld" : "Ladin", // 639-2: roa
"lmo" : "Lombard",
"ln" : "Lingala",
"lo" : "Lao",
"loz" : "Lozi",
"lt" : "Lithuanian",
"lu" : "Luba-Katanga",
"lv" : "Latvian",
"lzz" : "Laz",
"mad" : "Madurese",
"mai" : "Maithili",
"map-bms" : "Banyumasan",
"mc" : "Murcian",
"mdf" : "Moksha",
"mg" : "Malagasy",
"mh" : "Marshallese",
"mi" : "Māori",
"mk" : "Macedonian",
"ml" : "Malayalam",
"mn" : "Mongolian",
"mo" : "Moldavian",
"mr" : "Marathi",
"ms" : "Malay",
"mt" : "Maltese",
"mus" : "Creek",
"mwl" : "Mirandese",
"my" : "Burmese",
"myv" : "Erzya",
"mzn" : "Mazanderani",
"na" : "Nauru",
"nah" : "Nahuatl languages",
"nan" : "Min-nan", // same as zh-min-nan; nan is the 639-3 code
"nap" : "Neapolitan",
"nb" : "Norwegian (Bokmål)", // same as no
"nd" : "North Ndebele",
"nds" : "Low Saxon", // or Low German
"nds-nl" : "Dutch Low Saxon", // nds is the 639-3 code for Low Saxon
"ne" : "Nepali",
"new" : "Newar", // Nepal Bhasa
"ng" : "Owambo",
"niu" : "Niuean",
"nl" : "Dutch",
"nn" : "Norwegian (Nynorsk)",
"no" : "Norwegian (Bokmål)", // same as nb
"non" : "Old Norse",
"nov" : "Novial",
"nr" : "South Ndebele",
"nrm" : "Narom",
"nso" : "Northern Sotho", // or Pedi or Sepedi
"nv" : "Navajo",
"ny" : "Chichewa",
"oc" : "Occitan",
"och" : "Classical Chinese", // or Literary Chinese; same as zh-classical
"oj" : "Ojibwa",
"om" : "Oromo",
"or" : "Oriya",
"os" : "Ossetian",
"pa" : "Panjabi",
"pag" : "Pangasinan",
"pam" : "Kapampangan", // or Pampanga
"pap" : "Papiamento",
"pdc" : "Pennsylvania German",
"pdt" : "Plautdietsch",
"pfl" : "Pfaelzisch",
"pi" : "Pali",
"pih" : "Pitcairn-Norfolk",
"pl" : "Polish",
"plm" : "Palembang",
"pms" : "Piemontese",
"pnt" : "Pontic",
"ps" : "Pashto",
"pt" : "Portuguese",
"pt-br" : "Brazilian Portuguese",
"qu" : "Quechua",
"rif" : "Tarifit",
"rm" : "Raeto-Romance",
"rmy" : "Vlax Romani",
"rn" : "Kirundi",
"ro" : "Romanian",
"roa-rup" : "Aromanian", // rup is the 639-2/3 code; roa is the 639-2 code for Romance (Other)
"roa-tara" : "Tarantino",
"ru" : "Russian",
"ruq" : "Romanian", // or Megleno-Romanian
"ruq-cyrl" : "Megleno-Romanian (Cyrillic script)",
"ruq-grek" : "Megleno-Romanian (Greek script)",
"ruq-latn" : "Megleno-Romanian (Latin script)",
"rw" : "Kinyarwanda",
"sa" : "Sanskrit",
"sah" : "Yakut",
"sc" : "Sardinian",
"scn" : "Sicilian",
"sco" : "Scots",
"sd" : "Sindhi",
"sdc" : "Sardinian", // or Sassarese
"se" : "Northern Sami",
"sei" : "Seri",
"sg" : "Sango",
"sh" : "Serbo-Croatian",
"shi" : "Tachelhit",
"si" : "Sinhala",
"simple" : "Simple English",
"sk" : "Slovak",
"sl" : "Slovenian",
"sm" : "Samoan",
"sma" : "Southern Sami",
"sn" : "Shona",
"so" : "Somali",
"sq" : "Albanian",
"sr" : "Serbian",
"sr-ec" : "Serbian ekavian (Cyrillic script)",
"sr-el" : "Serbian ekavian (Latin script)",
"srn" : "Sranan Tongo",
"ss" : "Swati",
"st" : "Sotho", // or Southern Sotho
"stq" : "Saterland Frisian", // or Saterfriesisch
"su" : "Sundanese",
"sv" : "Swedish",
"sw" : "Swahili",
"szl" : "Silesian",
"ta" : "Tamil",
"te" : "Telugu",
"tet" : "Tetum",
"tg" : "Tajik",
"tg-cyrl" : "Tajiki (Cyrillic script)",
"tg-latn" : "Tajiki (Latin script)",
"th" : "Thai",
"ti" : "Tigrinya",
"tk" : "Turkmen",
"tl" : "Tagalog",
"tlh" : "Klingon",
"tn" : "Tswana",
"to" : "Tonga",
"tokipona" : "Toki Pona",
"tpi" : "Tok Pisin",
"tr" : "Turkish",
"ts" : "Tsonga",
"tt" : "Tatar",
"tt-cyrl" : "Tatar (Cyrillic script)",
"tt-latn" : "Tatar (Latin script)",
"ttt" : "Tati",
"tum" : "Tumbuka",
"tw" : "Twi",
"ty" : "Tahitian",
"tyv" : "Tyvan",
"tzm" : "Central Morocco Tamazight",
"udm" : "Udmurt",
"ug" : "Uighur",
"uk" : "Ukrainian",
"ur" : "Urdu",
"uz" : "Uzbek",
"ve" : "Venda",
"vec" : "Venetian",
"vi" : "Vietnamese",
"vls" : "Vlaams",
"vo" : "Volapük",
"vrm" : "Värmlandic",
"wa" : "Walloon",
"war" : "Waray", // or Wáray-Wáray / Waráy
"wo" : "Wolof",
"wuu" : "Wu Chinese",
"xal" : "Kalmyk",
"xh" : "Xhosa",
"xmf" : "Mingrelian",
"yao" : "Yao",
"yap" : "Yapese",
"ydd" : "Eastern Yiddish",
"yi" : "Yiddish",
"yo" : "Yoruba",
"yue" : "Cantonese", // or Yue Chinese; same as zh-yue
"yux" : "Southern Yukaghir",
"za" : "Zhuang",
"zea" : "Zeeuws",
"zh" : "Chinese", // or Mandarin / Standard Chinese; cmn is the 639-3 code
"zh-classical" : "Classical Chinese", // or Literary Chinese; same as och
"zh-cn" : "Chinese (PRC)",
"zh-hans" : "Simplified Chinese",
"zh-hant" : "Traditional Chinese",
"zh-hk" : "Chinese (Hong Kong)",
"zh-min-nan" : "Min-nan", // same as nan
"zh-mo" : "Chinese (Macau)",
"zh-my" : "Chinese (Malaysia)",
"zh-sg" : "Chinese (Singapore)",
"zh-tw" : "Chinese (Taiwan)", // or Taiwanese Mandarin
"zh-yue" : "Cantonese", // or Yue Chinese; same as yue
"zu" : "Zulu"
};
function translateInterwikiCodes() {
var alert_string;
var num_lines_printed = 0;
var describe_results = false;
var on_main_page = false;
var translate_all_extiw_hyperlinks = true;
var parent_node;
var interwiki_portlet;
var hyperlinks;
var temp_hyperlink;
var hyperlink_index;
var hyperlink_counter;
var num_hyperlinks = 0;
var language_code;
var English_translation;
var num_interwiki_links_translated = 0;
var interwiki_link_string = "interwiki link";
// 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
alert_string = "";
num_lines_printed = 0;
num_hyperlinks = 0;
interwiki_portlet = document.getElementById("p-lang");
if (!interwiki_portlet) {
alert_string += "Interwiki portlet is undefined.\n";
} else {
hyperlinks = interwiki_portlet.getElementsByTagName("A");
if (!hyperlinks) {
alert_string += "Interwiki hyperlinks are undefined.\n";
} else {
num_hyperlinks = hyperlinks.length;
}
}
interwiki_link_string = "interwiki link";
if (num_hyperlinks != 1) { interwiki_link_string += "s"; };
alert_string += "This page has " + num_hyperlinks + " potential " + interwiki_link_string + ".\n\n";
num_lines_printed += 2;
// 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 (num_lines_printed>45) { // in cases of many error messages
if (describe_results) { window.alert(alert_string); }
alert_string = "";
num_lines_printed = 0;
}
parent_node = temp_hyperlink.parentNode;
if (!parent_node) {
alert_string += "No parent node in hyperlink " + hyperlink_index + "\n";
num_lines_printed++;
continue;
}
if (parent_node.nodeName != "LI") {
alert_string += "No LI parent node in hyperlink " + hyperlink_index + "\n";
num_lines_printed++;
continue;
}
if (!parent_node.className) {
// alert_string += "No className for parent node in hyperlink " + hyperlink_index + "\n";
num_lines_printed++;
continue;
}
language_code = parent_node.className.replace(/interwiki-/, "");
language_code = language_code.replace(/\sFA/, "");
English_translation = interwiki_English_names[language_code];
if (!English_translation) {
alert_string += "No English translation for " + language_code + " in hyperlink " + hyperlink_index + "\n";
num_lines_printed++;
continue;
}
hyperlink_counter++;
if ((hyperlink_counter%40 == 1) && (hyperlink_counter > 1)) {
if (describe_results) { window.alert(alert_string); }
alert_string = "Continued...\n\n";
}
alert_string += "Interwiki link " + hyperlink_counter + " : " + language_code + " => " + English_translation + "\n";
temp_hyperlink.innerHTML = English_translation;
} // closes loop over interwiki links
num_interwiki_links_translated = hyperlink_counter;
interwiki_link_string = "interwiki link";
if (num_interwiki_links_translated != 1) { interwiki_link_string += "s"; };
alert_string += "\nTranslated " + num_interwiki_links_translated + " " + interwiki_link_string + " into English.";
if (describe_results) { window.alert(alert_string); }
// Translate other interwiki links; removed restriction to the Main Page
alert_string = "";
translate_all_extiw_hyperlinks = true;
if ((translate_all_extiw_hyperlinks) || (on_main_page)) {
num_hyperlinks = 0;
hyperlinks = document.getElementsByTagName("A"); // earlier code was restricted to mp-lang on Main Page
if (!hyperlinks) {
alert_string += "Document hyperlinks are undefined.\n";
} else {
num_hyperlinks = hyperlinks.length; // number of potential extiw hyperlinks
}
hyperlink_counter = 0;
for (hyperlink_index=0; hyperlink_index<num_hyperlinks; hyperlink_index++) {
temp_hyperlink = hyperlinks[hyperlink_index];
if (temp_hyperlink.className != "extiw") { continue; }
if (temp_hyperlink.title == "m:List of Wikipedias") { 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%40 == 1) && (hyperlink_counter > 1)) {
if (describe_results) { window.alert(alert_string); }
alert_string = "Continued...\n\n";
}
alert_string += "Interwiki link " + hyperlink_counter + " : " + language_code + " => " + English_translation + "\n";
temp_hyperlink.innerHTML = English_translation;
} // closes loop over interwiki links
num_interwiki_links_translated += hyperlink_counter; // Increment the number translated
interwiki_link_string = "interwiki link";
if (hyperlink_counter != 1) { interwiki_link_string += "s"; };
alert_string += "\nTranslated " + hyperlink_counter + " " + interwiki_link_string + " at the bottom of the Main Page into English.";
if (describe_results) { window.alert(alert_string); }
} // closes check for being on the Main Page
// Minimal acknowledgment message
if (!describe_results) {
interwiki_link_string = "interwiki link";
if (num_interwiki_links_translated != 1) { interwiki_link_string += "s"; };
alert_string = "\nTranslated " + num_interwiki_links_translated + " " + interwiki_link_string + " into English.";
window.alert(alert_string);
}
} // closes function translateInterwikiCodes()
$(function () {
mw.util.addPortletLink('p-tb', 'javascript:translateInterwikiCodes()', 'Translate interwiki links', 'ca-translate', 'Translates interwiki links into English', 'i', '');
});
//</pre>