Pumunta sa nilalaman

Module:grc-translit

Mula Wiksiyonaryo

This module will transliterate Wikang Ancient Greek text. It is also used to transliterate Oscan, Sicel, Thracian, Bactrian, Dacian, Galatian, Alanic, Elymian, Ancient Macedonian, Phrygian, at Punic. The module should preferably not be called directly from templates or other modules. To use it from a template, use {{xlit}}. Within a module, use Module:languages#Language:transliterate.

For testcases, see Module:grc-translit/testcases.

Functions

[baguhin]
tr(text, lang, sc)
Transliterates a given piece of text written in the script specified by the code sc, and language specified by the code lang.
When the transliteration fails, returns nil.

local export = {}

local tt = {
	["α"] = "a",  ["ά"] = "á",  ["ὰ"] = "à", ["ᾶ"] = "ã", ["β"] = "v",  
	["γ"] = "g",  ["δ"] = "d", ["ε"] = "e",  ["έ"] = "é",  ["ὲ"] = "è", 
	["ζ"] = "z",  ["η"] = "i",  ["ή"] = "í", ["ὴ"] = "ì", ["ῆ"] = "ẽ",
	["θ"] = "th", ["ι"] = "i",  ["ί"] = "í",  ["ὶ"] = "ì",  ["ῖ"] = "ĩ",
	["κ"] = "k",  ["λ"] = "l",  ["μ"] = "m",  ["ν"] = "n",  ["ξ"] = "x",
	["ο"] = "o",  ["ό"] = "ó",  ["ὸ"] = "ò", ["π"] = "p",  ["ρ"] = "r",  
	["σ"] = "s", ["ς"] = "s",  ["τ"] = "t",  ["υ"] = "y",  ["ύ"] = "ý",  
	["ὺ"] = "ỳ", ["ῦ"] = "ỹ",  ["φ"] = "f",  ["χ"] = "kh", ["ψ"] = "ps",
	["ω"] = "o", ["ώ"] = "ó", ["ῶ"] = "õ",
	["Α"] = "A",  ["Ά"] = "Á",  ["Ὰ"] = "À", ["Β"] = "V",  ["Γ"] = "G", 
	["Δ"] = "D", ["Ε"] = "E",  ["Έ"] = "É",  ["Ὲ"] = "È", ["Ζ"] = "Z",  
	["Η"] = "I",  ["Ή"] = "Í", ["Ὴ"] = "Ì", ["Θ"] = "Th", ["Ι"] = "I",  
	["Ί"] = "Í",  ["Ὶ"] = "Ì", ["Κ"] = "K",  ["Λ"] = "L", ["Μ"] = "M",  
	["Ν"] = "N",  ["Ξ"] = "X",  ["Ο"] = "O",  ["Ό"] = "Ó", ["Ὸ"] = "Ò", 
	["Π"] = "P",  ["Ρ"] = "R",  ["Σ"] = "S",  ["Τ"] = "T",  ["Υ"] = "Y", 
	["Ύ"] = "Ý",  ["Ὺ"] = "Ỳ", ["Φ"] = "F",  ["Χ"] = "Ch", ["Ψ"] = "Ps", 
	["Ω"] = "O", ["Ώ"] = "Ó",
	[";"] = "?",  ["·"] = ";"
}

-- nag tatransliterate ng salita o parirala
function export.tr(text, lang, sc)
	local gsub = mw.ustring.gsub

	text = gsub(text, "([αεηΑΕΗ]υ)([αάεέηήιίϊΐοόυύϋΰωώβγδζλμνρ])",
		function(a, b)
			local t = {["αυ"] = "av", ["ευ"] = "ev", ["ηυ"] = "iv",
					   ["Αυ"] = "Av", ["Ευ"] = "Ev", ["Ηυ"] = "Iv"}
			return (t[a] .. b)
		end)
	text = gsub(text, "([αεηΑΕΗ]ύ)([αάεέηήιίϊΐοόυύϋΰωώβγδζλμνρ])",
		function(a, b)
			local t = {["αύ"] = "áv", ["εύ"] = "év", ["ηύ"] = "ív",
					   ["Αύ"] = "Áv", ["Εύ"] = "Év", ["Ηύ"] = "Ív"}
			return (t[a] .. b)
		end)
	text = gsub(text, "([αεηΑΕΗ]υ)([θκξπσςτφχψ])",
		function(a, b)
			local t = {["αυ"] = "af", ["ευ"] = "ef", ["ηυ"] = "if",
					   ["Αυ"] = "Af", ["Ευ"] = "Ef", ["Ηυ"] = "If"}
			return (t[a] .. b)
		end)
	text = gsub(text, "([αεηΑΕΗ]ύ)([θκξπσςτφχψ])",
		function(a, b)
			local t = {["αύ"] = "áf", ["εύ"] = "éf", ["ηύ"] = "íf",
					   ["Αύ"] = "Áf", ["Εύ"] = "Éf", ["Ηύ"] = "Íf"}
			return (t[a] .. b)
		end)
	text = gsub(text, "[αεηΑΕΗ]υ$",
				{["αυ"] = "af", ["ευ"] = "ef", ["ηυ"] = "if",
				 ["Αυ"] = "Af", ["Ευ"] = "Ef", ["Ηυ"] = "If"})
	text = gsub(text, "[αεηΑΕΗ]ύ$",
				{["αύ"] = "áf", ["εύ"] = "éf", ["ηύ"] = "íf",
				 ["Αύ"] = "Áf", ["Εύ"] = "Éf", ["Ηύ"] = "Íf"})
	text = gsub(text, "[οΟ][υύ]",
				{["ου"] = "ou", ["ού"] = "oú",
				 ["Ου"] = "Ou", ["Ού"] = "Oú"})

	text = gsub(text, "^[μΜ]π", {["μπ"] = "b", ["Μπ"] = "B"})
	text = gsub(text, " [μΜ]π", {[" μπ"] = " b", [" Μπ"] = " B"})
	text = gsub(text, "-[μΜ]π", {["-μπ"] = "-b", ["-Μπ"] = "-B"})
	
	text = gsub(text, "^[νΝ]τ", {["ντ"] = "d", ["Ντ"] = "D"})
	text = gsub(text, " [νΝ]τ", {[" ντ"] = " d", [" Ντ"] = " D"})
	text = gsub(text, "-[νΝ]τ", {["-ντ"] = "-d", ["-Ντ"] = "-D"})

	text = gsub(text, "γ([γκξχ])", "n%1")

	text = gsub(text, ".", tt)

	return text
end

return export