Bước tới nội dung

Mô đun:eee-IPA

Từ điển mở Wiktionary
export = {}

local m_pron_utilities = require("Module:pron utilities")
local m_str_utils = require("Module:string utilities")
local gsub = m_str_utils.gsub
local match = m_str_utils.match

local tones = {
	["¹"] = "⁵¹",
	["²"] = "³¹",
	["³"] = "⁵⁵",
	["⁵"] = "³⁵",
	["⁶"] = "²⁴",
	["⁷"] = "⁵⁴",
	["⁸"] = "²⁴",
}

local function respelling_to_IPA(data)
	local text = data.pagename
	
	if match(text, "[⁴⁹0-9]") then
		error("Please check the tone number.")
	end
	
	text = gsub(text, "[¹²³⁵⁶⁷⁸]", tones)
	text = gsub(text, "%f[h%s%c]h", "ʰ") -- non-initial h
	text = gsub(text, "ȵ", "n̠ʲ")
	
	return "/" .. text .. "/"
end

function export.eee_IPA(frame)
	local parent_args = frame:getParent().args
	return m_pron_utilities.format_prons {
		lang = require("Module:languages").getByCode("eee"),
		respelling_to_IPA = respelling_to_IPA,
		raw_args = parent_args,
		track_module = "eee-IPA",
	}
end

return export