ข้ามไปเนื้อหา

มอดูล:el-translit

จาก วิกิพจนานุกรม พจนานุกรมเสรี

This module will transliterate ภาษากรีก text. It is also used to transliterate Cappadocian Greek, Pontic Greek, Tsakonian, and Thracian. 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:el-translit/testcases.

Functions

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",  ["χ"] = "ch", ["ψ"] = "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",
	["Ώ"] = "Ó",
	[";"] = "?",  ["·"] = ";"
}

-- transliterates any words or phrases
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