As an anonymous user, you can only add new data. If you would like to also modify existing data, please create an account and indicate your languages on your user page.

User:Kipcool/common.js/wiktimport.js

From OmegaWiki
Jump to: navigation, search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences
if ( (wgAction == "edit") && ( wgCanonicalNamespace == "DefinedMeaning" ) && ( $(".wld_lang_filter_off").length > 0 ) ) {
  // Create portlet link
  $("#p-cactions").find("ul:first").append('<li id="ca-wiktportlet">importWikt</li>');
 
  $("li#ca-wiktportlet").css('padding','0.5em').css('font-size','small').css('color','blue');
  $("li#ca-wiktportlet").click( function () {
 
    // create some div, with the interface
    wrappingDiv = document.createElement('div');
    $(wrappingDiv).css('position','fixed').css('top','0px').css('right','0px').css('width','300px')
      .css('z-index','105').css('background-color','white').css('border-style','solid');
 
    $(wrappingDiv).append('<h2>Semiautomatic import tool</h2>');
    $(wrappingDiv).append('<textarea id="wiktimport-input" rows="10" cols="9"></textarea>');
    $(wrappingDiv).append('<div id="wiktimport-clickme"><b> ! Start Importing ! </b></div>');
    $(wrappingDiv).append('<div id="wiktimport-output"></div>');
    // display it
    document.getElementById('mw-content-text').appendChild( wrappingDiv );
 
    $('#wiktimport-output').css('overflow-y','scroll').css('max-height','300px');
    $('#wiktimport-clickme').css('cursor','pointer').css('text-align','center');
    $('#wiktimport-clickme').click( function () {
      // start parsing the wiki-formatted textarea
      var textToParse = $('#wiktimport-input').val();
      var regTranslation = /\{\{tr?a?d?.?\|([^|]+)\|([^|}]+)[|}]/g ;
      while ( (arrayResult = regTranslation.exec(textToParse)) !== null) {
        codelang = arrayResult[1];
        transl = arrayResult[2];
 
        OWlang = getOWLangIdAndName( codelang );
        if ( OWlang ) {
          // codelang is known.
          // Are there already translations in that language in the page?
          if ( $('div.expand-syntrans').find('td[langid="' + OWlang[0] + '"]').length > 0 ) {
            // there are already translations in that language
            // check if there is a translation with exactly the same word
            var sameTransList = $('td[langid="' + OWlang[0] + '"]').next().children('a')
              .filter(function() { return $(this).text() == transl });
            if ( $(sameTransList).length > 0 ) {
              // this translation already exists
            } else {
              $('#wiktimport-output').append(
                '<p>There are already translations in ' + codelang + ' (' + OWlang[1]
                + ') but not "<b>' + transl + '</b>" please add manually if correct</p>');
            }
          } else {
            // no translation in that lang yet: add the translation
            // id of last 'tr' is something like add-dm-269-syntrans
            var idaddtr = $('div.expand-syntrans').find('tr:last').attr('id');
            // the id we want is something of the form add-dm-269-syntrans-exp-language
            var idaddlang = idaddtr + '-exp-language';
            // add an empty row before putting some values
            addEmptyRow(idaddtr);
            // enter the lang id
            $('#' + idaddlang).val( OWlang[0] );
            // display a language name
            $('#' + idaddlang + '-suggest-link').html(OWlang[1]);
            // add the translation
            $('#' + idaddtr + '-exp-spelling').val(transl);
          }
        } else {
          $('#wiktimport-output').append('<p>no known OW equivalent for code ' + codelang + ' "<b>' + transl + '</b>"</p>');
        }
      }
      $('#wiktimport-input').val('');
    });
  });
} // wgAction == edit
 
