Jump to content

Module:IPA

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Erutuon (talk | contribs) at 23:48, 17 October 2016 (oops, wrong Unicode codepoint, and needs 0x at the beginning). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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

local p = {}

local function IPAspan(text)
	return '<span title="Representation in the International Phonetic Alphabet (IPA)" class="IPA">'..text..'</span>'
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 languageCode = args[2] and args[1] or nil
	local IPApages = require("Module:IPA/data")
	local text = (languageCode and args[2]) or args[1] or ( (namespace == "Template" or namespace == "Module") and "[ɪɡˈzɑːmpəl]") or error("Please provide valid IPA symbols to the IPA template")
	text = gsub(text, U(0x67), U(0x261)) -- Replace regular g with IPA g.
	local out = languageCode and IPApages[languageCode] and "[["..IPApages[languageCode].."|"..text.."]]" or text
	out = IPAspan(out)
	return out
end

return p