Module:el-translit-2

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

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

-- Μεταγραφή κατά ΕΛΟΤ 743-2 χωρίς διακριτικά όπως χρησιμοποιείται σε διαβατήρια και ταυτότητες της Ελλάδας
-- βλ. και https://www.passport.gov.gr/passports/GrElotConverter/GrElotConverter.html

local p = {}

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

-- 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, "([αΑεΕηΗ])υ(.?)", 
		function (vowel, following)
			if following == diaeresis then
				return tt[vowel] .. "y"
			end
			if following == " " or following == "" then -- υ > f στο τέλος λέξης
				return tt[vowel] .. "f" .. following
			end
			if find(following, "[βγδζλμνρΒΓΔΖΛΜΝΡαεηιυοωΑΕΗΙΥΟΩ]") then -- υ > v (αν ακολουθεί β, γ, δ, ζ, λ, μ, ν, ρ, φωνήεν)
				return tt[vowel] .. "v" .. following
			end
			if find(following, "[θκξπστφχψΘΚΞΠΣΤΦΧΨ]") then -- υ > f (αν ακολουθεί θ, κ, ξ, π, σ, τ, φ, χ, ψ)
				return tt[vowel] .. "f" .. following
			end
		end)

	text = gsub(text, "([οΟ])υ", {["ο"] = "ou", ["Ο"] = "Ou"})  -- ου > ou και όχι oy
	-- αφαίρεση τόνων και διαλυτικών
	text = gsub(text, diaeresis, "") 
	text = gsub(text, acute, "") 

	text = gsub(text, "(γ)(γ)", "ng")

	text = gsub(text, "(Γ)(Γ)", "NG")

	text = gsub(text, "(γ)(ξ)", "nx")

	text = gsub(text, "(Γ)(Ξ)", "NX")

	text = gsub(text, "(γ)(χ)", "nch")

	text = gsub(text, "(Γ)(Χ)", "NCH")

	text = gsub(text, "(.?)μπ", 
		function (before)
			if before ~= "" and before ~= " " and before ~= "-" then
				return before .. "mp"
			end
			return before .. "b"
		end)
	text = gsub(text, "(.?)Μπ", 
		function (before)
			if before ~= "" and before ~= " " and before ~= "-" then
				return before .. "Mp"
			end
			return before .. "B"
		end)	

	text = gsub(text, "mp(.?)", 
		function (after)
			if after == "" or after == " " or after == "-" then
				return "b" .. after
			end
		end)	
		
	text = gsub(text, ".", tt)
	return text

end

return p