Module:IPA/templates

Definition from Wiktionary, the free dictionary
Jump to: navigation, search
Text-x-generic with pencil.svg This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local m_IPA = require("Module:IPA")

local export = {}

-- Used for [[Template:IPA]].
function export.IPA(frame)
	local params = {
		[1] = {list = true, allow_holes = true},
		["n"] = {list = true, allow_holes = true},
		["lang"] = {required = true, default = "und"},
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local lang = args["lang"]
	lang = require("Module:languages").getByCode(lang) or error("The language code \"" .. lang .. "\" is not valid.")
	
	local items = {}
	
	for i = 1, math.max(args[1].maxindex, args["n"].maxindex) do
		local pron = args[1][i]
		local note = args["n"][i]
		
		if pron or note then
			table.insert(items, {pron = pron, note = note})
		end
	end
	
	return m_IPA.format_IPA_full(lang, items)
end

-- Used for [[Template:IPAchar]].
function export.IPAchar(frame)
	local params = {
		[1] = {list = true, allow_holes = true},
		["n"] = {list = true, allow_holes = true},
		["lang"] = {}, -- This parameter is not used and does nothing, but is allowed for futureproofing.
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local items = {}
	
	for i = 1, math.max(args[1].maxindex, args["n"].maxindex) do
		local pron = args[1][i]
		local note = args["n"][i]
		
		if pron or note then
			table.insert(items, {pron = pron, note = note})
		end
	end
	
	-- Format
	return m_IPA.format_IPA_multiple(nil, items)
end

return export