Module:pox-IPA

From Wiktionary, the free dictionary
Jump to navigation Jump to search

local export = {}

local m_IPA = require("Module:IPA")
local lang = require("Module:languages").getByCode("pox")
local rsub = mw.ustring.gsub
local rlower = mw.ustring.lower

local binary = {
	['nn'] = 'nː', ['ai'] = 'ai̯', ['åi'] = 'ɒi̯',
	['au'] = 'au̯', ['åu'] = 'ɒu̯', ['oi'] = 'ɔi̯',
}

local inventory = {
	['b'] = 'b', ['b́'] = 'bʲ', ['d'] = 'd', ['ď'] = 'dʲ',
	['ʒ'] = 'd͡z', ['ʒ́'] = 'd͡zʲ', ['f'] = 'f', ['g'] = 'ɡ',
	['j'] = 'j', ['k'] = 'k', ['l'] = 'l', ['ľ'] = 'lʲ', 
	['m'] = 'm', ['ḿ'] = 'mʲ', ['n'] = 'n', ['ń'] = 'nʲ', 
	['p'] = 'p', ['ṕ'] = 'pʲ', ['r'] = 'r', ['ŕ'] = 'rʲ', 
	['s'] = 's', ['ś'] = 'sʲ', ['š'] = 'ʃ', ['t'] = 't', 
	['ť'] = 'tʲ', ['c'] = 't͡s', ['ć'] = 't͡sʲ', ['v'] = 'v',
	['v́'] = 'vʲ', ['x'] = 'x', ['x́'] = 'xʲ', ['z'] = 'z',
	['ź'] = 'zʲ', ['ž'] = 'ʒ', ['́'] = 'ʲ',
	['a'] = 'a', ['ą'] = 'ã', ['å'] = 'ɒ', ['ă'] = 'ɐ',
	['ĕ'] = 'ə', ['e'] = 'ɛ', ['i'] = 'i', ['o'] = 'ɔ',
	['ǫ'] = 'ɔ̃', ['ö'] = 'œ', ['u'] = 'u', ['ü'] = 'y',
}

local function phonemic(text)
	text = rlower(text)
	text = rsub(text, "..", binary)
	text = rsub("1" .. text, "..", binary)
	text = rsub(text, "1", "")
	text = rsub(text, ".", inventory)
	if mw.ustring.find(text, "'") == nil then
		text = "ˈ" .. text
	end
	text = rsub(text, "'", "ˈ")
	return text
end

function export.IPA(frame)
	local words = {}
	
	for _, word in ipairs(frame:getParent().args) do
		table.insert(words, word)
	end
	
	if #words == 0 then
		words = {mw.title.getCurrentTitle().text}
	end
	
	local IPA_results = {}
	
	for _, word in ipairs(words) do
		table.insert(IPA_results, { pron = "/" .. phonemic(word) .. "/" })
	end
	
	return m_IPA.format_IPA_full { lang = lang, items = IPA_results }
end

return export