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 args = frame:getParent().args
	local lang = args["lang"] or (mw.title.getCurrentTitle().nsText == "Template" and "und") or error("Language code has not been specified. Please pass the parameter \"lang\" to the template.")
	lang = require("Module:languages").getByCode(lang) or error("The language code \"" .. lang .. "\" is not valid.")
 
	-- Gather parameters
	local pronunciations = {}
	local notes = {}
	local i = 1
	local pron = args[i]; if pron == "" then pron = nil end
 
	while pron do
		table.insert(pronunciations, pron)
 
		local note = args['n' .. i]; if note == "" then note = nil end
		notes[#pronunciations] = note
 
		i = i + 1
		pron = args[i]; if pron == "" then pron = nil end
	end
 
	return m_IPA.format_IPA_full(lang, pronunciations, notes)
end
 
-- Used for [[Template:IPAchar]].
function export.IPAchar(frame)
	local args = frame:getParent().args
 
	-- Gather parameters
	local pronunciations = {}
	local notes = {}
	local i = 1
	local pron = args[i]; if pron == "" then pron = nil end
 
	while pron do
		table.insert(pronunciations, pron)
 
		local note = args['n' .. i]; if note == "" then note = nil end
		notes[#pronunciations] = note
 
		i = i + 1
		pron = args[i]; if pron == "" then pron = nil end
	end
 
	-- Format
	return m_IPA.format_IPA_multiple(lang, pronunciations, notes)
end
 
return export