This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing.
-- This module implements [[Template:IPAc-en]].localdata=mw.loadData('Module:IPAc-en/data')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)-- mw.html doesn't properly escape '|'returnstring.format('<span title="%s">%s</span>',mw.text.encode(tooltip,'|'),label)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]=mw.getCurrentFrame():extensionTag({name='templatestyles',args={src='Module:IPA/styles.css'}})ret[#ret+1]=string.format('<span class="IPA-label IPA-label-small">%s</span>',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'):attr('lang','en-fonipa'):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