This Lua module is used on many pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them.
localp={}localmatch=mw.ustring.matchlocalgsub=mw.ustring.gsublocalU=mw.ustring.charlocalfunctionIPAspan(text)return'<span title="Representation in the International Phonetic Alphabet (IPA)" class="IPA">'..text..'</span>'endlocalfunctionine(text)iftext==""thenreturnnilelsereturntextendendfunctionp.tag(frame)locallinkHelpPage=require('Module:Yesno')(frame.args.link,false)localargs=frame:getParent().args[1]andframe:getParent().argsorframe.argslocalnamespace=mw.title.getCurrentTitle().nsTextlocaltext,langlocalerr={}localtrackingCategories={}localIPApage-- Tracks incorrect characters.localfunctiontrack(text)-- non-IPA gifmw.ustring.find(text,U(0x67))thenmw.log("Incorrect character g found in "..text)table.insert(trackingCategories,"[[Category:IPA templates with incorrect characters]]")endendiflinkHelpPagethentext=ine(args[2])lang=ine(args[1])iflangthenIPApage=mw.loadData("Module:IPA/data")[lang]ifnotIPApagethentable.insert(err,"[No IPA key for the language code "..lang.."]")endelsetable.insert(err,"[language code?]")endelsetext=ine(args[1])endlocaloutput=""iftextthenworkingString=text-- Remove targets of wikilinks.workingString=gsub(workingString,"%[%[([^|]+|)","")-- Remove HTML tags.workingString=gsub(workingString,"<[^>]+>","")track(workingString)text=IPAspan(text)ifIPApagethenoutput="[["..IPApage.."|"..text.."]]"elseiftextthenoutput=textendelsetable.insert(err,"[IPA symbols?]")endif#err>0thenerr="<sup>"..table.concat(err).."</sup>"elseerr=""end-- Makes the error message show only in preview mode.ifframe:preprocess("{{REVISIONID}}")==""thenoutput=output..errendreturnoutput..table.concat(trackingCategories)endreturnpreprocess