求真百科歡迎當事人提供第一手真實資料,洗刷冤屈,終結網路霸凌。

模組:IPAc-en/data檢視原始碼檢視歷史

事實揭露 揭密真相
前往: 導覽搜尋

此模塊的文檔可以在模塊:IPAc-en/data/doc創建

-- This module processes data for [[Module:IPAc-en]]. It is intended to be
-- loaded with mw.loadData.

local PRONUNCIATION_MODULE = '模块:IPAc-en/pronunciation'
local PHONEME_MODULE = '模块:IPAc-en/phonemes'

local function makeData(oldData)
	local newData = {}
	for i, old in ipairs(oldData) do
		local new = {}
		for k, v in pairs(old) do
			if k ~= 'aliases' and k ~= 'code' then
				new[k] = v
			end
		end
		newData[old.code] = new
		if old.aliases then
			for i, alias in ipairs(old.aliases) do
				newData[alias] = new
			end			
		end
	end
	return newData
end

local function main()
	local pronunciation = makeData(require(PRONUNCIATION_MODULE))
	local phonemes = makeData(require(PHONEME_MODULE))

	-- Check that no pronunciation keys are also contained in the phonemes
	-- data. This would cause silent, hard-to-debug errors if it went
	-- unchecked, so  make it cause a big red error message instead.
	for id in pairs(pronunciation) do
		if phonemes[id] then
			error(string.format(
				"重複的ID '%s' - 在 %s 及 %s",
				id,
				PRONUNCIATION_MODULE,
				PHONEME_MODULE
			))
		end
	end

	return {
		pronunciation = pronunciation,
		phonemes = phonemes,
	}
end

return main()