Jump to content

Module:onb-pron

From Wiktionary, the free dictionary

This module is in beta stage.
Its interface has been stabilised, but the module may still contain errors. Do not deploy widely until the module has been tested.

--References: 临高汉词典 (Bolian), 临高语研究 (Lincheng, Longtang), 海南临高话 (Dongying, Laocheng, Longqiao), http://ling.hawaii.edu/wp-content/uploads/ChenYenlingFinal.pdf
local export = {}
local find = mw.ustring.find
local gsub = mw.ustring.gsub

local lang = require("Module:languages").getByCode("onb")

local toneConv_Lincheng = {
	['¹']   = '˨˩˧', ['²']   = '˥', ['³']   = '˧', ['⁴']   = '˨˩', ['⁷']   = '˧', ['⁸']   = '˥'
}
local toneConv_Bolian = {
	['¹']   = '˩˧', ['²']   = '˥', ['³']   = '˧', ['⁴']   = '˨˩', ['⁷']   = '˧', ['⁸']   = '˥', ['⁹']   = '˨˩'
}
local toneConv_Dongying = {
	['¹']   = '˨˩˧', ['²']   = '˥˧', ['³']   = '˧', ['⁴']   = '˨˩', ['⁷']   = '˧', ['⁸']   = '˥˧', ['⁹']   = '˨˩'
}
local toneConv_Qiaotou = {
	['¹']   = '˨˩˧', ['²']   = '˧˨˦', ['³']   = '˧', ['⁴']   = '˥', ['⁷']   = '˧', ['⁸']   = '˥'
}
local toneConv_Huangtong = {
	['¹']   = '˨˩˧', ['²']   = '˥˩', ['³']   = '˧˩', ['⁴']   = '˨˩', ['⁷']   = '˧', ['⁸']   = '˥'
}
local toneConv_Xinying = {
	['¹']   = '˨˩˧', ['²']   = '˥', ['³']   = '˧', ['⁴']   = '˨˩', ['⁷']   = '˧', ['⁸']   = '˥'
}
local toneConv_Laocheng = {
	['¹']   = '˧˥', ['²']   = '˧', ['³']   = '˩˧', ['⁴']   = '˨˩', ['⁵']   = '˥', ['⁷']   = '˥', ['⁸']   = '˩˧'
}
local toneConv_Longtang = {
	['¹']   = '˩˧', ['1']   = '˦', ['²']   = '˧', ['³']   = '˨˦', ['⁴']   = '˩', ['⁵']   = '˥', ['⁶']   = '˧˥', ['⁷']   = '˩˧', ['7']   = '˦', ['⁸']   = '˩', ['8']   = '˧', ['⁹']   = '˥', ['十']   = '˧˥' --5, 6, 9, 10 are only used in loanwords
}
local toneConv_Longqiao = {
	['¹']   = '˩˧', ['1']   = '˦˥', ['²']   = '˧˨', ['³']   = '˨˦', ['⁴']   = '˨˩', ['⁵']   = '˥', ['⁶']   = '˧˥', ['⁷']   = '˩˧', ['7']   = '˦˥', ['⁸']   = '˨˩', ['8']   = '˧˨', ['⁹']   = '˥', ['十']   = '˧˥'
}
local toneConv_Yongxing = {
	['¹']   = '˨˩˧', ['²']   = '˦', ['³']   = '˨˦', ['⁴']   = '˨˩', ['⁷']   = '˨˩', ['7']   = '˥', ['⁸']   = '˧'
}
local toneConv_Changliu = {
	['¹']   = '˧˥', ['²']   = '˨˦', ['³']   = '˧', ['⁴']   = '˨˩', ['⁷']   = '˥', ['⁸']   = '˨˩'
}

