Anda dapat membuat halaman dokumentasi untuk buat pada modul Scribunto ini.
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
Penyunting dapat melakukan uji coba pada halaman bak pasir (buat | cermin) dan kasus uji (buat) modul ini.
Subhalaman modul ini.
require('strict') localp={} -- articles in which traditional Chinese preceeds simplified Chinese localt1st={ ["228 Incident"]=true, ["Chinese calendar"]=true, ["Lippo Centre, Hong Kong"]=true, ["Republic of China"]=true, ["Republic of China at the 1924 Summer Olympics"]=true, ["Taiwan"]=true, ["Taiwan (island)"]=true, ["Taiwan Province"]=true, ["Wei Boyang"]=true, } -- the labels for each part locallabels={ ["c"]="Hanzi", ["s"]="Hanzi sederhana", ["t"]="Hanzi tradisional", ["p"]="Pinyin", ["tp"]="Tongyong Pinyin", ["w"]="Wade–Giles", ["j"]="Jyutping", ["cy"]="Yale (Bahasa Kanton)", ["sl"]="Sidney Lau", ["poj"]="Pe̍h-ōe-jī", ["zhu"]="Zhuyin Fuhao", ["l"]="harfiah", } -- article titles for wikilinks for each part localwlinks={ ["c"]="Bahasa Tionghoa", ["s"]="Aksara Han sederhana", ["t"]="Aksara Han tradisional", ["p"]="Hanyu Pinyin", ["tp"]="Tongyong Pinyin", ["w"]="Wade–Giles", ["j"]="Jyutping", ["cy"]="Romanisasi Yale untuk bahasa Kanton", ["sl"]="Romanisasi Sidney Lau", ["poj"]="Pe̍h-ōe-jī", ["zhu"]="Bopomofo", } -- for those parts which are to be treated as languages their ISO code localISOlang={ ["c"]="zh", ["t"]="zh-Hant", ["s"]="zh-Hans", ["p"]="zh-Latn-pinyin", ["tp"]="zh-Latn", ["w"]="zh-Latn-wadegile", ["j"]="yue-jyutping", ["cy"]="yue", ["sl"]="yue", ["poj"]="nan", ["zhu"]="zh-Bopo", } localitalic={ ["p"]=true, ["tp"]=true, ["w"]=true, ["j"]=true, ["cy"]=true, ["sl"]=true, ["poj"]=true, } localsuperscript={ ["w"]=true, ["sl"]=true, } -- Categories for different kinds of Chinese text localcats={ ["c"]="[[Kategori:Artikel mengandung aksara Han]]", ["s"]="[[Kategori:Artikel mengandung aksara Han sederhana]]", ["t"]="[[Kategori:Artikel mengandung aksara Han tradisional]]", } functionp.Zh(frame) -- load arguments module to simplify handling of args localgetArgs=require('Module:Arguments').getArgs localargs=getArgs(frame) returnp._Zh(args) end functionp._Zh(args) localuselinks=not(args["links"]=="no")-- whether to add links localuselabels=not(args["labels"]=="no")-- whether to have labels localcapfirst=args["scase"]~=nil localt1=false-- whether traditional Chinese characters go first localj1=false-- whether Cantonese Romanisations go first localtestChar if(args["first"])then fortestCharinmw.ustring.gmatch(args["first"],"%a+")do if(testChar=="t")then t1=true end if(testChar=="j")then j1=true end end end if(t1==false)then localtitle=mw.title.getCurrentTitle() t1=t1st[title.text]==true end -- based on setting/preference specify order localorderlist={"c","s","t","p","tp","w","j","cy","sl","poj","zhu","l"} if(t1)then orderlist[2]="t" orderlist[3]="s" end if(j1)then orderlist[4]="j" orderlist[5]="cy" orderlist[6]="sl" orderlist[7]="p" orderlist[8]="tp" orderlist[9]="w" end -- rename rules. Rules to change parameters and labels based on other parameters ifargs["hp"]then -- hp an alias for p ([hanyu] pinyin) args["p"]=args["hp"] end ifargs["tp"]then -- if also Tongyu pinyin use full name for Hanyu pinyin labels["p"]="Hanyu Pinyin" end if(args["s"]andargs["s"]==args["t"])then -- Treat simplified + traditional as Chinese if they're the same args["c"]=args["s"] args["s"]=nil args["t"]=nil elseif(not(args["s"]andargs["t"]))then -- use short label if only one of simplified and traditional labels["s"]=labels["c"] labels["t"]=labels["c"] end localbody=""-- the output string localparams-- for creating HTML spans locallabel-- the label, i.e. the bit preceeding the supplied text localval-- the supplied text -- go through all possible fields in loop, adding them to the output fori,partinipairs(orderlist)do if(args[part])then -- build label label="" if(uselabels)then label=labels[part] if(capfirst)then label=mw.language.getContentLanguage():ucfirst(label) capfirst=false end if(uselinksandpart~="l")then label="[["..wlinks[part].."|"..label.."]]" end label=label..": " end -- build value val=args[part] if(cats[part])andmw.title.getCurrentTitle().namespace==0then -- if has associated category AND current page in article namespace, add category val=cats[part]..val end if(ISOlang[part])then -- add span for language if needed params={["lang"]=ISOlang[part],["xml:lang"]=ISOlang[part]} val=mw.text.tag({name="span",attrs=params,content=val}) elseif(part=="l")then -- put literals in quotes val="'"..val.."'" end if(italic[part])then -- italicise val="<i>"..val.."</i>" end ifstring.match(val,"</?sup>")thenval=val.."[[Kategori:Halaman yang menggunakan templat Zh dengan tag sup]]"end if(superscript[part])then -- superscript val=val:gsub("(%d)","<sup>%1</sup>"):gsub("(%d)</sup>%*<sup>(%d)","%1*%2"):gsub("<sup><sup>([%d%*]+)</sup></sup>","<sup>%1</sup>") end -- add both to body body=body..label..val.."; " end end if(body>"")then-- check for empty string returnstring.sub(body,1,-3)-- chop off final semicolon and space else--no named parameters; see if there's a first parameter, ignoring its name if(args[1])then -- if there is treat it as Chinese label="" if(uselabels)then label=labels["c"] if(uselinks)then label="[["..wlinks["c"].."|"..label.."]]" end label=label..": " end -- default to show links and labels as no options given ifmw.title.getCurrentTitle().namespace==0then -- if current page in article namespace val=cats["c"]..args[1] else val=args[1] end params={["lang"]=ISOlang["c"],["xml:lang"]=ISOlang["c"]} val=mw.text.tag({name="span",attrs=params,content=val}) returnlabel..val end return"" end end returnp