Module:gan-pron

Hello, you have come here looking for the meaning of the word Module:gan-pron. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:gan-pron, but we will also tell you about its etymology, its characteristics and you will know how to say Module:gan-pron in singular and plural. Everything you need to know about the word Module:gan-pron you have here. The definition of the word Module:gan-pron will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:gan-pron, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local export = {}
local m_string_utils = require("Module:string utilities")

local gsub = m_string_utils.gsub
local sub = m_string_utils.sub
local len = m_string_utils.len
local match = m_string_utils.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 = 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)
	return (text
		:gsub("/", " / ")
		:gsub("(+)", "<sup>%1</sup>"))
end

return export