function export.show(frame)
	local params = {
		[1] = { },
		["Lincheng"] = { type = "boolean" },
		["Bolian"] = { type = "boolean" },
		["Dongying"] = { type = "boolean" },
		["Qiaotou"] = { type = "boolean" },
		["Huangtong"] = { type = "boolean" },
		["Xinying"] = { type = "boolean" },
		["Laocheng"] = { type = "boolean" },
		["Longtang"] = { type = "boolean" },
		["Longqiao"] = { type = "boolean" },
		["Yongxing"] = { type = "boolean" },
		["Changliu"] = { type = "boolean" },
	}
	local args = require("Module:parameters").process(frame:getParent().args, params)

	local text = args[1]
	if not text then text = mw.title.getCurrentTitle().text end
	text = gsub(text, "ȵ", "n̠ʲ")
	text = gsub(text, "b", "ɓ")
	text = gsub(text, "d", "ɗ")

	if not find(text, "[¹²³⁴⁵⁶⁷⁸⁹]") then
		error("Tones are missing")
	end

	local IPAtext = ""

	if args["Lincheng"] or args["Bolian"] or args["Dongying"] or args["Qiaotou"] or args["Huangtong"] or args["Xinying"] then
		IPAtext = IPAtext .. "\n*" .. require("Module:accent qualifier").format_qualifiers(lang, {"Western"})
	end

	if args["Lincheng"] then
		if find(text, "[⁰⁵⁶⁹]") then
			error("Invalid tones in Lincheng accent")
		end

		IPAtext = IPAtext .. "\n** " .. require("Module:accent qualifier").format_qualifiers(lang, {"[[w:zh:臨城鎮 (臨高縣)|Lincheng]]"}) .. " " ..
		require("Module:IPA").format_IPA_full {
			lang = lang,
			items = {{ pron = "/" .. gsub(text, "[¹²³⁴⁷⁸]", toneConv_Lincheng) .. "/" }},
		}
	end

	if args["Bolian"] then
		if find(text, "[⁰⁵⁶]") then
			error("Invalid tones in Bolian accent")
		end

		IPAtext = IPAtext .. "\n** " .. require("Module:accent qualifier").format_qualifiers(lang, {"[[w:zh:波蓮鎮|Bolian]]"}) .. " " ..
		require("Module:IPA").format_IPA_full {
			lang = lang,
			items = {{ pron = "/" .. gsub(text, "[¹²³⁴⁷⁸⁹]", toneConv_Bolian) .. "/" }},
		}
	end

	if args["Dongying"] then
		if find(text, "[⁰⁵⁶]") then
			error("Invalid tones in Dongying accent")
		end

		IPAtext = IPAtext .. "\n** " .. require("Module:accent qualifier").format_qualifiers(lang, {"[[w:zh:東英鎮|Dongying]]"}) .. " " ..
		require("Module:IPA").format_IPA_full {
			lang = lang,
			items = {{ pron = "/" .. gsub(text, "[¹²³⁴⁷⁸⁹]", toneConv_Dongying) .. "/" }},
		}
	end

	if args["Qiaotou"] then
		if find(text, "[⁰⁵⁶⁹]") then
			error("Invalid tones in Qiaotou accent")
		end

		IPAtext = IPAtext .. "\n** " .. require("Module:accent qualifier").format_qualifiers(lang, {"[[w:zh:橋頭鎮 (澄邁縣)|Qiaotou]]"}) .. " " ..
		require("Module:IPA").format_IPA_full {
			lang = lang,
			items = {{ pron = "/" .. gsub(text, "[¹²³⁴⁷⁸]", toneConv_Qiaotou) .. "/" }},
		}
	end

	if args["Huangtong"] then
		if find(text, "[⁰⁵⁶⁹]") then
			error("Invalid tones in Huangtong accent")
		end

		IPAtext = IPAtext .. "\n** " .. require("Module:accent qualifier").format_qualifiers(lang, {"[[w:zh:皇桐鎮|Huangtong]]"}) .. " " ..
		require("Module:IPA").format_IPA_full {
			lang = lang,
			items = {{ pron = "/" .. gsub(text, "[¹²³⁴⁷⁸]", toneConv_Huangtong) .. "/" }},
		}
	end

	if args["Xinying"] then
		if find(text, "[⁰⁵⁶⁹]") then
			error("Invalid tones in Xinying accent")
		end

		IPAtext = IPAtext .. "\n** " .. require("Module:accent qualifier").format_qualifiers(lang, {"[[w:zh:新盈鎮|Xinying]]"}) .. " " ..
		require("Module:IPA").format_IPA_full {
			lang = lang,
			items = {{ pron = "/" .. gsub(text, "[¹²³⁴⁷⁸]", toneConv_Xinying) .. "/" }},
		}
	end

	if args["Laocheng"] or args["Longtang"] or args["Longqiao"] or args["Yongxing"] or args["Changliu"] then
		IPAtext = IPAtext .. "\n*" .. require("Module:accent qualifier").format_qualifiers(lang, {"Eastern"})
	end

	if args["Laocheng"] then
		if find(text, "[⁰⁶⁹]") then
			error("Invalid tones in Laocheng accent")
		end

		IPAtext = IPAtext .. "\n** " .. require("Module:accent qualifier").format_qualifiers(lang, {"[[w:zh:老城鎮 (澄邁縣)|Laocheng]]"}) .. " " ..
		require("Module:IPA").format_IPA_full {
			lang = lang,
			items = {{ pron = "/" .. gsub(text, "[¹²³⁴⁵⁷⁸]", toneConv_Laocheng) .. "/" }},
		}
	end

	if args["Longtang"] then
		text = gsub(text, "¹⁰", "十")
		text = gsub(text, "¹'", "1")
		text = gsub(text, "⁷'", "7")
		text = gsub(text, "⁸'", "8")

		IPAtext = IPAtext .. "\n** " .. require("Module:accent qualifier").format_qualifiers(lang, {"[[w:zh:龍塘鎮 (海口市)|Longtang]]"}) .. " " ..
		require("Module:IPA").format_IPA_full {
			lang = lang,
			items = {{ pron = "/" .. gsub(text, "[¹²³⁴⁵⁶⁷⁸⁹178十]", toneConv_Longtang) .. "/" }},
		}
	end


	if args["Longqiao"] then
		text = gsub(text, "¹⁰", "十")
		text = gsub(text, "¹'", "1")
		text = gsub(text, "⁷'", "7")
		text = gsub(text, "⁸'", "8")

		IPAtext = IPAtext .. "\n** " .. require("Module:accent qualifier").format_qualifiers(lang, {"[[w:zh:龍橋鎮 (海口市)|Longqiao]]"}) .. " " ..
		require("Module:IPA").format_IPA_full {
			lang = lang,
			items = {{ pron = "/" .. gsub(text, "[¹²³⁴⁵⁶⁷⁸⁹178十]", toneConv_Longqiao) .. "/" }},
		}
	end

	if args["Yongxing"] then
		if find(text, "[⁰⁵⁶⁹]") then
			error("Invalid tones in Yongxing accent")
		end

		text = gsub(text, "⁷'", "7")

		IPAtext = IPAtext .. "\n** " .. require("Module:accent qualifier").format_qualifiers(lang, {"[[w:zh:永興鎮 (海口市)|Yongxing]]"}) .. " " ..
		require("Module:IPA").format_IPA_full {
			lang = lang,
			items = {{ pron = "/" .. gsub(text, "[¹²³⁴⁷7⁸]", toneConv_Yongxing) .. "/" }},
		}
	end

	if args["Changliu"] then
		if find(text, "[⁰⁵⁶⁹]") then
			error("Invalid tones in Changliu accent")
		end

		IPAtext = IPAtext .. "\n** " .. require("Module:accent qualifier").format_qualifiers(lang, {"[[w:zh:長流鎮|Changliu]]"}) .. " " ..
		require("Module:IPA").format_IPA_full {
			lang = lang,
			items = {{ pron = "/" .. gsub(text, "[¹²³⁴⁷⁸]", toneConv_Changliu) .. "/" }},
		}
	end

	return IPAtext
end

return export