This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing.
-- This module implements [[Template:IPAc-en]].-- local data = mw.loadData('Module:IPAc-en/data')localdata=mw.loadData('Module:IPAc-en/data/sandbox')localp={}-- Global container for tracking categorieslocalcategories={}-- Trims whitespace from a stringlocalfunctiontrim(s)returns:match('^%s*(.-)%s*$')end-- This implements [[Template:Nowrap]].localfunctionmakeNowrapSpan(s)localspan=mw.html.create('span'):addClass('nowrap'):wikitext(s)returntostring(span)endlocalfunctionmakePronunciationText(id)id=idandstring.lower(trim(id))ifidandid~=''anddata.pronunciation[id]thenreturndata.pronunciation[id].textendend-- This adds a tooltip icon to a label. It implements [[Template:H:title]].localfunctionmakeTooltip(label,tooltip)localspan=mw.html.create('span'):attr('title',tooltip):wikitext(label)returntostring(span)endlocalfunctionformatPhonemeGroup(phonemes)if#phonemes>0thenlocalspan=mw.html.create('span'):css('border-bottom','1px dotted'):wikitext(table.concat(phonemes))returntostring(span)elsereturn''endendlocalfunctionrenderCategories()localret={}forcatinpairs(categories)dotable.insert(ret,string.format('[[Category:%s]]',cat))endtable.sort(ret)returntable.concat(ret)endfunctionp._main(args)localret={}locali=0-- Keeps track of numbered args-- Pronunciationdolocalpron={}whiletruedoi=i+1localpronItem=makePronunciationText(args[i])ifpronItemthenpron[#pron+1]=pronItempron[#pron+1]=' 'elsebreakendendif#pron>0thenret[#ret+1]=string.format('<small>%s</small>',table.concat(pron))endend-- Phonemesdo-- 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.localwords={}words[#words+1]='/'-- Opening slashi=i-1-- Set up i again as it was changed in the pronunciation looplocalidrepeatlocalphonemes={}localisWordEnd=falsewhilenotisWordEnddoi=i+1id=args[i]id=idandtrim(id)ifnotidthenisWordEnd=truewords[#words+1]=formatPhonemeGroup(phonemes)elseifid~=''thenlocalt=data.phonemes[id]ifnottthen-- We were passed an invalid id.isWordEnd=truecategories["Ill-formatted IPAc-en transclusions"]=truewords[#words+1]=formatPhonemeGroup(phonemes)words[#words+1]=makeTooltip("'''[unsupported input]'''",'Unrecognized symbol')elseifnott.labelthen-- The data module contains bad data, so throw an error.error(string.format("no label was found for id '%s'",tostring(id)))elseift.tooltipthen-- We are dealing with a regular phoneme.phonemes[#phonemes+1]=makeTooltip(t.label,t.tooltip)else-- We are dealing with a separator.isWordEnd=truewords[#words+1]=formatPhonemeGroup(phonemes)words[#words+1]=t.labelendendenduntilnotidwords[#words+1]='/'-- Closing slash-- Wrap the words in a link to IPA help.localspan=mw.html.create('span'):addClass('IPA nopopups'):wikitext(string.format('[[Help:IPA for English|%s]]',table.concat(words)))ret[#ret+1]=tostring(span)end-- Audio linkdolocalfile=args.audioandtrim(args.audio)iffileandfile~=''thencategories["Articles including recorded pronunciations"]=trueret[#ret+1]=mw.getCurrentFrame():expandTemplate{title='Template:IPA audio link',args={file}}endend-- Nowrap and categoriesret=makeNowrapSpan(table.concat(ret))..renderCategories()-- Reset the categories table in case we are run again.categories={}returnretendfunctionp.main(frame)returnp._main(frame:getParent().args)endreturnp