Jump to content
Wikipedia The Free Encyclopedia

Module:IPAc-en

From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]
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.
Page template-protected This module is currently protected from editing.
See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected.
Warning This Lua module is used on approximately 54,000 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.
This module depends on the following other modules:

This module implements {{IPAc-en }}. Please see the template page for documentation.

To edit the diaphoneme data, go to Module:IPAc-en/phonemes, and to edit the pronunciation data go to Module:IPAc-en/pronunciation.

This module also uses a data-formatting module at Module:IPAc-en/data.

The above documentation is transcluded from Module:IPAc-en/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.

 -- This module implements [[Template:IPAc-en]].

 localdata=mw.loadData('Module:IPAc-en/data')
 localp={}

 -- Global container for tracking categories
 localcategoryHandler=require('Module:Category handler').main
 localcategories={}

 -- Trims whitespace from a string
 localfunctiontrim(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)
 end

 localfunctionmakePronunciationText(id)
 id=idandstring.lower(trim(id))
 ifidandid~=''anddata.pronunciation[id]then
 returndata.pronunciation[id].text
 end
 end

 -- 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
 )
 end

 localfunctionformatPhonemeGroup(phonemes)
 if#phonemes>0then
 localspan=mw.html.create('span')
 :css('border-bottom','1px dotted')
 :wikitext(table.concat(phonemes))
 returntostring(span)
 else
 return''
 end
 end

 localfunctionrenderCategories()
 localret=''

 ifcategoryHandler{true}then
 ret={}
 forcatinpairs(categories)do
 table.insert(ret,string.format('[[Category:%s]]',cat))
 end
 table.sort(ret)
 ret=table.concat(ret)
 else
 ret=''
 end
 returnret
 end

 functionp._main(args)
 localret={}
 locali=0-- Keeps track of numbered args

 -- Pronunciation
 do
 localpron={}
 whiletruedo
 i=i+1
 localpronItem=makePronunciationText(args[i])
 ifpronItemthen
 pron[#pron+1]=pronItem
 pron[#pron+1]=' '
 else
 break
 end
 end
 if#pron>0then
 ret[#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)
 )
 end
 end

 -- Phonemes
 do
 -- 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 slash
 i=i-1-- Set up i again as it was changed in the pronunciation loop
 localid
 repeat
 localphonemes={}
 localisWordEnd=false
 whilenotisWordEnddo
 i=i+1
 id=args[i]
 id=idandtrim(id)
 ifnotidthen
 isWordEnd=true
 words[#words+1]=formatPhonemeGroup(phonemes)
 elseifid~=''then
 localt=data.phonemes[id]
 ifnottthen
 -- We were passed an invalid id.
 isWordEnd=true
 categories["Ill-formatted IPAc-en transclusions"]=true
 words[#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=true
 words[#words+1]=formatPhonemeGroup(phonemes)
 words[#words+1]=t.label
 end
 end
 end
 untilnotid
 words[#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 link
 do
 localfile=args.audioandtrim(args.audio)
 iffileandfile~=''then
 categories["Pages including recorded pronunciations"]=true
 ret[#ret+1]=mw.getCurrentFrame():expandTemplate{
 title='Template:IPA audio link',args={file}}
 end
 end

 -- Nowrap and categories
 ret=makeNowrapSpan(table.concat(ret))..renderCategories()

 -- Reset the categories table in case we are run again.
 categories={}

 returnret
 end

 functionp.main(frame)
 returnp._main(frame:getParent().args)
 end

 returnp

AltStyle によって変換されたページ (->オリジナル) /