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 02:07, 17 October 2016 (+French). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

local IPApages = {
	["acw"] = "Help:IPA for Hejazi Arabic",
	["aeb"] = "Help:IPA for Tunisian Arabic",
	["af"] = "Help:IPA for Afrikaans",
	["ar"] = "Help:IPA for Arabic",
	["as"] = "Help:IPA for Assamese",
	["arc"] = "Help:IPA for Aramaic",
	["arz"] = "Help:IPA for Egyptian Arabic",
	["ast"] = "Help:IPA for Astur-Leonese",
	["be"] = "Help:IPA for Belarusian",
	["ber"] = "Help:IPA for Berber",
	["bg"] = "Help:IPA for Bulgarian and Macedonian",
	["bn"] = "Help:IPA for Bengali",
	["br"] = "Help:IPA for Breton",
	["ca"] = "Help:IPA for Catalan",
	["en"] = "Help:IPA for English",
	["eu"] = "Help:IPA for Basque",
	["fr"] = "Help:IPA for French",
	["hy"] = "Help:IPA for Armenian",
	["my"] = "Help:IPA for Burmese",
	["sa"] = "Help:IPA for Sanskrit",
	["sq"] = "Help:IPA for Albanian",
	["tr"] = "Help:IPA for Turkic dialects",
	["yue"] = "Help:IPA for Cantonese", -- Wikipedia-specific code
--	[""] = "",
}
-- For pages that describe multiple languages
IPApages["ext"] = IPApages["ast"]
IPApages["mwl"] = IPApages["ast"]
IPApages["tk"] = IPApages["tr"]
IPApages["az"] = IPApages["tr"]
IPApages["at"] = IPApages["tr"]
IPApages["gag"] = IPApages["tr"]
IPApages["mk"] = IPApages["bg"]


-- For pages that describe groups of languages
IPApages["kab"] = IPApages["ber"]
IPApages["rif"] = IPApages["ber"]

-- For aliases of symbols in the main list or other lists
IPApages["bre"] = IPApages["br"]
IPApages["bul"] = IPApages["bg"]
IPApages["mkd"] = IPApages["bg"]
IPApages["mya"] = IPApages["my"]
IPApages["cat"] = IPApages["ca"]
IPApages["san"] = IPApages["sa"]
IPApages["eng"] = IPApages["en"]
--[[
IPApages[""] = IPApages[""]
IPApages[""] = IPApages[""]
]]

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 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")
	local out = IPAspan(text)
	out = languageCode and IPApages[languageCode] and "[["..IPApages[languageCode].."|"..out.."]]" or out
	return out
end

return p