User:Erutuon/scripts/phonemicGreekTransliteration.js

Note: You may have to bypass your browser’s cache to see the changes. In addition, after saving a sitewide CSS file such as MediaWiki:Common.css, it will take 5-10 minutes before the changes take effect, even if you clear your cache.

  • Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
  • Konqueror and Chrome: click Reload or press F5;
  • Opera: clear the cache in Tools → Preferences;
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

/*	Modifies Greek transliteration to be more phonemic: voiced stops with dot
	above, ου as u, all vowels pronounced /i/ as i, no double consonants,
	diaeresis sometimes removed.
	
	The dot above is weird.
	
	Greek		default		modified
	μου			mou			mu
	οι πολλοί	oi polloí	i polí
	βοήθεια		voḯtheia	voíthia
	πολύ		polý		polí
	είναι		eínai		íne
	αμπέλι		ámpeli		aḃéli
	άντρας		ántras		áḋras
	φεγγάρι		fengári		feġári
	
	I'd like to distinguish fricative d from stop d, but at the moment the two
	aren't distinguished at the beginning of a word!
	
	δύο			dýo			(fricative d)
	ντετέκτιβ	detéktiv	(stop d)
*/

var dotAbove = String.fromCharCode(0x307);

$("[lang=el-Latn]").html(
	function (index, element) {
		return element
			// At beginning of word, b represents the stop μπ.
			.replace(/((?:^|[ -])[Bb])/g, "$1" + dotAbove)
			.replace(
				/([GgNn])[KkGg]/g,
				function (wholeMatch, firstLetter) {
					if ( firstLetter.toUpperCase() === firstLetter ) {
						return "G" + dotAbove;
					} else {
						return "g" + dotAbove;
					}
				})
			.replace(
				/([Nn])[TtDd](?!h)/g,
				function (wholeMatch, firstLetter) {
					if ( firstLetter.toUpperCase() === firstLetter ) {
						return "D" + dotAbove;
					} else {
						return "d" + dotAbove;
					}
				})
			.replace(
				/([Mm])[PpBb](?![TtSs])/g,
				function (wholeMatch, firstLetter) {
					if ( firstLetter.toUpperCase() === firstLetter ) {
						return "B" + dotAbove;
					} else {
						return "b" + dotAbove;
					}
				})
			.normalize("NFD")
			.replace(
				/([AaEeOoUu])i(\u0308?)/g, // U+308, combining diaeresis
				function (wholeMatch, firstLetter, diaeresis) {
					if (diaeresis !== "") { // If diaeresis is present, remove it.
						return firstLetter + "i";
					}
					var capital = firstLetter.toUpperCase() === firstLetter;
					if ( firstLetter === "a" ) {
						if ( capital ) {
							return "E";
						} else {
							return "e";
						}
					} else {
						if ( capital ) {
							return "I";
						} else {
							return "i";
						}
					}
				})
			.replace(/y/g, "i")
			.replace(/Y/g, "I")
			.replace(/ou/g, "u")
			.replace(/([bgdzklmnprstfv])\1/g, "$1")
			.replace(/tz/g, "dz")
			.replace(/x/g, "ks")
			.normalize("NFC");
	});