Modul:gan-pron

Üdvözlöm, Ön a Modul:gan-pron szó jelentését keresi. A DICTIOUS-ban nem csak a Modul:gan-pron szó összes szótári jelentését megtalálod, hanem megismerheted az etimológiáját, a jellemzőit és azt is, hogyan kell a Modul:gan-pron szót egyes és többes számban mondani. Minden, amit a Modul:gan-pron szóról tudni kell, itt található. A Modul:gan-pron szó meghatározása segít abban, hogy pontosabban és helyesebben fogalmazz, amikor beszélsz vagy írsz. AModul:gan-pron és más szavak definíciójának ismerete gazdagítja a szókincsedet, és több és jobb nyelvi forráshoz juttat.

A modult a Modul:gan-pron/doc lapon tudod dokumentálni

local export = {}

local gsub = mw.ustring.gsub
local sub = mw.ustring.sub
local len = mw.ustring.len
local match = mw.ustring.match

local initialConv = {
	 = "p",  = "pʰ",  = "m",  = "f", 
	 = "t",  = "tʰ",  = "l", 
	 = "t͡s",  = "t͡sʰ",  = "s",
	 = "t͡ɕ",  = "t͡ɕʰ",  = "ɕ",  = "n̠ʲ",
	 = "k",  = "kʰ",  = "ŋ",
	 = "h",  = ""
}

local finalConv = {
	 = "z̩",
	 = "i", 
	 = "u", 
	 = "y", 
	 = "a",  = "ia",  = "ua",
	 = "o",  = "uo", 
	 = "e",  = "ie",  = "ue",  = "ye",
	 = "ɵ",
	 = "ai",  = "uai",
	 = "oi",  = "ei",  = "ɨi",  = "ui",
	 = "au",  = "ɛu",  = "iɛu",
	 = "iu",  = "ɨu", 
	 = "an",  = "uan",
	 = "ɵn",  = "uɵn",  = "yɵn",
	 = "ɛn",  = "iɛn",  = "in",  = "ɨn",
	 = "un",  = "yn",
	 = "aŋ",  = "iaŋ",  = "uaŋ",
	 = "ɔŋ",  = "iɔŋ",  = "uɔŋ",
	 = "uŋ",  = "iuŋ",
	 = "at̚",  = "uat̚",
	 = "ɵt̚",  = "uɵt̚",  = "yɵt̚",
	 = "ɛt̚",  = "iɛt̚",  = "uɛt̚",
	 = "it̚",  = "ɨt̚",  = "ut̚",  = "yt̚",
	 = "aʔ",  = "iaʔ",  = "uaʔ",
	 = "ɔʔ",  = "iɔʔ",  = "uɔʔ",
	 = "uʔ",  = "iuʔ",
	 = "m̩",  = "n̩",  = "ŋ̍"
}

local toneConv = {
	 = "⁴²",  = "²⁴",  = "²¹³",  = "³⁵",
	 = "¹¹",  = "⁵",  = "²",  = "¹",  = "²",
	 = "²¹³⁻¹³",  = "²¹³⁻²⁴",  = "²¹³⁻²¹",  = "",
}

function export.ipa(text)
	if type(text) == "table" then
		text = text.args
	end
	local syllables, stress, initial, final, tone, ipa, result = {}, {}, {}, {}, {}, {}, {}
	local has_stress, has_neutral, attention = false, false, ""
	local words = mw.text.split(text, "/")
	for _, word in ipairs(words) do
		syllables = mw.text.split(word, " ")
		for index, syllable in ipairs(syllables) do
			stress = match(syllable, "^'") and "ˈ" or ""
			has_stress = has_stress or stress == "ˈ"
			syllable = mw.ustring.gsub(syllable, "^'", "")
			initial = match(syllable, "^??")
			if match(initial, "^.y$") and initial ~= "ny" then
				initial = sub(initial, 1, 1)
			end
			initial = initial == "y" and "" or initial
			final = match(sub(syllable, len(initial) + 1, -1), "^*")
			if final == "" then
				final = initial
				initial = ""
			end
			tone = match(syllable, "+$") or (index ~= 1 and "8" or "")
			has_neutral = has_neutral or tone == "8"
			
			-- checks validity of the syllable
			local aspirated = match(initial, "^$")
			local checked = match(final, "$")
			if tone == "2" and not aspirated then
				error("The 2nd tone can only go with aspirated initials. Use the 4th tone instead.")
			elseif tone == "4" and aspirated then
				error("The 4th tone can only go with unaspirated initials. Use the 2nd tone instead.")
			elseif match(tone, "^$") and not checked then
				error(string.format("Tone %s can only go with checked finals.", tone))
			elseif match(tone, "^$") and checked then
				error(string.format("Tone %s cannot go with a checked final.", tone))
			end
		end
		for index = 1, #syllables do
			initial = initialConv] or error(("Unrecognised initial: \"%s\""):format(initial))
			final = (match(initial, "s") and final == "i") and "z" or final
			final = (initial == "f" and final == "i") and "ii" or final
			final = (match(initial, "s") and final == "iu") and "iiu" or final
			final = finalConv] or error(("Unrecognised final: \"%s\""):format(final))
			if tone == "3" then
				if match(tone or "", "") then
					tone = "3-1"
				elseif match(tone or "", "") then
					tone = "3-2"
				elseif tone then -- tone == "8"
					tone = "3-3"
				end
			elseif tone == "8" then
				if tone == "²¹³⁻²¹" or tone == "¹¹" or tone == "²" then
					tone = "8-1"
				else
					tone = "8-2"
				end
			end
			tone = toneConv] or error(("Unrecognised tone: \"%s\""):format(tone))
			ipa = stress .. initial .. final .. tone
		end
		table.insert(result, table.concat(ipa, " "))
	end
	
	-- check for stress if needed
	if #syllables > 1 and not has_neutral and not has_stress then
		attention = "]"
	end
	
	return table.concat(result, "/, /") .. attention
end

function export.rom(text)
	text = gsub(text, "/", " / ")
	text = gsub(text, '(+)', '<sup>%1</sup>')
	return text
end

return export