Mòideal:WD Ainm Oifigeil
Coltas
Documentation for this module may be created at Mòideal:WD Ainm Oifigeil/doc
-- fetch names and language tags from P1448 (official name) from some qid; prettify and return as a comma-separated string
require ('strict');
--[[--------------------------< E R R _ M S G >----------------------------------------------------------------
]]
local function err_msg (msg)
return string.format ('<span style="color:#bf3c2c"> %s', msg);
end
--[[--------------------------< M A I N >----------------------------------------------------------------------
{{#invoke:WD Ainm Oifigeil|main|<qid>}}
]]
local function main (frame)
local qid = frame.args[1]; -- required parameter is wikidata QID
if not qid or '' == qid then
return err_msg ('missing required qid'); -- missing qid, abandon with error message
end
local p1448_claims = mw.wikibase.getEntity (qid).claims.P1448;
if not p1448_claims then -- qid must have p1448 claims
return err_msg ('no p1448 claims'); -- if not, abandon with error message
end
local out_t = {}; -- output goes here
for i, v_t in ipairs (p1448_claims) do -- for each p1448 claim
local text = p1448_claims[i].mainsnak.datavalue.value.text; -- get the official name text
table.insert (out_t, string.format ('%s', text)); -- prettify
end
local selector = frame.args[2]; -- digit to select one of possibly many name/tag strings
if not selector or '' == selector then
return table.concat (out_t, ', '); -- concatenate all of the pretty strings and done
end
selector = tonumber (selector);
if not selector or not out_t[selector] then -- not a digit or out of range then
return err_msg ('invalid selector'); -- invalid selector, abandon with error message
end
return out_t[selector]; -- return the selected pretty string
end
--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]
return {
main = main
}