Module:Redirect-distinguish: Difference between revisions

Added pronoun detection code I originally implemented in Module:About-distinguish
m (Shorter form for orList)
(Added pronoun detection code I originally implemented in Module:About-distinguish)
Line 12:
 
function p._redirectDistinguish(args)
--Check for first argument, and evaluate redirect if present
if not args[1] then
return mHatnote.makeWikitextError(
Line 27 ⟶ 28:
args[1] = args[1] .. '[[Category:Missing redirects]]'
end
--Check for second argument
if not args[2] then
return mHatnote.makeWikitextError(
Line 34 ⟶ 37:
)
end
 
--Get pronoun from Wikidata. Really basic, but it should work.
local pronouns = {
['female'] = 'She is',
['transgender female'] = "She is",
['male'] = 'He is',
['transgender male'] = 'He is',
['default'] = 'They are'
}
local wde = mw.wikibase.getEntity()
local p31 = (wde and wde:formatPropertyValues('P31').value) == 'human'
local p21 = wde and wde:formatPropertyValues('P21').value
local pronoun = p31 and (pronouns[p21] or pronouns['default']) or 'It is'
 
--Assemble hatnote and return
args = mTableTools.compressSparseArray(args)
--Assignment by removal here makes for convenient concatenation later
local redirect = table.remove(args, 1)
local text = string.format(
'"%s" redirects here. It is%s not to be confused with %s.',
redirect,
pronoun,
mHatlist.orList(args, true)
)
Anonymous user