模組:Onb-pron

維基詞典,自由的多語言詞典
這個模块仍在測試階段。
其界面已經穩定,但模块仍可能有部分錯誤。直到模块測試完成前,請不要大量使用此模块。

--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 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({'西部'})
	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({'[[w:zh:臨城鎮 (臨高縣)|臨城]]'}) .. " " ..
		require('Module:IPA').format_IPA_full(
			require('Module:languages').getByCode('onb'),
			{
				{
					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({'[[w:zh:波蓮鎮|波蓮]]'}) .. " " ..
		require('Module:IPA').format_IPA_full(
			require('Module:languages').getByCode('onb'),
			{
				{
					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({'[[w:zh:東英鎮|東英]]'}) .. " " ..
		require('Module:IPA').format_IPA_full(
			require('Module:languages').getByCode('onb'),
			{
				{
					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({'[[w:zh:橋頭鎮 (澄邁縣)|橋頭]]'}) .. " " ..
		require('Module:IPA').format_IPA_full(
			require('Module:languages').getByCode('onb'),
			{
				{
					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({'[[w:zh:皇桐鎮|皇桐]]'}) .. " " ..
		require('Module:IPA').format_IPA_full(
			require('Module:languages').getByCode('onb'),
			{
				{
					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({'[[w:zh:新盈鎮|新盈]]'}) .. " " ..
		require('Module:IPA').format_IPA_full(
			require('Module:languages').getByCode('onb'),
			{
				{
					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({'東部'})
	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({'[[w:zh:老城鎮 (澄邁縣)|老城]]'}) .. " " ..
		require('Module:IPA').format_IPA_full(
			require('Module:languages').getByCode('onb'),
			{
				{
					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({'[[w:zh:龍塘鎮 (海口市)|龍塘]]'}) .. " " ..
		require('Module:IPA').format_IPA_full(
			require('Module:languages').getByCode('onb'),
			{
				{
					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({'[[w:zh:龍橋鎮 (海口市)|龍橋]]'}) .. " " ..
		require('Module:IPA').format_IPA_full(
			require('Module:languages').getByCode('onb'),
			{
				{
					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({'[[w:zh:永興鎮 (海口市)|永興]]'}) .. " " ..
		require('Module:IPA').format_IPA_full(
			require('Module:languages').getByCode('onb'),
			{
				{
					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({'[[w:zh:長流鎮|長流]]'}) .. " " ..
		require('Module:IPA').format_IPA_full(
			require('Module:languages').getByCode('onb'),
			{
				{
					pron = "/" .. gsub(text, '[¹²³⁴⁷⁸]', toneConv_Changliu) .. "/"
				}
			}
		)
	end

	return IPAtext
end

return export