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]].localdata=mw.loadData('Module:IPAc-en/data/sandbox')localp={}-- Global container for tracking categorieslocalcategoryHandler=require('Module:Category handler').mainlocalcategories={}-- Trims whitespace from a stringlocalfunctiontrim(s)returns:match('^%s*(.-)%s*$')end-- This implements [[Template:Nowrap]].localfunctionmakeNowrapSpan(s)localspan=mw.html.create('span'):addClass('rt-commentedText')-- Works with [[MediaWiki:Gadget-ReferenceTooltips.js]]: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=''ifcategoryHandler{true}thenret={}forcatinpairs(categories)dotable.insert(ret,string.format('[[Category:%s]]',cat))endtable.sort(ret)ret=table.concat(ret)elseret=''endreturnretendfunctionp._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(string.format("<strong class=\"error\">[invalid input: '%s']</strong>",id),'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')-- Suppress Navigation popups and Page Previews (aka Hovercards):addClass('IPA nopopups noexcerpt'):wikitext(string.format('[[Help:IPA/English|%s]]',table.concat(words)))ret[#ret+1]=tostring(span)end-- Audio linkdolocalfile=args.audioandtrim(args.audio)iffileandfile~=''thencategories["Pages 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