function getOWLangIdAndName( WiktId ) {
  // returns the OW lang_id and a name for a given WiktId
  switch ( WiktId ) {
    case "ab": return ["250", "Abkhaz"];
    case "abq": return ["417", "Abaza"];
    case "ace": return ["330", "Acehnese"];
    case "ady": return ["515", "Adyghe"];
    case "af": return ["125", "Afrikaans"];
    case "ain": return ["480", "Ainu"];
    case "ale": return ["539", "Aleut"];
    case "alt": return ["471", "Southern Altai"];
    case "am": return ["276", "Amharic"];
    case "an": return ["141", "Aragonese"];
    case "ang": return ["263", "Old English"];
    case "apy": return ["550", "Apalaí"];
    case "ar": return ["120", "Arabic"];
    case "ary": return ["423", "Moroccan Arabic"];
    case "arz": return ["292", "Egyptian Arabic"];
    case "as": return ["249", "Assamese"];
    case "ast": return ["195", "Asturian"];
    case "aus-dar": return ["520", "Darkinjung"];
    case "av": return ["566", "Avar"];
    case "ay": return ["395", "Aymara"];
    case "ba": return ["227", "Bashkir"];
    case "bal": return ["270", "Baluchi"];
    case "ban": return ["454", "Balinese"];
    case "be": return ["147", "Belarusian"];
    case "bg": return ["84", "Bulgarian"];
    case "bi": return ["365", "Bislama"];
    case "bjn": return ["455", "Banjarese"];
    case "bn": return ["185", "Bengali"];
    case "bo": return ["544", "Standard Tibetan"];
    case "bqi": return ["290", "Bakhtiari"];
    case "br": return ["182", "Breton"];
    case "brg": return ["551", "Baure"];
    case "bs": return ["288", "Bosnian"];
    case "bua": return ["469", "Buryat"];
    case "bug": return ["456", "Buginese"];
    case "bxr": return ["469", "Russia Buryat"];
    case "ca": return ["117", "Catalan"];
    case "ccc": return ["379", "Chamicuro"];
    case "ce": return ["287", "Chechen"];
    case "chr": return ["228", "Cherokee"];
    case "cjs": return ["470", "Shor"];
    case "ckb": return ["260", "Sorani"];
    case "co": return ["220", "Corsican"];
    case "crh": return ["226", "Crimean Tatar"];
    case "cs": return ["90", "Czech"];
    case "csb": return ["148", "Kashubian"];
    case "cu": return ["335", "Old Church Slavonic"];
    case "cv": return ["279", "Chuvash"];
    case "cy": return ["153", "Welsh"];
    case "da": return ["103", "Danish"];
    case "dak": return ["553", "Dakota"];
    case "de": return ["101", "German"];
    case "dgr": return ["440", "Dogrib"];
    case "dlg": return ["453", "Dolgan"];
    case "dlm": return ["484", "Dalmatian"];
    case "dsb": return ["205", "Lower Sorbian"];
    case "dv": return ["248", "Dhivehi"];
    case "ee": return ["118", "Ewe"];
    case "egl": return ["523", "Emilian"];
    case "el": return ["105", "Greek"];
    case "en": return ["85", "English"];
    case "eo": return ["113", "Esperanto"];
    case "es": return ["87", "Spanish"];
    case "esh": return ["504", "Eshtehardi"];
    case "et": return ["98", "Estonian"];
    case "eu": return ["96", "Basque"];
    case "fa": return ["142", "Persian"];
    case "fi": return ["99", "Finnish"];
    case "fj": return ["524", "Fijian"];
    case "fo": return ["213", "Faroese"];
    case "fr": return ["86", "French"];
    case "frm": return ["333", "Middle French"];
    case "fro": return ["332", "Old French"];
    case "fur": return ["505", "Friulian"];
    case "fy": return ["183", "West Frisian"];
    case "ga": return ["166", "Irish"];
    case "gag": return ["441", "Gagauz"];
    case "gd": return ["262", "Scottish Gaelic"];
    case "gl": return ["199", "Galician"];
    case "gmh": return ["327", "Middle High German"];
    case "gml": return ["491", "Middle Low German"];
    case "gn": return ["380", "Guarani"];
    case "goh": return ["328", "Old High German"];
    case "grc": return ["174", "Ancient Greek"];
    case "gsw": return ["169", "Alemannic German"];
    case "gu": return ["162", "Gujarati"];
    case "gv": return ["224", "Manx"];
    case "hai": return ["570", "Haida"];
    case "haw": return ["286", "Hawaiian"];
    case "he": return ["106", "Hebrew"];
    case "hi": return ["163", "Hindi"];
    case "hil": return ["341", "Hiligaynon"];
    case "hop": return ["391", "Hopi"];
    case "hsb": return ["204", "Upper Sorbian"];
    case "ht": return ["334", "Haitian Creole"];
    case "hu": return ["102", "Hungarian"];
    case "hy": return ["123", "Armenian"];
    case "ia": return ["210", "Interlingua"];
    case "iba": return ["536", "Iban"];
    case "id": return ["165", "Indonesian"];
    case "ig": return ["189", "Igbo"];
    case "ilo": return ["278", "Ilocano"];
    case "io": return ["131", "Ido"];
    case "is": return ["193", "Icelandic"];
    case "it": return ["100", "Italian"];
    case "ja": return ["112", "Japanese"];
    case "jbo": return ["242", "Lojban"];
    case "jv": return ["231", "Javanese"];
    case "ka": return ["124", "Georgian"];
    case "kaw": return ["538", "Old Javanese"];
    case "ket": return ["554", "Ket"];
    case "kjh": return ["443", "Khakas"];
    case "kk": return ["191", "Kazakh"];
    case "kl": return ["356", "Kalaallisut"];
    case "kld": return ["521", "Gamilaraay"];
    case "km": return ["139", "Khmer"];
    case "kmr": return ["357", "Kurmanji"];
    case "kn": return ["181", "Kannada"];
    case "ko": return ["138", "Korean"];
    case "kpy": return ["411", "Koryak"];
    case "krc": return ["343", "Karachay-Balkar"];
    case "kri": return ["483", "Krio"];
    case "krl": return ["533", "Karelian"];
    case "kum": return ["445", "Kumyk"];
    case "kv": return ["444", "Komi"];
    case "kw": return ["253", "Cornish"];
    case "ky": return ["229", "Kyrgyz"];
    case "la": return ["238", "Latin"];
    case "lad": return ["525", "Ladino"];
    case "lb": return ["243", "Luxembourgish"];
    case "lez": return ["378", "Lezgi"];
    case "liv": return ["506", "Livonian"];
    case "lkt": return ["532", "Lakota"];
    case "ln": return ["202", "Lingala"];
    case "lo": return ["272", "Lao"];
    case "lt": return ["150", "Lithuanian"];
    case "ltg": return ["336", "Latgalian"];
    case "lus": return ["531", "Mizo"];
    case "lv": return ["143", "Latvian"];
    case "mad": return ["457", "Madurese"];
    case "mdf": return ["277", "Moksha"];
    case "mg": return ["374", "Malagasy"];
    case "mhn": return ["557", "Mòcheno"];
    case "mhr": return ["160", "Eastern Mari"];
    case "mi": return ["246", "Maori"];
    case "min": return ["460", "Minangkabau"];
    case "mk": return ["209", "Macedonian"];
    case "ml": return ["217", "Malayalam"];
    case "mn": return ["329", "Mongolian"];
    case "moe": return ["513", "Montagnais"];
    case "mr": return ["110", "Marathi"];
    case "mrc": return ["463", "Maricopa"];
    case "ms": return ["222", "Malay"];
    case "mt": return ["207", "Maltese"];
    case "mvi": return ["556", "Miyako"];
    case "mwl": return ["234", "Mirandese"];
    case "mwp": return ["522", "Kala Lagaw Ya"];
    case "my": return ["275", "Burmese"];
    case "myv": return ["271", "Erzya"];
    case "mzn": return ["527", "Mazanderani"];
    case "na": return ["465", "Nauruan"];
    case "nap": return ["109", "Neapolitan"];
    case "naq": return ["530", "Nama"];
    case "nay": return ["448", "Ngarrindjeri"];
    case "nb": return ["95", "Bokmal"];
    case "ne": return ["188", "Nepali"];
    case "nia": return ["461", "Nias"];
    case "nij": return ["537", "Ngaju"];
    case "nl": return ["89", "Dutch"];
    case "nmn": return ["562", "ǃXóõ"];
    case "nn": return ["200", "Nynorsk"];
    case "nnt": return ["447", "Nanticoke"];
    case "no": return ["95", "Bokmal"];
    case "nov": return ["239", "Novial"];
    case "nv": return ["184", "Navajo"];
    case "nwy": return ["449", "Nottoway-Meherrin"];
    case "ny": return ["349", "Chichewa"];
    case "oc": return ["273", "Occitan"];
    case "ood": return ["467", "O'odham"];
    case "or": return ["377", "Oriya"];
    case "os": return ["255", "Ossetian"];
    case "osx": return ["516", "Old Saxon"];
    case "ota": return ["362", "Ottoman Turkish"];
    case "pad": return ["558", "Paumarí"];
    case "pap": return ["427", "Papiamentu"];
    case "pim": return ["450", "Powhatan"];
    case "pjt": return ["241", "Pitjantjatjara"];
    case "pl": return ["93", "Polish"];
    case "pms": return ["114", "Piedmontese"];
    case "pot": return ["392", "Potawatomi"];
    case "ppl": return ["540", "Pipil"];
    case "pro": return ["389", "Old Provencal"];
    case "pt": return ["94", "Portugese"];
    case "rm": return ["244", "Romansch"];
    case "rap": return ["331", "Rapa Nui"];
    case "ro": return ["133", "Romanian"];
    case "roa-grn": return ["494", "Guernésiais"];
    case "roa-jer": return ["462", "Jersiais"];
    case "rom": return ["360", "Romani"];
    case "ru": return ["88", "Russian"];
    case "rup": return ["488", "Aromanian"];
    case "rw": return ["526", "Kinyarwanda"];
    case "sa": return ["215", "Sanskrit"];
    case "sah": return ["436", "Yakut"];
    case "sas": return ["534", "Sasak"];
    case "sce": return ["569", "Dongxiang"];
    case "scn": return ["140", "Sicilian"];
    case "sco": return ["284", "Scots"];
    case "sdc": return ["543", "Sassarese Sardinian"];
    case "sdn": return ["542", "Gallurese Sardinian"];
    case "se": return ["400", "Northern Sami"];
    case "sga": return ["342", "Old Irish"];
    case "shn": return ["535", "Shan"];
    case "si": return ["258", "Sinhalese"];
    case "sia": return ["519", "Akkala Sami"];
    case "sjd": return ["555", "Kildin Sami"];
    case "sk": return ["97", "Slovak"];
    case "sl": return ["92", "Slovenian"];
    case "sm": return ["280", "Samoan"];
    case "sma": return ["294", "Southern Sami"];
    case "sms": return ["482", "Skolt Sami"];
    case "so": return ["237", "Somali"];
    case "sq": return ["354", "Albanian"];
    case "sro": return ["541", "Campidanese Sardinian"];
    case "st": return ["355", "Sotho"];
    case "su": return ["252", "Sundanese"];
    case "sv": return ["91", "Swedish"];
    case "sw": return ["145", "Swahili"];
    case "syc": return ["339", "Syriac"];
    case "szl": return ["267", "Silesian"];
    case "ta": return ["164", "Tamil"];
    case "tab": return ["559", "Tabassaran"];
    case "te": return ["158", "Telugu"];
    case "tg": return ["152", "Tadjik"];
    case "th": return ["130", "Thai"];
    case "ti": return ["261", "Tigrinya"];
    case "tk": return ["388", "Turkmen"];
    case "tl": return ["206", "Tagalog"];
    case "tn": return ["403", "Tswana"];
    case "to": return ["289", "Tongan"];
    case "tpi": return ["282", "Tok Pisin"];
    case "tr": return ["137", "Turkish"];
    case "tt": return ["194", "Tatar"];
    case "tta": return ["451", "Tutelo"];
    case "tvl": return ["529", "Tuvaluan"];
    case "twf": return ["431", "Taos"];
    case "txb": return ["561", "Tocharian B (Latin script)"];
    case "ty": return ["472", "Tahitian"];
    case "tyv": return ["452", "Tuvan"];
    case "udm": return ["281", "Udmurt"];
    case "ug": return ["433", "Uyghur"];
    case "uk": return ["116", "Ukrainian"];
    case "ur": return ["186", "Urdu"];
    case "uz": return ["370", "Uzbek"];
    case "vec": return ["115", "Venetian"];
    case "vep": return ["509", "Veps"];
    case "vi": return ["144", "Vietnamese"];
    case "vo": return ["221", "Volapük"];
    case "vro": return ["295", "Võro"];
    case "wa": return ["192", "Walloon"];
    case "wbp": return ["432", "Warlpiri"];
    case "xal": return ["442", "Kalmyk"];
    case "xcl": return ["361", "Old Armenian"];
    case "xto": return ["560", "Tocharian A (Latin script)"];
    case "yi": return ["240", "Yiddish"];
    case "yua": return ["325", "Yucatec Maya"];
    case "zdj": return ["571", "Ngazidja Comorian"];
    case "zu": return ["214", "Zulu"];
  } // switch
  return null;
}