local p;
---Maximum number version of Ethnologue for which we have a {{Ethnologue##}} template
local maxEthnologueVersion=25
function p.ref(frame)
args=frame.args or frame:getParent().args
return generateRef(frame,args)
end
local function generateRef(frame,args)
local first=string.tolower(args[1])
if first=="elp" then
return frame:preprocess("<ref name=ELP/>")
elseif first=="aiatsis" then
return frame:preprocess("<ref name=AIATSIS/>")
elseif first=="guthrie" then
return frame:preprocess("<ref name=Guthrie/>")
elseif first=="ne2007" then
return frame:extensionTag("ref",
"Mikael Parkvall, \"Världens 100 största språk 2007\" (The World's 100 Largest Languages in 2007), in ''[[Nationalencyklopedin]]''",
{name="NE100"})
elseif first=="ne2010" then
return frame:extensionTag("ref",
"\"Världens 100 största språk 2010\" (The World's 100 Largest Languages in 2010), in ''[[Nationalencyklopedin]]''",
{name="NE100_2"})
elseif first=="linglist" then
local refName=maskBlank(params["refname"],nonil(params["name"]))
local iso3=nonil(params["iso3"])
return frame:extensionTag("ref",
"[https://web.archive.org/web/20200101010101/http://multitree.org/codes/"..iso3.." "..refName.."] at ''[[MultiTree]]'' on [[the Linguist List]]",
{name="linglist"})
elseif string.sub(first,1,1)=="e" and #first==3 then
ethnologueVer=tonumber(string.sub(first,2,-1))
if ethnologueVer then
if ethnologueVer>maxEthnologueVersion then
return "<span class=\"error\">[[Template:Ethnologue"
..ethnologueVer.."]] does not exist</span>"
else
local iso3=nonil(params["iso3"])
local refName=maskBlank(params["refname"],nonil(params["name"]))
local results={}
local ethnologueParams={iso3,refName}
if(iso3~="") then
table.insert(frame:expandTemplate
{name="Ethnologue"..ethnologueVer,args=ethnologueParams})
end
end
end
end
end
local familyColors=require("Module:Infobox language/family color")
local infoboxImage=require("Module:InfoboxImage").InfoboxImage
local function nonil(data)
if(data==nil) then
return ""
else
return data
end
end
local function maskBlank(data,default)
if (data==nil or data=="") then
return default
else
return data
end
end
local function nowrap(text)
return "<span class=\"nowrap\">"..text.."</span>"
end
local function image(params,name)
image=nonil(params[name])
size=nonil(params[name.."size"])
alt=nonil(params[name.."alt"])
return InfoboxImage({["args"]=
{
["image"]=image,
["size"]=size,
["sizedefault"]="200px",
["alt"]=alt
}
})
end
local function addParam(params, key, value)
if value then
index=params[1]
params["label"..index]=key
params["data"..index]=value
params[1]=index+1
end
end
---main function for Template:Infobox language
function p.individual(frame)
return main(frame,galse)
end
--main function for Template:Infobox language family
function p.family(frame)
return main(frame,true)
end
local function main(frame,isFamily)
local inParams = frame:getParent().args
local outParams={1}
local cats=""
local familyColor=nonil(inParams["familycolor"])
familyColor=nonil(familyColors[familyColor])
local setting=nonil(inParams["setting"])
local creator=nonil(inParams["creator"])
local speakers=nonil(inParams["speakers"])
local isConlang=(setting~="") or (creator~="") or (familyColor==familyColors["conlang"])
local fontColor=maskBlank(inParams["fontcolor"],"black")
local name=nonil(inParams["name"])
local date=nonil(inParams["date"])
local ref=nonil(inParams["ref"])
local acceptance=nonil(inParams["acceptance"])
if acceptance~="" then
acceptance="("..acceptance..")"
end
if isFamily then
outParams["bodystyle"] = "width:"..maskBlank(inParams["boxsize"],"22em")
local style="backgroundcolor:"..familyColor
outParams["aboveStyle"]=style
outParams["subheaderstyle" ]=style
outParams["above"]=inParams["name"]
outParams["subheader"]=nonil(inParams["altname"])
outParams["subheader2"]=acceptance
else
outParams["bodyclass"] = "vevent"
local width=inParams["boxsize"]
if width==nil then
outParams["bodystyle"]=""
else
outParams["bodystyle"]="width:"..width
end
local style="color:"
if(isConlang) then
style=style.."white"
else
style=style..fontColor
end
style=style.."; background-color: "
if isConlang then
style=style.."#114057"
else
style=style..familyColor
end
style=style..";"
outParams["aboveStyle"]="font-size:125%;"..aboveStyle
local above
if name~="" then
above=name
else
above=mw.wikibase.getLabel()
if above=="" then
above=string.gsub(mw.title.getCurrentTitle().text,"%s+%b()$","",1)
end
end
outParams["above"]=above
outParams["aboveclass"]="above"
outParams["subheaderstyle"]="font-size:110%;"..style
outParams["subheader1"]=nonil(inParams["altname"])
outParams["subheader2"]=nonil(inParams["nativename"])
outParams["subheader3"]=acceptance
outParams["image"]=image(inParams,"image")
outParams["captionstyle"] = "padding:0.35em 0.35em 0.25em;line-height:1.25em;"
outParams["caption"]=nonil(inParams["imagecaption"])
outParams["headerstyle"]=style
--to ensure gap between any long/nonwrapped label and subsequent data on same line
outParams["labelstyle"]="white-space:nowrap;padding-right:0.65em"
outParams["datastyle"]="line-height:1.3em;"
addParam(outParams,"Pronunciation",inParams["pronunciation"])
local label2,data2
if isConlang then
label2="Created by"
data2=maskBlank(inParams["creator"],"-")
else
label2="Native to"
data2=inParams["state"] or nonil(inParams["states"])
end
addParam(outParams,label2,data2)
addParam(outParams,"Date",inParams["created"])
if isConlang then
addParam(outParams,"Setting and usage",inParams["setting"])
else
addParam(outParams,"Region",inParams["region"])
end
end
addParam(outParams,"Ethnicity",inParams["ethnicity"])
if isFamily then
addParam(outParams,"Geographic<br>distribution",maskBlank(inParams["region"],"-"))
end
local extinct=nonil(inParams["extinct"])
local era=nonil(inParams["era"])
local speakersData
if extinct~="" then
outParams["label"..counter]="[[Extinct language|Extinct]]"
if extinct=="?" then
speakersData="(date missing)[[Category:Language articles with unknown extinction date]]"
else
speakersData=extinct
end
elseif era~="" then
outParams["label"..counter]="Era"
speakersData=era
else
local speakersLabel=inParams["speakers_label"]
if speakersLabel then
outParams["label"..counter]=speakersLabel
elseif creator~="" then
outParams["label"..counter]="Users"
else
outParams="<div style=\"display:inline-block;\">Native speakers</div>"
end
if speakers~="" then
if string.upper(date)=="NA" then
speakersData=speakers
else
if speakers =="none" then
speakersData="''None''"
elseif speakers~="?" then
if date~="" then
if isSign then
speakersData=nowrap(speakers.." "..nonil(inParams["dateprefix"])..date)
else
if date=="no date" then
speakersData="(undated figure of "..speakers..")"
else
local dateNum=tonumber(string.sub(date,4))
if dateNum~=nil then
--[[The following changes the display depending on the age of the
data. Limit set to 25 years, as a population can double in that
time.]]
if os.date("%Y")-dateNum<25 then
speakersData=nowrap(speakers.." "..nonil(inParams["dateprefix"])..date)
else
speakersData=speakers.." cited "..nonil(inParams["dateprefix"])..date
if ref=="e19" then
cats=cats.."[[Category:Language articles with old Ethnologue 19 speaker data]]"
elseif ref=="e18" then
cats=cats.."[[Category:Language articles with old Ethnologue 18 speaker data]]"
else
cats=cats.."[[Category:Language articles with old speaker data]]"
end
end --os.date("%Y")-datenum<25
end --datenum~=nil
end --date=="no date"
end --isSign
else
speakersData=speakers
cats=cats.."[[Category:Language articles with speaker number undated]]"
end
end
end
end
end
---Categories should only be used in the mainspace; additionally, it should
---be possible to exclude from a specific page using the |no_cat parameter
if mw.title.getCurrentTitle().namespace~=0 or inParams["no_cat"]=="1" then
cats=""
end
return frame:expandTemplate{ title = "infobox", args = outParams }..cats
end
return p;