get_name_list ('translator', citeq_args, qid, wdl) -- modify citeq_args table with translators from Wikidata
end
end  
for k, v in pairs(citeq_args) do
if in_array (v, {'()', 'unset', 'ignore'}) or 'string' ~= type(k) then -- empty accept-as-is-written () markup to indicate an empty/unused parameter value, other ((...)) markups are deliberately passed down to
citeq_args[k] = nil
elseif in_array (v, {'((unset))', '((ignore))'}) then -- strip off markup for free-text values clashing with local keywords
citeq_args[k] = 'unset'
end
end  
local author_count = 0
for k, v in pairs(citeq_args) do
if k:find("^author%d+$") then
author_count = author_count + 1
end
end
if author_count > 8 then -- convention in astronomy journals, optional mode for this?
if 'all' == citeq_args['display-authors'] then
citeq_args['display-authors'] = nil; -- unset because no longer needed
else
citeq_args['display-authors'] = citeq_args['display-authors'] or 3 -- limit to three displayed names
end
end  
local editor_count = 0
for k, v in pairs(citeq_args) do
if k:find("^editor%d+$") then
editor_count = editor_count + 1
end
end
if editor_count > 8 then -- convention in astronomy journals, optional mode for this?
if 'all' == citeq_args['display-editors'] then
citeq_args['display-editors'] = nil; -- unset because no longer needed
else
citeq_args['display-editors'] = citeq_args['display-editors'] or 3 -- limit to three displayed names
end
end  
-- change edition to ordinal if it's set and numeric
citeq_args.edition = citeq_args.edition and p.makeOrdinal(citeq_args.edition)  
-- code to make a guess what template to use from the supplied parameters
-- (first draft for proof-of-concept)
if citeq_args.isbn then
template = template or "book"
citeq_args.asin = nil -- suppress ASIN if ISBN exists
elseif citeq_args.journal then
template = template or "journal"
elseif citeq_args.website then
template = template or "web"
end  
-- template is CS1 designator: journal, web, news, etc.
if template then
-- citeq_args.mode = citeq_args.mode or "cs1" -- a cs1 template already knows that it is cs1 so this line is superfluous
template = "Cite " .. template
else
-- citeq_args.mode = citeq_args.mode or "cs2" -- a cs2 template already knows that it is cs2 so this line is superfluous
template = "Citation"
end  
-- |id= could hold more than one identifier pulled from Wikidata not supported by , now only add our qid to the list
local list_sep = '. '
if citeq_args.mode ~= 'cs1' then
list_sep = ', '
end
local id = 'விக்கித்தரவு&nbsp;' .. qid .. '' -- go through "WDQ (identifier)" redirect to reduce clutter in "What links here" and improve reverse lookup. Keep in sync with .
local old_id = citeq_args.id
if wdl then -- show WD logo
id = id .. '' -- possibly replace by WD edit icon?
end
if is_set (old_id) then
citeq_args.id = old_id .. list_sep .. id -- append to user-specified contents
else
citeq_args.id = id
end  
-- clean up any blank parameters
for k, v in pairs(citeq_args) do
if v == "" then citeq_args[k] = nil end
end  
-- if |expand=<anything>, write a nowiki'd version to see what the template call looks like
if expand then
local expand_args = { "
local erratumid = getPropertyIDs( { "P2507", qid = qid, fwd = "ALL", osd = "no", rank = "best", maxvals = 1 } )
if erratumid then
erratumid = " (erratum)" .. ""
else
erratumid = ""
end  
local opt_cat = ''
if getValue( {"P5824", ps = 1, qid = qid} ) then
opt_cat = ''
end
if getValue( {"P1366", ps = 1, qid = qid} ) then
opt_cat = opt_cat .. ''
end
return :expandTemplate{title = template, args = citeq_args} .. erratumid .. opt_cat -- render the template
end  
function p.cite_q
local args = {}
for k, v in pairs(:getParent.args) do
if v ~= "" then args[k] = v end
end
for k, v in pairs(.args) do
if v ~= "" then args[k] = v end
end
args.qid = args.qid or args[1] or ""
if args.qid == "" then return nil end
args[1] = nil  
local citesep = (args.citesep or "")
if citesep == "" then citesep = ", " end
citesep = citesep:gsub('"', '') -- strip double quotes after setting default to allow |citesep="" as a blank separator
args.citesep = nil  
local tag = args.tag or ""
if tag == "" then tag = nil end
args.tag = nil  
local list = args.list or ""
if list == "" then list = nil end
args.list = nil  
args.language = args.language or args.lang
args.lang = nil  
local cites = {}
for q in args.qid:gmatch("Q%d+") do
-- make a new copy of the arguments
local newargs = {}
for k, v in pairs(args) do
if k ~= "qid" then
newargs[k] = v
end
end
newargs.qid = q
if tag == "ref" then
cites[#cites + 1] = :callParserFunction{ name = "#tag:ref", args = { p._cite_q(newargs), name = q } }
-- expand like this: args = { p._cite_q(newargs), name = 'foo', group = 'bar' }
else
cites[#cites + 1] = p._cite_q(newargs)
end
end  
if list then
return :expandTemplate{ title = list, args = cites }
else
return table.concat(cites, citesep)
end
end  
return p