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:Purodha/common.js/altersyntran.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: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
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

  return null;
}