Bước tới nội dung

Mô đun:ane-IPA

Từ điển mở Wiktionary
local export = {}
local PAGENAME = mw.title.getCurrentTitle().text

local m_IPA = require("Module:IPA")
local lang = require("Module:languages").getByCode("ane")

-- single characters that map to IPA sounds
local phonetic_chars_map = {
	["a"] = "ɑ",
	["ä"] = "ʌ̃",
	["â"] = "ɑ̃",
	["b"] = "ᵐb",
	["c"] = "t͡ʃ",
	["d"] = "ⁿd",
	["e"] = "ɤ",
	["é"] = "e",
	["ë"] = "ʌ",
	["è"] = "ɛ",
	["ê"] = "ɛ̃",
	["f"] = "f",
	["g"] = "ᵑɡ",
	["i"] = "i",
	["î"] = "ĩ",
	["j"] = "ᶮɟ",
	["k"] = "k",	
	["l"] = "l",
	["m"] = "m",
	["n"] = "n",
	["o"] = "o",
	["ö"] = "ɔ",
	["ô"] = "ɔ̃",
	["p"] = "p",
	["r"] = "r",
	["s"] = "ç",
	["t"] = "t",
    ["u"] = "u",
	["ü"] = "ɨ̃",
	["ù"] = "ɨ",
	["û"] = "ũ",
	["v"] = "v",
	["w"] = "w",
	["x"] = "x",
	["y"] = "j",
}

-- character sequences of two that map to IPA sounds
local phonetic_2chars_map = {
	["aa"] = "ɑː",
	["ää"] = "ʌ̃ː",
	["ââ"] = "ɑ̃ː",
	["bw"] = "ᵐbʷ",
	["ch"] = "ʃ",
	["ee"] = "ɤː",
	["éé"] = "eː",
	["ëë"] = "ʌː",
	["èè"] = "ɛː",
	["êê"] = "ɛ̃ː",
	["gw"] = "ᵑɡʷ",
	["ii"] = "iː",
	["îî"] = "ĩː",
	["kw"] = "kʷ",
	["mw"] = "mʷ",
    ["ng"] = "ŋ",
	["ny"] = "ɲ",
    ["oo"] = "oː",
	["öö"] = "ɔː",
	["ôô"] = "ɔ̃ː",
    ["pw"] = "pʷ",
    ["uu"] = "uː",
	["üü"] = "ɨ̃ː",
	["ùù"] = "ɨː",
	["ûû"] = "ũː",
    ["xw"] = "xʷ",
}

function export.to_IPA(word)
	word = mw.ustring.lower(word)

	local phonetic = word

	for pat, repl in pairs(phonetic_2chars_map) do
		phonetic = phonetic:gsub(pat, repl)
	end

	phonetic = mw.ustring.gsub(phonetic, '.', phonetic_chars_map)

	return "[" .. phonetic .. "]"
end

function export.pronunciation(word)
	if type(word) == "table" then
		word = word.args[1] or word:getParent().args[1]
	end
	if not word or (word == "") then
		word = PAGENAME
	end
	local items = {}
	table.insert(items, {pron = export.to_IPA(word), note = nil})
	return m_IPA.format_IPA_full { lang = lang, items = items }
end

return export