Module:zu-IPA

Hello, you have come here looking for the meaning of the word Module:zu-IPA. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:zu-IPA, but we will also tell you about its etymology, its characteristics and you will know how to say Module:zu-IPA in singular and plural. Everything you need to know about the word Module:zu-IPA you have here. The definition of the word Module:zu-IPA will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:zu-IPA, 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 lang = require("Module:languages").getByCode("zu")


local u = mw.ustring.char

local ACUTE     = u(0x0301)
local CIRC      = u(0x0302)
local MACRON    = u(0x0304)
local CARON     = u(0x030C)
local SYLL      = u(0x0329)

local letters_phonemes = {
	 = "a",
	 = "e",
	 = "i",
	 = "o",
	 = "u",
	
	 = "ǀ",  = "ǀʰ",  = "ᵑǀ",  = "ᶢǀʱ",  = "ᵑǀʱ",
	 = "ǃ",  = "ǃʰ",  = "ᵑǃ",  = "ᶢǃʱ",  = "ᵑǃʱ",
	 = "ǁ",  = "ǁʰ",  = "ᵑǁ",  = "ᶢǁʱ",  = "ᵑǁʱ",
	
	 = "ɓ",  = "b",  = "mb",
	 = "d",  = "ɮ",
	 = "f",
	 = "ɡ",  = "nɡ",
	 = "h",  = "ɦ",  = "ɬ",
	 = "dʒ",  = "ɲdʒ", 
	 = "ɠ",  = "kʰ",  = "kx",  = "nk",  = "k",
	 = "l",
	 = "m",  = "mʱ",
	 = "n",  = "nʱ",  = "nɬ",
	 = "ɲ",
	 = "p",  = "pʰ",
	 = "r", 
	 = "s",  = "ʃ",
	 = "t",  = "tʰ",
	 = "tʃ",  = "ɲtʃ",
	 = "v",
	 = "w",  = "wʱ",
	 = "j",  = "jʱ",
	 = "z",
	 = "ʔ",
	
	 = "m" .. SYLL,
	 = "m" .. ACUTE .. SYLL,
	 = "ˈ",
	
	 = "ː",
	 = ACUTE .. "ː",
	 = CIRC .. "ː",
	 = CARON .. "ː",
}

local function IPA_word(term)
	local rest = mw.ustring.toNFD(term)
	local phonemes = {}
	
	while mw.ustring.len(rest) > 0 do
		-- Find the longest string of letters that matches a recognised sequence in the list
		local longestmatch = ""
		
		for letter, phoneme in pairs(letters_phonemes) do
			if mw.ustring.sub(rest, 1, mw.ustring.len(letter)) == letter and mw.ustring.len(letter) > mw.ustring.len(longestmatch) then
				longestmatch = letter
			end
		end
		
		-- Convert the string to IPA
		if mw.ustring.len(longestmatch) > 0 then
			table.insert(phonemes, letters_phonemes)
			rest = mw.ustring.sub(rest, mw.ustring.len(longestmatch) + 1)
		else
			table.insert(phonemes, mw.ustring.sub(rest, 1, 1))
			rest = mw.ustring.sub(rest, 2)
		end
	end
	
	return mw.ustring.toNFC(table.concat(phonemes))
end


function export.IPA(frame)
	local args = frame:getParent().args
	local term
	local tone_needed = ""
	if args then
		term = args
	else
		term = mw.ustring.lower(mw.title.getCurrentTitle().subpageText)
		tone_needed = "<sup title=\"tones missing\">?</sup>"
	end
	
	if not (mw.ustring.find(term, '"') or mw.ustring.find(term, "$")) then
		-- Penultimate lengthening
		term = require("Module:zu-common").split_syllables(term)
		
		if term then
			term = mw.ustring.gsub(term, "$", { = "ā",  = "ē",  = "ī",  = "ō",  = "ū",  = "ā́",  = "ḗ",  = "ī́",  = "ṓ",  = "ū́"})
		end
		
		term = table.concat(term)
	end
	
	term = IPA_word(term)
	return require("Module:IPA").format_IPA_full { lang = lang, items = {{pron = "/" .. term .. "/"}} } .. tone_needed
end


return export