Vés al contingut

Mòdul:hy-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 per a la transcripció automàtica de l’armeni segons w:Viquipèdia:Transcripció de l'armeni. És usat per altres mòduls i indirectament per les plantilles {{entrada}}, {{m}} i {{trad}}.

local p = {}

local trans2ca = require("Module:ca-general")
local u = mw.ustring.char
local GR = u(0x0300) -- grave =  ̀
local AC = u(0x0301) -- acute = ˊ
local DI = u(0x0308) -- diaeresis = ¨

local tt = {
	["ա"]="a", ["բ"]="b", ["գ"]="g", ["դ"]="d", ["ե"]="e", ["զ"]="z", ["է"]="e", ["ը"]="e",
	["թ"]="t", ["ժ"]="j", ["ի"]="i", ["լ"]="l", ["խ"]="kh", ["ծ"]="ts", ["կ"]="k", ["հ"]="h",
	["ձ"]="dz", ["ղ"]="kh", ["ճ"]="tx", ["մ"]="m", ["յ"]="i", ["ն"]="n", ["շ"]="x", ["ո"]="o",
	["չ"]="tx", ["պ"]="p", ["ջ"]="dj", ["ռ"]="r", ["ս"]="s", ["վ"]="v", ["տ"]="t", ["ր"]="r",
	["ց"]="tx", ["ւ"]="v", ["փ"]="p", ["ք"]="k", ["օ"]="o", ["ֆ"]="f", ["և"]="ev",
	["Ա"]="A", ["Բ"]="B", ["Գ"]="G", ["Դ"]="D", ["Ե"]="E", ["Զ"]="Z", ["Է"]="E", ["Ը"]="E",
	["Թ"]="T", ["Ժ"]="J", ["Ի"]="I", ["Լ"]="L", ["Խ"]="Kh", ["Ծ"]="Ts", ["Կ"]="K", ["Հ"]="H",
	["Ձ"]="Dz", ["Ղ"]="Kh", ["Ճ"]="Tx", ["Մ"]="M", ["Յ"]="I", ["Ն"]="N", ["Շ"]="X", ["Ո"]="O",
	["Չ"]="Tx", ["Պ"]="P", ["Ջ"]="Dj", ["Ռ"]="R", ["Ս"]="S", ["Վ"]="V", ["Տ"]="T", ["Ր"]="R",
	["Ց"]="Tx", ["Ւ"]="V", ["Փ"]="P", ["Ք"]="K", ["Օ"]="O", ["Ֆ"]="F"
}

local function wtr(armn)
	-- digraphs
	armn = mw.ustring.gsub(armn, "([ոՈ])ւ", {["ո"]="u", ["Ո"]="U"})
	
	-- changes at the beginning of a word
	armn = mw.ustring.gsub(armn, "^([եԵ])", {["ե"]="ie", ["Ե"]="Ie"})
	armn = mw.ustring.gsub(armn, "^և", "iev")
	armn = mw.ustring.gsub(armn, "^([ոՈ])", {["ո"]="vո", ["Ո"]="Vո"})
	
	local latin = mw.ustring.gsub(armn, '.', tt)
	
	local sil = mw.text.split(trans2ca.sil(latin), "·")
	if not mw.ustring.find(latin, "[" .. AC .. GR .. "]") then
		-- accent en la darrera síl·laba excepte monosíl·labs
		if #sil > 1 then
			if string.find(sil[#sil], "[AEOaeo]") then
				sil[#sil] = mw.ustring.gsub(sil[#sil], "[AEOaeo]", "%1" .. AC, 1) -- vocal forta en diftongs decreixents o creixents
			else
				sil[#sil] = mw.ustring.gsub(sil[#sil], "[IUiu]", "%1" .. AC, 1) -- primera vocal dèbil en diftongs creixents
			end
			latin = table.concat(sil)
		end
	end
	-- regles d'accentuació
	if mw.ustring.find(sil[#sil], AC) then -- aguda
		if not (mw.ustring.find(latin, "[aeiou]" .. AC .. "s?$") or mw.ustring.find(latin, "[ei]" .. AC .. "n$")) then
			latin = mw.ustring.gsub(latin, "([aeoiu][iu])" .. AC, "%1" .. DI)
			latin = mw.ustring.gsub(latin, "gui" .. DI, "gui")
			latin = mw.ustring.gsub(latin, AC, "")
		end
	end
	
	local char_acc = {["A"..AC]="À", ["E"..AC]="È", ["I"..AC]="Í", ["O"..AC]="Ó", ["U"..AC]="Ú", 
		["a"..AC]="à", ["e"..AC]="è", ["i"..AC]="í", ["i"..DI]="ï", ["o"..AC]="ó", ["u"..AC]="ú", ["u"..DI]="ü"}
	latin = mw.ustring.gsub(latin, ".[" .. AC .. DI .. "]", char_acc)
	
	-- correcció ò
	if mw.ustring.find(armn, "[ոՈ][^աեէըիյօև]+$") then -- darrera vocal ò
		latin = mw.ustring.gsub(latin, "([óÓ])", {["ó"]="ò", ["Ó"]="Ò"})
	end
	
	-- correcció gue/gui
	latin = mw.ustring.gsub(latin, "([Gg])([eèií])", "%1u%2")
	
	-- correcció intervocàlica ss, ix
	latin = mw.ustring.gsub(latin, "([AEIOUaeiouÀÈÍÓÒÚàèíóòú])s([aeiouàèíóòú])", "%1ss%2")
	latin = mw.ustring.gsub(latin, "([AEOUaeouÀÈÓÒÚàèóòúü])x", "%1ix")
	
	return latin
end

-- Transliterates text, a single word or phrase.
function p.tr(text)
	if type(text) == "table" then text = text.args[1] end
	local trwords = {}
	for word in mw.text.gsplit(text, '%s') do
		table.insert(trwords, wtr(word))
	end
	
	return table.concat(trwords, ' ')
end

return p