-- This module implements .
local data = mw.loadData('Module:Sandbox/Þjarkur/IPAc-is/data')local p =
-- Global container for tracking categorieslocal categoryHandler = require('Module:Category handler').mainlocal categories =
-- Trims whitespace from a stringlocal function trim(s) return s:match('^%s*(.-)%s*$')end
-- This implements .local function makeNowrapSpan(s) local span = mw.html.create('span') :addClass('nowrap') :wikitext(s) return tostring(span)end
-- This adds a tooltip icon to a label. It implements .local function makeTooltip(label, tooltip) local span = mw.html.create('span') :attr('title', tooltip) :wikitext(label) return tostring(span)end
local function formatPhonemeGroup(phonemes) if #phonemes > 0 then local span = mw.html.create('span') :css('border-bottom', '1px dotted') :wikitext(table.concat(phonemes)) return tostring(span) else return endend
local function renderCategories local ret = ret = categoryHandler
if ret
function p._main(args) local ret = local i = 0 -- Keeps track of numbered args
-- Phonemes do -- Loop through the numbered args, separating them into phoneme groups -- and separator strings (both called "words" for convenience). We only -- underline the phoneme groups, not the separators. local words = words[#words + 1] = '/' -- Opening slash i = i - 1 -- Set up i again as it was changed in the pronunciation loop local id repeat local phonemes = local isWordEnd = false while not isWordEnd do i = i + 1 id = args[i] id = id and trim(id) if not id then isWordEnd = true words[#words + 1] = formatPhonemeGroup(phonemes) elseif id ~= then local t = data.phonemes[id] if not t then -- We were passed an invalid id. isWordEnd = true categories["Ill-formatted IPAc-en transclusions"] = true words[#words + 1] = formatPhonemeGroup(phonemes) words[#words + 1] = makeTooltip(string.format("[invalid input: '%s']", id), 'Unrecognized symbol') elseif not t.label then -- The data module contains bad data, so throw an error. error(string.format("no label was found for id '%s'", tostring(id))) elseif t.tooltip then -- We are dealing with a regular phoneme. phonemes[#phonemes + 1] = makeTooltip(t.label, t.tooltip) else -- We are dealing with a separator. isWordEnd = true words[#words + 1] = formatPhonemeGroup(phonemes) words[#words + 1] = t.label end end end until not id words[#words + 1] = '/' -- Closing slash
-- Wrap the words in a link to IPA help. local span = mw.html.create('span') -- Suppress Navigation popups and Page Previews (aka Hovercards) :addClass('IPA nopopups noexcerpt') :wikitext(string.format('%s', table.concat(words)))
ret[#ret + 1] = tostring(span) end
-- Audio link do local file = args.audio and trim(args.audio) if file and file ~= then -- if args[1] and string.lower(trim(args[1]))
'us' then -- categories["Pages including recorded pronunciations (US English)"] = true -- else -- categories["Pages including recorded pronunciations (English)"] = true -- end
ret[#ret + 1] = mw.getCurrentFrame:expandTemplate end end
-- Nowrap and categories ret = makeNowrapSpan(table.concat(ret)) .. renderCategories
-- Reset the categories table in case we are run again. categories =
return retend
function p.main(frame) return p._main(frame:getParent.args)end
return p