Module:IPA

local gsub = mw.ustring.gsub local U = mw.ustring.char

local p = {}

local function IPAspan(text) return ''..text..' ' end

local function isEmpty(text) return text == nil or text == "" end

function p.IPA(frame) local args = frame:getParent.args[1] and frame:getParent.args or frame.args local namespace = mw.title.getCurrentTitle.nsText local text, lang = "", "" if not isEmpty(args[2]) then text = args[2] lang = args[1] elseif not isEmpty(args[1]) then text = args[1] end local IPApage = mw.loadData("Module:IPA/data")[lang] local err = {} if not IPApage and not isEmpty(lang) then table.insert(err, "[No IPA key for the language code " .. lang.."]") end -- if isEmpty(text) then		if namespace == "Template" or namespace == "Module" then			text = "[ɪɡˈzɑːmpəl]"		else			error("No text provided to Template:IPA")		end	end -- if isEmpty(lang) and args[2] then table.insert(err, "[language code?]") end if isEmpty(text) then table.insert(err, "[IPA symbols?]") end text = gsub(text, U(0x67), U(0x261)) -- Replace regular g with IPA g.	text = IPAspan(text) local output = IPApage and "" .. text .. "" or text or "" if not err[1] then err = "" else err = "" .. table.concat(err) .. ""	end -- Makes error messages show only in preview mode. if frame:preprocess("") == "" then return output .. err else return output end end

return p