Salta al contegnùo

Modulo:el-trans

Da Wikisionario

La documentazione per questo modulo può essere creata in Modulo:el-trans/man

local p = {}

local tt = {
	["α"] = "a",  ["β"] = "v",  ["γ"] = "g",  ["δ"] = "d",
	["ε"] = "e",  ["ζ"] = "z",  ["η"] = "i",  ["θ"] = "th",
	["ι"] = "i",  ["κ"] = "k",  ["λ"] = "l",  ["μ"] = "m",
	["ν"] = "n",  ["ξ"] = "x",  ["ο"] = "o",  ["π"] = "p",
	["ρ"] = "r",  ["σ"] = "s",  ["ς"] = "s",
	["τ"] = "t",  ["υ"] = "i",  ["φ"] = "f",
	["χ"] = "kh", ["ψ"] = "ps",	["ω"] = "o",
	["Α"] = "A",  ["Β"] = "V",  ["Γ"] = "G",  ["Δ"] = "D",
	["Ε"] = "E",  ["Ζ"] = "Z",  ["Η"] = "I",  ["Θ"] = "Th",
	["Ι"] = "I",  ["Κ"] = "K",  ["Λ"] = "L",  ["Μ"] = "M",
	["Ν"] = "N",  ["Ξ"] = "X",  ["Ο"] = "O",  ["Π"] = "P",
	["Ρ"] = "R",  ["Σ"] = "S",
	["Τ"] = "T",  ["Υ"] = "I",	["Φ"] = "F",
	["Χ"] = "Kh", ["Ψ"] = "Ps", ["Ω"] = "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, "([βκπτ])([βκπτ])", -- no dopie ββ, κκ, ππ, ττ
		function (cons, doble)
			if cons == doble then
				return cons
			end
		end)
	
	text = gsub(text, "(.?)([γΓ]ι)", -- γι (inisial) > i
		function(before, current)
			if before == "" or before == " " or before == "-" then
				return current == "Γι" and "I" or "i"
			end
		end)
	
	text = gsub(text, "γγ(.)", -- γγ > ng(u)
		function(following)
			if find(following, "[ει]") then
				return "ngu" .. following
			end
			return "ng" .. following
		end)
	
	text = gsub(text, "(.?)([γΓ])κ(.)", -- γκ (inisial, mediale) > (n)g(u)
		function(before, gamma, following)
			local ucase = gamma == "Γ"
			local cons = ucase and "G" or "g"
			if before ~= "" and before ~= " " and before ~= "-" then
				cons = ucase and "Ng" or "ng"
			end
			if find(following, "[ει]") then
				return before .. cons .. "u" .. following
			end
			return before .. cons .. following
		end)
	
	text = gsub(text, "γ([ξχ])", "n%1")
	
	text = gsub(text, "μβ", "mb")
	
	text = gsub(text, "(.?)([μΜ])π", -- μπ (inisial o rare consonanti, mediali) > (m)b
		function(before, mi)
			local ucase = mi == "Μ"
			if before == "" or before == " " or before == "-" or not find(before, vowels) then
				return before .. (ucase and "B" or "b")
			end
			return before .. "mb"
		end)
	
	text = gsub(text, "(.?)([νΝ])τ(.?)", -- ντ (inisial o rare consonanti, mediali) > (n)d, eceto τζ > tz
		function(before, ni, following)
			local ucase = ni == "Ν"
			if before == "" or before == " " or before == "-" or not find(before, vowels) then
				return before .. (ucase and "D" or "d") .. following
			elseif following ~= "ζ" then
				return before .. "nd" .. following
			end
		end)
	
	text = gsub(text, "(.?)σ(.?)", -- ss intrà vocali
		function (before, following)
			if find(before, vowels) and find(following, vowels) then
				return before .. "ss" .. following
			end
		end)
	
	-- vowels
	text = gsub(text, "([αεοΑΕΟ])ι(.?)", -- αι > e, ει > i, οι > i, eceto ϊ
		function (vowel, following)
			if following ~= diaeresis then
				return gsub(vowel, "[αεοΑΕΟ]", {["α"] = "e", ["Α"] = "E", ["ε"] = "i", ["Ε"] = "I", ["ο"] = "i", ["Ο"] = "I"})
					.. following
			end
		end)
	
	text = gsub(text, "([αεΑΕ])υ(.?)", -- αυ > av, ευ > ev, eceto ϋ
		function (vowel, following)
			if following ~= diaeresis then
				return tt[vowel] .. "v" .. following
			end
		end)
	
	text = gsub(text, "([αεοωΑΕΟΩ])η",
				function (vowel)
					return tt[vowel] .. "i" .. diaeresis
				end)
	
	text = gsub(text, "([οΟ])υ", {["ο"] = "u", ["Ο"] = "U"})
	
	text = gsub(text, ".", tt)
	text = gsub(text, "ll", "l·l")
	
	-- regulaminti de asentasion en vèneto
	text = gsub(text, diaeresis, "")
	local latin = mw.ustring.toNFC(text)
	latin = gsub(latin, "([áÁ])", {["á"]="à", ["Á"]="À"})
	local sil = mw.text.split(require("Module:vec-zenerałe").sil(latin), '·')
	
	if #sil == 1 then -- monosilaba sensa asento
		latin = gsub(text, acute, "")
	elseif find(sil[#sil], "[ÀàÉéÍíÓóÚú]") then -- agudo
		if not (find(latin, "[àéíóú]" .. "s?$") or find(latin, "[éí]" .. "n$")) then
			text = gsub(text, "([aeoiu][iu])" .. acute, "%1" .. diaeresis)
			text = gsub(text, "gui" .. diaeresis, "gui")
			latin = gsub(text, acute, "")
		end
	elseif find(sil[#sil-1], "[ÀàÉéÍíÓóÚú]") then -- pian
		if string.find(text, "[aeiou]s?$") or string.find(text, "[ei]n$") then
			if not string.find(text, "[aeiou][iu]$") then
				text = gsub(text, "([aeoiu][iu])" .. acute, "%1" .. diaeresis)
				text = gsub(text, "gui" .. diaeresis, "gui")
				latin = gsub(text, acute, "")
			end
		end
	end
	
	return latin
end

return p
Traesto fora da Wikipèdia - L'ençiclopedia łìbara e cołaboradiva in łéngua Vèneta "https://vec.wiktionary.org/w/index.php?title=Modulo:el-trans&oldid=33848"