Module:IPAc-en: Difference between revisions

no edit summary
m (1 revision imported)
en>Centrist16
No edit summary
Line 2:
 
local data = mw.loadData('Module:IPAc-en/data')
local currentFrame = mw.getCurrentFrame()
local p = {}
 
-- Global container for tracking categories
local categoryHandler = require('Module:Category handler').main
local categories = {}
 
Line 25 ⟶ 27:
return data.pronunciation[id].text
end
end
 
local function getFilepath(file)
return mw.getCurrentFrame():callParserFunction('filepath', file)
end
 
local function makeAudioLink(file)
categories["Articles including recorded pronunciations"] = true
local span = mw.html.create('span')
span
:addClass('noexcerpt')
:wikitext(string.format(
'[[File:Speakerlink-new.svg|11px|link=%s|Listen]]',
getFilepath(file)
))
:tag('sup')
:tag('span')
:css('color', '#00e')
:css('font', 'bold 80% sans-serif')
:css('padding', '0 .1em')
:addClass('IPA')
:wikitext(string.format('[[:File:%s|i]]', file))
return tostring(span)
end
 
Line 70 ⟶ 49:
 
local function renderCategories()
local ret = {}''
ret = categoryHandler{
for cat in pairs(categories) do
[1] = 'yes', -- Add categories in these namespaces
table.insert(ret, string.format('[[Category:%s]]', cat))
main = 1,
wikipedia = 1,
file = 1,
template = 1,
help = 1,
category = 1,
portal = 1,
book = 1,
draft = 1,
module = 1,
}
if fileret and file ~== 'yes' then
ret = {}
for cat in pairs(categories) do
:wikitexttable.insert(ret, string.format('[[:FileCategory:%s|i]]', filecat))
end
return table.concatsort(ret)
ret = table.concat(ret)
else
ret = ''
end
table.sort(return ret)
return table.concat(ret)
end
 
Line 100 ⟶ 99:
table.concat(pron)
)
end
end
 
-- Audio link
do
local file = args.audio and trim(args.audio)
if file and file ~= '' then
ret[#ret + 1] = makeAudioLink(file)
end
end
Line 137 ⟶ 128:
categories["Ill-formatted IPAc-en transclusions"] = true
words[#words + 1] = formatPhonemeGroup(phonemes)
-- Call [[Template:Error]]
local errorText = currentFrame:expandTemplate{
title = 'Template:Error',
args = {
string.format("[invalid input: '%s']", id)
}
}
words[#words + 1] = makeTooltip(
"'''[unsupported input]'''"errorText,
'Unrecognized symbol'
)
Line 166 ⟶ 164:
-- 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')
:addClass('IPA nopopups noexcerpt')
:wikitext(string.format(
'[[W:Help:IPA for /English|%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])) == 'uk' then
categories["Articles including recorded pronunciations (UK English)"] = true
elseif args[1] and string.lower(trim(args[1])) == 'us' then
categories["Articles including recorded pronunciations (US English)"] = true
else
categories["Articles including recorded pronunciations (English)"] = true
end
ret[#ret + 1] = makeAudioLink(file)currentFrame:expandTemplate{
title = 'Template:IPA audio link', args = { file } }
end
end
-- Nowrap and categories
ret = makeNowrapSpan(table.concat(ret)) .. renderCategories()
Anonymous user