Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Module:IPA

Permanently protected module
From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]
This module depends on the following other modules:
CSSThis module usesTemplateStyles:
WarningThis Lua module is used onapproximately 162,000 pages.
To avoid major disruption and server load, any changes should be tested in the module's/sandbox or/testcases subpages, or in your ownmodule sandbox. The tested changes can be added to this page in a single edit. Consider discussing changes on thetalk page before implementing them.

SeeTemplate:IPA.

The abovedocumentation istranscluded fromModule:IPA/doc.(edit |history)
Editors can experiment in this module'ssandbox(edit |diff) andtestcases(edit |run) pages.
Subpages of this module.

require('strict')localp={}localfunctionmultiFind(s,patterns,init)locali,j=mw.ustring.find(s,patterns[1],init)forn=2,#patternsdolocali2,j2=mw.ustring.find(s,patterns[n],init)ifi2and(notiori2<i)theni,j=i2,j2endendreturni,jendlocalfunctionwrapAtSpaces(s)returnmw.ustring.gsub(s,'(%s+)','<span class="wrap">%1</span>')endlocalfunctionwrapAtSpacesSafely(s)localpatterns={'%[%[[^%]|]-%s[^%]|]-|',-- Piped links'</?[A-Za-z][^>]-%s[^>]->'-- HTML tags}s=mw.ustring.gsub(s,'%[%[([^%]|]-%s[^%]|]-)%]%]','[[%1|%1]]')-- Pipe all linkslocalt={}localinitwhiletruedolocali,j=multiFind(s,patterns,init)ifnotithenbreakendlocalpre=wrapAtSpaces(mw.ustring.sub(s,init,i-1))-- What precedes the matchtable.insert(t,pre)table.insert(t,mw.ustring.sub(s,i,j))-- The matchinit=j+1endlocalpost=wrapAtSpaces(mw.ustring.sub(s,init))-- What follows the last matchtable.insert(t,post)returntable.concat(t)endlocalfunctioncheckNamespace(isDebug)returnisDebugorrequire('Module:Category handler').main({true})endlocalfunctionrenderCats(cats,isDebug)ifnotcats[1]ornotcheckNamespace(isDebug)thenreturn''endlocalt={}for_,vinipairs(cats)dotable.insert(t,string.format('[[%sCategory:%s]]',isDebugand':'or'',v))endreturntable.concat(t)endlocalfunctionresolveSynonym(s)returnmw.loadData('Module:Lang/ISO 639 synonyms')[s]orsendlocalfunctionsplitTag(s)locallangCode=s:gsub('%-.*',''):lower()langCode=resolveSynonym(langCode)localregionCode=s:match('%-(.+)')localisPrivate=regionCodeandregionCode:sub(1,2)=='x-'returnlangCode,regionCode,isPrivateendlocalfunctiongetLangName(code,link,raw)returnrequire('Module:Lang')._name_from_tag({code,link=link,raw=raw,-- Without linking, "{{IPA}}" gets expanded in some contextstemplate='[[Template:IPA|IPA]]'})endlocalfunctionlinkLang(name,target,link)returnlink=='yes'andstring.format('[[%s|%s]]',targetorname..' language',name)ornameendfunctionp._main(args)localret,cats={},{}localisDebug=args.debug=='yes'locals,langCode,regionCode,isPrivate-- Guide-linking modeifargs[2]andargs[2]~=''thenlocaldata=mw.loadData('Module:IPA/data')localisGeneric=args.generic=='yes's=args[2]langCode,regionCode,isPrivate=splitTag(args[1])locallangData=data.langs[langCode]or{}ifregionCodethenifnotisPrivatethenregionCode=regionCode:upper()endiflangData.dialectsandlangData.dialects[regionCode]then-- Overwrite language data with the dialect'slocalnewLangData={}fork,vinpairs(langData)doifk~='dialects'thennewLangData[k]=vendendlocaldialectData=langData.dialects[regionCode]ifdialectData.aliasOfthen-- Use the canonical region coderegionCode=dialectData.aliasOfisPrivate=regionCode:sub(1,2)=='x-'dialectData=langData.dialects[regionCode]end-- Lowercase IANA variantifdialectData.isVariantthenregionCode=regionCode:lower()endfork,vinpairs(dialectData)donewLangData[k]=vendlangData=newLangDataelseisGeneric=trueendendlocalfullLangCode=regionCodeandlangCode..'-'..regionCodeorlangCodelocallangName=langData.nameandlinkLang(langData.name,langData.link,args.link)orgetLangName(fullLangCode,args.link)iflangName:sub(1,5)=='<span'then-- Module:Lang has returned an errorreturnlangName..renderCats({'IPA template errors'},isDebug)endifargs.cat~='no'thenlocalcatLangName=langData.nameorgetLangName(fullLangCode,nil,'yes')ifcatLangName:sub(1,5)=='<span'then-- Module:Lang has returned an error, but it's not fataltable.insert(cats,'IPA template errors')mw.addWarning(catLangName)elsetable.insert(cats,string.format('Pages with %s IPA',catLangName))endend-- Labellocallabel=args.labelifnotlabelthenlocallabelCode=args[3]andargs[3]:lower()orlangData.defaultLabelCodeiflabelCode==''thenlabel=''elselocallangTextiflangData.textthenlangText=linkLang(langData.text,mw.ustring.match(langName,'^%[%[([^|%]]+)'),args.link)elselangText=mw.ustring.gsub(langName,'^%[%[(([^|]+) languages)%]%]$','[[%1|%2]]')langText=mw.ustring.gsub(langText,' languages(%]?%]?)$','%1')endiflabelCodeanddata.labels[labelCode]thenlabel=data.labels[labelCode]:format(langText)elselabel=data.defaultLabel:format(langText)endendendiflabelandlabel~=''thenlocalspan=mw.html.create('span'):addClass('IPA-label'):wikitext(label)ifargs.small~='no'thenspan:addClass('IPA-label-small')table.insert(ret,mw.getCurrentFrame():extensionTag({name='templatestyles',args={src='Module:IPA/styles.css'}}))endtable.insert(ret,tostring(span)..' ')end-- Bracketss=(notisGenericandlangData.formator'&#91;%s&#93;'):format(s)-- Link to keylocalkey=notisGenericandlangData.keyordata.defaultKeys=string.format('[[%s|%s]]',key,s)else-- Basic modes=args[1]ifargs.langandargs.lang~=''thenlangCode,regionCode,isPrivate=splitTag(args.lang)endifargs.cat~='no'thentable.insert(cats,'Pages with plain IPA')endend-- Transcriptiondolocallang=(langCodeor'und')..'-Latn'ifnotisPrivateandregionCodethenlang=lang..'-'..regionCodeendlang=lang..'-fonipa'localspan=mw.html.create('span'):addClass('IPA'):addClass(args.class):attr('lang',lang)-- wrap=all: Do nothing-- wrap=none: Never break-- Otherwise: Break at spaces onlyifargs.wrap~='all'thenspan:addClass('nowrap')ifargs.wrap~='none'thens=wrapAtSpacesSafely(s)endendif(notargs[2]orargs[2]=='')andargs.tooltip~=''thenlocaltooltip=args.tooltipor'Representation in the International Phonetic Alphabet (IPA)'span:attr('title',tooltip)ends=tostring(span:wikitext(s))table.insert(ret,s)end-- Audiolocalaudio=args.audio~=''andargs.audioorargs[4]~=''andargs[4]ifaudiothenlocalbutton=mw.getCurrentFrame():expandTemplate({title='Audio',args={audio,''}})table.insert(ret,' '..button)table.insert(cats,'Pages including recorded pronunciations')end-- Categoriestable.insert(ret,renderCats(cats,isDebug))returntable.concat(ret)endfunctionp.main(frame)localargs=frame:getParent().argsifnotargs[1]thenreturn''endfori,vinipairs(args)doargs[i]=mw.text.trim(v)endreturnp._main(args)endreturnp
Retrieved from "https://en.wikipedia.org/w/index.php?title=Module:IPA&oldid=1265527573"
Category:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp