Module:Pronouns: Difference between revisions

From Pixlies
Content added Content deleted
(Created page with "local p = {} function p.pronoun(frame) local args = frame.args local pronouns = { he = "he", she = "she", they = "they" } local selectedPronouns = {} local categories = {} for i, arg in ipairs(args) do if pronouns[arg] then table.insert(selectedPronouns, pronouns[arg]) table.insert(categories, "[[Category:Players who are a " .. pronouns[arg] .. "]]") end end if #selectedP...")
 
No edit summary
 
(5 intermediate revisions by the same user not shown)
Line 12: Line 12:
local selectedPronouns = {}
local selectedPronouns = {}
local categories = {}
local categories = {}
local pronounSet = {} -- Table to keep track of unique selected pronouns


for i, arg in ipairs(args) do
for i, arg in ipairs(args) do
if pronouns[arg] then
if pronouns[arg] and not pronounSet[arg] then
table.insert(selectedPronouns, pronouns[arg])
table.insert(selectedPronouns, pronouns[arg])
table.insert(categories, "[[Category:Players who are a " .. pronouns[arg] .. "]]")
table.insert(categories, "[[Category:Players who go by " .. pronouns[arg] .. "]]")
pronounSet[arg] = true -- Mark the pronoun as selected in the set
end
end
end
end


if #selectedPronouns == 0 then
if #selectedPronouns == 0 then
elseif #selectedPronouns == 1 then
return "No valid pronouns specified."
local pronoun = selectedPronouns[1]
pronouns = {
he = "he/him",
she = "she/her",
they = "they/them"
}
local altPronouns = pronouns[pronoun]
table.insert(selectedPronouns, altPronouns:match("/(.*)")) -- Extracts the alternative forms from the pronouns table
end

if #selectedPronouns == 0 then
else
else
return table.concat(selectedPronouns, "/") .. table.concat(categories)
return table.concat(selectedPronouns, "/") .. table.concat(categories)

Latest revision as of 09:46, 29 July 2023

Documentation for this module may be created at Module:Pronouns/doc

local p = {}

function p.pronoun(frame)
    local args = frame.args

    local pronouns = {
        he = "he",
        she = "she",
        they = "they"
    }

    local selectedPronouns = {}
    local categories = {}
    local pronounSet = {}  -- Table to keep track of unique selected pronouns

    for i, arg in ipairs(args) do
        if pronouns[arg] and not pronounSet[arg] then
            table.insert(selectedPronouns, pronouns[arg])
            table.insert(categories, "[[Category:Players who go by " .. pronouns[arg] .. "]]")
            pronounSet[arg] = true  -- Mark the pronoun as selected in the set
        end
    end

    if #selectedPronouns == 0 then
    elseif #selectedPronouns == 1 then
        local pronoun = selectedPronouns[1]
        pronouns = {
            he = "he/him",
            she = "she/her",
            they = "they/them"
        }
        local altPronouns = pronouns[pronoun]
        table.insert(selectedPronouns, altPronouns:match("/(.*)")) -- Extracts the alternative forms from the pronouns table
    end

    if #selectedPronouns == 0 then
    else
        return table.concat(selectedPronouns, "/") .. table.concat(categories)
    end
end

return p