User:Dunee/modern.js

From translatewiki.net
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.
function createSpecCharBox() {
    var boxDiv = document.createElement("div");

    var innerText = '<div id="specChar" style="margin-top:5px;border-width:1px;border-style:solid;border-color:#aaaaaa;padding:3px;"><a href="http://hu.wikipedia.org/wiki/Wikipédia:Különleges_karakterek" title="Wikipédia:Különleges karakterek">Különleges karakterek:</a>:' +
    "<a href=\"javascript:insertTags('„','','')\">„</a> ·" +
    "<a href=\"javascript:insertTags('”','','')\">“</a> ·" +
    "<a href=\"javascript:insertTags('–','','')\">– <small>(gondolatjel)</small></a> ·" +
    "<a href=\"javascript:insertTags('„','”','')\">„”</a> ·" +
    "<a href=\"javascript:insertTags('»','«','')\">»«</a> ·" +
    "<a href=\"javascript:insertTags('²','','')\">²</a> " +
    "<a href=\"javascript:insertTags('³','','')\">³</a> " +
    "<a href=\"javascript:insertTags('½','','')\">½</a> ·" +
    "<a href=\"javascript:insertTags('€','','')\">€</a> ·" +
    "<a href=\"javascript:insertTags('í','','')\">í</a> ·" +
    "<a href=\"javascript:insertTags('[[',']]','')\">[[]]</a> " +
    "<a href=\"javascript:insertTags('|','','')\">|</a> " +
    "<a href=\"javascript:insertTags('{{','}}','')\">{{}}</a> ·" +
    "<a href=\"javascript:fixLatin1Chars()\"><small>kalapos</small></a> ·" +
    "<a href=\"javascript:fixHungarianQuotes()\"><small>idézőjel</small></a> ·" +
    "</div>"; 

   boxDiv.innerHTML = innerText;   
   return boxDiv;
}

function replaceRegexp(replaceWhat, replaceWith, modifiers) {
        if (modifiers == null) {
modifiers = "";
}
var txtarea = document.editform.wpTextbox1;
// IE
if(document.selection  && !is_gecko) {
var theSelection = document.selection.createRange().text;
txtarea.focus();
theSelection = theSelection.replace(replaceWhat, replaceWith);
document.selection.createRange().text = theSelection;
// Mozilla
} else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
                // This is probably more complicated than it needs to be
  var startPos = txtarea.selectionStart;
var endPos = txtarea.selectionEnd;
var scrollTop=txtarea.scrollTop;

var pattern = new RegExp(replaceWhat, modifiers);
var myText = (txtarea.value).replace(pattern, replaceWith);

txtarea.value = myText;

txtarea.focus();

var cPos=startPos;
txtarea.selectionStart=cPos;
txtarea.selectionEnd=cPos;
txtarea.scrollTop=scrollTop;

// All others
} else {
alert("No support for this browser yet");
return;
}
// reposition cursor if possible
if (txtarea.createTextRange) txtarea.caretPos = document.selection.createRange().duplicate();
}

// Replaces Latin 1 chars with properly encoded Hungarian Latin 2 equivalents
function fixLatin1Chars() {
replaceRegexp("Ő", "\u0150", "g");
replaceRegexp("Ű", "Ű", "g");
replaceRegexp("ő", "ő", "g");
        replaceRegexp("ő", "ő", "g");
replaceRegexp("ű", "ű", "g");
replaceRegexp("ű", "ű", "g");
}


// Replaces English style "" quotes with Hungarian „”
function fixHungarianQuotes() {
replaceRegexp("\"([^\"]*)\"", "„$1”", "mg");
}

// Translate dates from English format to Hungarian
// Currently it only handles linkified dates
function translateDatesEnHu() {
var months = [
["January", "január"],
["February", "február"],
["March", "március"],
["April", "április"],
["May", "május"],
["June", "június"],
["July", "július"],
["August", "augusztus"],
["September", "szeptember"],
["October", "október"],
["November", "november"],
["December", "december"]
];

for (var i = 0; i < months.length; i++) {
var enMonth = months[i][0];
var huMonth = months[i][1];
// alert("Replacing " + enMonths + " with " + huMonth);
// Replace "[[November 15]], [[2005]]" with "[[2005]]. [[november 15]]."
// $1 = "15", $2 = "2005"
replaceRegexp("\\[\\[" + enMonth + " (\\d+)\\]\\],?\\s*\\[\\[(\\d{4})\\]\\]", "[[$2]]. [[" + huMonth + " $1]].", "gm");
}
}

