Module:el-translit

Από Βικιλεξικό
Μετάβαση στην πλοήγηση Πήδηση στην αναζήτηση

Documentation for this module may be created at Module:el-translit/τεκμηρίωση

-- Μεταγραμματισμός κατά ΕΛΟΤ 743-1
local p = {}

local tt = {
	["α"] = "a",  ["ά"] = "á",  ["β"] = "v",  ["γ"] = "g",  ["δ"] = "d",
	["ε"] = "e",  ["ζ"] = "z",  ["η"] = "ī",  ["ή"] = "ī́",  ["θ"] = "th",
	["ι"] = "i",  ["ί"] = "í",  ["ϊ"] = "ï",  ["ΐ"] = "ḯ",  ["κ"] = "k",  ["λ"] = "l",  ["μ"] = "m",
	["ν"] = "n",  ["ξ"] = "x",  ["ο"] = "o",  ["ό"] = "ó",  ["π"] = "p",
	["ρ"] = "r",  ["σ"] = "s",  ["ς"] = "s",
	["τ"] = "t",  ["υ"] = "y",  ["ύ"] = "ý",  ["ϋ"] = "ÿ",  ["ΰ"] = "ÿ́",  ["φ"] = "f",
	["χ"] = "ch", ["ψ"] = "ps",	["ω"] = "ṓ",  ["ώ"] = "ṓ",
	["Α"] = "A",  ["Β"] = "V",  ["Γ"] = "G",  ["Δ"] = "D",
	["Ε"] = "E",  ["Ζ"] = "Z",  ["Η"] = "Ī",  ["Ή"] = "Ī́",  ["Θ"] = "Th",
	["Ι"] = "I",  ["Í"] = "Ϊ", 	["Í"] = "Ϊ",  ["Κ"] = "K",  ["Λ"] = "L",  ["Μ"] = "M",
	["Ν"] = "N",  ["Ξ"] = "X",  ["Ο"] = "O",  ["Ό"] = "Ó",  ["Π"] = "P",
	["Ρ"] = "R",  ["Σ"] = "S",
	["Τ"] = "T",  ["Υ"] = "Y",	["Ύ"] = "Ý",  ["Ϋ"] = "Ÿ",  ["Φ"] = "F",
	["Χ"] = "Ch", ["Ψ"] = "Ps", ["Ω"] = "Ō",  ["Ώ"] = "Ṓ",
	[";"] = "?",  ["·"] = ";"
}

-- transliterates any words or phrases
function p.tr(text)
	if type(text) == "table" then text = text.args[1] end
	
	local gsub = mw.ustring.gsub
	local find = mw.ustring.find
	local acute = mw.ustring.char(0x301)
	local diaeresis = mw.ustring.char(0x308)
	local vowels = "[αΑεΕηΗιΙυΥοΟωΩ" .. acute .. diaeresis .. "]"
	
	text = mw.text.trim(text)
	text = mw.ustring.toNFD(text)
	text = mw.ustring.gsub(text, acute .. diaeresis, diaeresis .. acute)

	text = gsub(text, "([αεΑΕ])υ(.?)", -- αυ > au, ευ > eu, except ϋ
		function (vowel, following)
			if following ~= diaeresis then
				return tt[vowel] .. "u" .. following
			end
		end)
	
	text = gsub(text, "([οΟ])υ", {["ο"] = "ou", ["Ο"] = "Ou"})
	
	text = gsub(text, ".", tt)
	return text
end

return p