[go: up one dir, main page]

Vés al contingut

Mòdul:rom-trans

De Viccionari
Icona de documentació de mòdul Documentació del mòdul[mostra] [modifica] [refresca]

A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]


Mòdul de conversions ortogràfiques segons Viccionari:Alfabet romaní, de l’estàndard internacional a acadèmic i anglicitzat.

local p = {}

local GR = mw.ustring.char(0x0300) -- grave = ̀
local AC = mw.ustring.char(0x0301) -- acute = ˊ

-- International Standard to Academic (AKA Plan-Vlax)
local is2ac = {
	["ă"] = "ja", ["ĕ"] = "je", ["ĭ"] = "ji", ["ŏ"] = "jo", ["ŭ"] = "ju",
	["ä"] = "ǝ", ["ë"] = "ǝ", ["ï"] = "i",
	["ć"] = "č", ["ś"] = "š", ["ź"] = "ž",
	["ʒ"] = "dž"
}

-- International Standard to Anglicized
local is2ang = {
	["ă"] = "ya", ["ĕ"] = "ye", ["ĭ"] = "yi", ["ŏ"] = "yo", ["ŭ"] = "yu",
	["ä"] = "e", ["ë"] = "e", ["ï"] = "i",
	["c"] = "ts", ["j"] = "y",
	["ć"] = "ch", ["ś"] = "sh", ["ź"] = "zh",
	["ʒ"] = "dj"
}

-- determine spelling
function p.spelling(term)
	local is_post = {["ç"] = true, ["q"] = true, ["θ"] = true}
	local ac_sp = {["č"] = true, ["ǝ"] = true, ["š"] = true, ["ž"] = true}
	local ang_sp = {["y"] = true}
	for i = 1, mw.ustring.len(term) do
		local letter = mw.ustring.sub(term, i, i)
		if is_post[letter] or is2ac[letter] then
			return "is" -- International Standard
		end
		if ac_sp[letter] then
			return "ac" -- Academic
		end
		if ang_sp[letter] then
			return "ang" -- Anglicized
		end
	end
	return "any"
end

-- transliteration of postposicionals
local function postpos_tr(postpos, preceding, spelling)
	if postpos == "ç" then
		if preceding == "n" and spelling == "ac" then return "c" end
		if preceding == "n" and spelling == "ang" then return "ts" end
		return "s"
	end
	if postpos == "q" then
		if preceding == "n" then return "g" end
		return "k"
	end
	if postpos == "θ" then
		if preceding == "n" then return "d" end
		return "t"
	end
	return postpos
end

function p.academic(term)
	local tr = mw.ustring.gsub(term, '.', is2ac)
	tr = mw.ustring.gsub(tr, "(.)-(.)", "%1'%2")
	tr = mw.ustring.gsub(tr, "(.)([çqθ])", function (pre, pp) return pre .. postpos_tr(pp, pre, "ac") end)
	tr = mw.ustring.gsub(mw.ustring.toNFD(tr), GR, AC)
	return tr
end

function p.anglicized(term)
	local tr = mw.ustring.gsub(term, '.', is2ang)
	tr = string.gsub(tr, "chh", "ch")
	tr = mw.ustring.gsub(tr, "(.)([çqθ])", function (pre, pp) return pre .. postpos_tr(pp, pre, "ang") end)
	tr = mw.ustring.gsub(mw.ustring.toNFD(tr), GR, "")
	return tr
end

return p