// Translates an English country infobox to Hungarian
function translateInfoboxCountryEnHu() {
var dict = [
["Infobox Country", "Országtáblázat"],
["Infobox_Country", "Országtáblázat"],
["native_name", "teljesnév"],
["image_flag", "zászlókép"],
["image_coat", "címerkép"],
["image_map", "elhelyezkedéskép"],
["national_motto", "mottó"],
["national_anthem", "himnusz"],
["official_languages", "hivatalos_nyelvek"],
["capital", "főváros"],
["capitals_coordinates.*\$", ""],
["government_type", "államforma"],
["leader_titles", "államfő"],
["leader_names", "jelenlegiállamfő"],
["largest_city", "legnagyobbváros"],
["area", "terület"],
["area_rank", "területrangsorban"],
["area_magnitude.*\$", ""],
["percent_water", "víz"],
["population_estimate", "népesség"],
["population_estimate_year", "népesség_dátum"],
["population_estimate_rank", "népességrangsorban"],
["population_census.*\$", ""],
["population_census_year.*\$", ""],
["population_density", "népsűrűség"],
["population_density_rank", "népsűrűségrangsorban"],
["GDP_PPP_year", "GDP_dátum"],
["GDP_PPP", "GDP"],
["GDP_PPP_rank", "GDPrangsorban"],
["GDP_PPP_per_capita", "egyfőrejutóGDP"],
["GDP_PPP_per_capita_rank", "egyfőrejutóGDPrangsorban"],
["sovereignty_type.*\$", ""],
["established_events", "függetlenségesemény"],
["established_dates", "függetlenségdátuma"],
["currency", "pénznem"],
["currency_code", "pénznemrövidítés"],
["time_zone", "időzóna"],
["utc_offset.*\$", ""],
["time_zone_DST", "NYISZ"],
["utc_offset_DST", ""],
["cctld", "tld"],
["calling_code", "hívókód"],
["footnotes", "lábjegyzet"],
["Federal republic", "szövetségi köztársaság"],
["", ""],
["", ""],
["", ""],
["", ""],
["", ""],
["", ""],
["", ""],
["", ""],
["", ""],
["", ""],
["", ""],
["Declared", "kikiáltása"], 
["Recognised", "elismerése"], 
["English language", "angol nyelv"], 
["French language", "francia nyelv"], 
["Spanish language", "spanyol nyelv"], 
["German language", "német nyelv"], 
["million", "millió"]
];

for (var i = 0; i < dict.length; i++) {
var pair = dict[i];
replaceRegexp(pair[0], pair[1]);
}

        // In Hungarian, we use &nbsp; for separating digits instead of ,
        replaceRegexp("(\\d+?),(\\d+?)", "$1&nbsp;$2", "g");
// Decimal separator "." -> ","
replaceRegexp("(\\d+?)\\.(\\d+?)", "$1,$2", "g");

// In rankings, get rid of "st", "th", etc.
replaceRegexp("(\\d+?)st", "$1", "g");
replaceRegexp("(\\d+?)nd", "$1", "g");
replaceRegexp("(\\d+?)rd", "$1", "g");
replaceRegexp("(\\d+?)th", "$1", "g");

// Get rid of $ prefix in GDP
replaceRegexp("\\$(\\d+?)", "$1", "g")


        // Get rid of whitespace before "="
        replaceRegexp("(\\s+)=", " =", "g");

        translateDatesEnHu();
}

// Initializes edit box
function myOnloadHook() {
  // Textarea positioning doesn't work in Opera
  if (is_opera) return;

  // Find the element that comes right after the special character box
  var copywarn = document.getElementById('editpage-copywarn');
  if (copywarn == null) {
      // Not in edit mode
      return;
  }
  var specCharBox = createSpecCharBox();
  var par = copywarn.parentNode;

  par.insertBefore(specCharBox, copywarn); 
}

if (window.addEventListener) window.addEventListener("load", myOnloadHook, false);
else if (window.attachEvent) window.attachEvent("onload", myOnloadHook);