User:BanningBotru-chi/langconvru-chi.js

/** Children's Language transliterator Cyrillic to Latin convertion Based on Old English Wikipedia transliterator by PiRSquared17 (https://ang.wikipedia.org/wiki/User:PiRSquared17/spellingstyle.js GFDL / CC-BY-SA 3.0) /** * Actually clone content, and transliterate * * @param event The event: event.data.outputstyle (see convertStyle args 2,3) * @returns nothing (undefined) */ function doConv(event) { var $ = jQuery; if ($("#mw-content-text-clone").length) $("#mw-content-text-clone").remove; //console.log("Entered doConv, (possibly removed old clone)"); // get target style var targetstyle = event.data.outputstyle; var contentClone; $("#mw-content-text").show; contentClone = $("#mw-content-text").clone; contentClone.attr("id", "mw-content-text-clone"); convertStyle(contentClone, "cyrs", targetstyle); convertStyle(contentClone, "cyrl", targetstyle); convertStyle(contentClone, "glag", targetstyle); $("#mw-content-text").hide; if (targetstyle == "cyrl") contentClone.addClass("content-cyrl"); else contentClone.addClass("content-" + targetstyle); contentClone.insertAfter("#mw-content-text"); $(".click-cyrs").click({"outputstyle": "cyrs"}, doConv); $(".click-cyrl").click({"outputstyle": "cyrl"}, doConv); $(".click-glag").click({"outputstyle": "glag"}, doConv); }

// any errors? Fix them var latn = { // latin to cyrillic substitutions "a": "а", "b": "б", "v": "в", "g": "г", "d": "д", "e": "е", "ë": "ё", "j": "ж", "z": "з", "i": "и", "ï": "й", "k": "к", "l": "л", "m": "м", "n": "н", "o": "о", "p": "п", "r": "р", "s": "с", "t": "т", "u": "у", "f": "ф", "h": "х", "ç": "ц", "č": "ч", "š": "ш", "ş": "щ", "-": "ъ", "ь": "ы" "'": "ь", "ə": "э", "ü": "ю", "ä": "я",

};

// again, please report any errors, please include replacement for this var latn2 = { // cyrillic -> latin "а": "a", "б": "b", "в": "v", "г": "g", "д": "d", "е": "e", "ё": "ë", "ж": "j", "з": "z", "и": "i", "й": "ï", "к": "k", "л": "l", "м": "m", "н": "n", "о": "o", "п": "p", "р": "r", "с": "s", "т": "t", "у": "u", "ф": "f", "х": "h", "ц": "ç", "ч": "č", "ш": "š", "щ": "ş", "ъ": "-", "ы": "ь", "ь": "'", "э": "ə", "ю": "ü", "я": "ä", };

/** * Two or more characters -> a single cyrl or a pattern of latn * Put here anything that should be converted from two or more cyrl characters to one or more latin. */ latn2_exceptions = [ ["Аз", "äz"], ["Эр", "ə"] ];

/** * Replace occurrences of regex, possibly normalize * * For nodes (not text) input, modifies object * @param input the input text or jQuery object * @param regex the regular expression * @param replacement replacement * @param norm Normalize input? (also converts to lowercase) * @returns the converted version of input (as text/DOM node) */ var myReplace = function(input, regex, replacement, norm) { var $ = jQuery; if(typeof normalizeString === 'undefined') return; if (typeof regex == "string") regex = new RegExp(regex, "g"); if (typeof input == "string") return norm?normalizeString(input).toLowerCase:input.replace(regex,replacement); if (typeof input == "undefined") return; var node = input[0]; if (typeof node == "undefined") node = input; if (!("nodeType" in node)) return node; if (node.nodeType == 3) { if (norm) node.nodeValue = normalizeString(node.nodeValue).toLowerCase; node.nodeValue = node.nodeValue.replace(regex, replacement); } else { if ($(node).hasClass("nochange")) return node; if (!("childNodes" in node)) return node; for (var i = 0, len = node.childNodes.length; i < len; i++) myReplace($(node.childNodes[i]), regex, replacement, norm); }   return node; };

/** * Convert style of text/jQuery node from one spelling style to another * * @param inputhtml input text or jQuery node * @param inputstyle possible values: "simb", "cyrl", "latn" * @param outputstyle possible values:"symb", "cyrl", "latn" * @returns converted version of inputhtml */ function convertStyle(inputhtml, inputstyle, outputstyle) { var temp = inputhtml; if (inputstyle == outputstyle) return inputhtml; if (inputstyle == "simb" && outputstyle == "cyrl") { temp = myReplace(temp, /Ζ/g, "З"); temp = myReplace(temp, /ζ/g, "з"); temp = myReplace(temp, /Ε/g, "Э"); temp = myReplace(temp, /ε/g, "э"); temp = myReplace(temp, /Ξ/g, 'Ы'); temp = myReplace(temp, /ξ/g, 'ы'); } else if (inputstyle == "cyrl" && outputstyle == "simb") { temp = myReplace(temp, /З/g, 'Ζ'); temp = myReplace(temp, /з/g, 'ζ'); temp = myReplace(temp, /Э/g, 'Ε'); temp = myReplace(temp, /э/g, 'ε'); temp = myReplace(temp, /Ы/g, 'Ξ'); temp = myReplace(temp, /ы/g, 'ξ'); } else if (inputstyle == "latn") { for (var glagolitic in glag) { temp = myReplace(temp, latinized, latn[latinized]); }       return convertStyle(temp, "simb", outputstyle); } else if (outputstyle == "latn") { temp = convertStyle(myReplace(temp,"","",1), inputstyle, "simb"); for (var i = 0; i < latn2_exceptions.length; i++) { temp = myReplace(temp,latn2_exceptions[i][0],latn2_exceptions[i][1]); }       for (var cyrillic in latn2) { temp = myReplace(temp, cyrillic, glag2[cyrillic]); }   }    return temp; }

/* * This is code to be executed when the document is ready * Basically, add [ simb ] [ cyrl ] [ latn ]. * Clicking each link converts the document to that style. * (see doConv) */ $(function {   $ = jQuery;    $("#mw-content-text").prepend($(" [ cyrs ] [ cyrl ] [ glag ]? "));    $(".click-cyrs").click({"outputstyle": "simb"}, doConv);    $(".click-cyrl").click({"outputstyle": "cyrl"}, doConv);    $(".click-glag").click({"outputstyle": "latn"}, doConv);    if (typeof enableNoDots !== "undefined" && enableNoDots) $(function{$(" [ no dots ] ").click({"outputstyle": "nodots"}, doConv).appendTo($(".click-glag").parent);});    if (typeof enableMacrons !== "undefined" && enableMacrons) $(function{$(" [ āēīōū ] ").click({"outputstyle": "macronsrule"}, doConv).appendTo($(".click-glag").parent);}); });