Difference between revisions of "Module:IPAc-en/data"

From blackwiki
Jump to navigation Jump to search
blackwiki>Mr. Stradivarius
(process pronunciation data as well)
blackwiki>Mr. Stradivarius
(check for pronunciation key dupes)
Line 1: Line 1:
 
-- This module processes data for [[Module:IPAc-en]]. It is intended to be
 
-- This module processes data for [[Module:IPAc-en]]. It is intended to be
 
-- loaded with mw.loadData.
 
-- loaded with mw.loadData.
 +
 +
local PRONUNCIATION_MODULE = 'Module:IPAc-en/pronunciation'
 +
local TOOLTIP_MODULE = 'Module:IPAc-en/tooltips'
  
 
local function makeData(oldData)
 
local function makeData(oldData)
Line 21: Line 24:
 
end
 
end
  
return {
+
local function main()
pronunciation = makeData(require('Module:IPAc-en/pronunciation')),
+
local pronunciation = makeData(require(PRONUNCIATION_MODULE))
tooltips = makeData(require('Module:IPAc-en/tooltips'))
+
local tooltips = makeData(require(TOOLTIP_MODULE))
}
+
 
 +
-- Check that no pronunciation keys are also contained in the tooltips
 +
-- 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 tooltips[id] then
 +
error(string.format(
 +
"duplicate ID '%s' found in %s and %s",
 +
id,
 +
PRONUNCIATION_MODULE,
 +
TOOLTIP_MODULE
 +
))
 +
end
 +
end
 +
 
 +
return {
 +
pronunciation = pronunciation,
 +
tooltips = tooltips,
 +
}
 +
end
 +
 
 +
return main()

Revision as of 07:50, 17 June 2015


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

local PRONUNCIATION_MODULE = 'Module:IPAc-en/pronunciation'
local TOOLTIP_MODULE = 'Module:IPAc-en/tooltips'

local function makeData(oldData)
	local newData = {}
	for id, old in pairs(oldData) do
		local new = {}
		for k, v in pairs(old) do
			if k ~= 'aliases' then
				new[k] = v
			end
		end
		newData[id] = 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 tooltips = makeData(require(TOOLTIP_MODULE))

	-- Check that no pronunciation keys are also contained in the tooltips
	-- 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 tooltips[id] then
			error(string.format(
				"duplicate ID '%s' found in %s and %s",
				id,
				PRONUNCIATION_MODULE,
				TOOLTIP_MODULE
			))
		end
	end

	return {
		pronunciation = pronunciation,
		tooltips = tooltips,
	}
end

return main()