Module:State

Revision as of 20:28, 13 May 2024 by Katty von Keksburg (talk | contribs) (创建页面,内容为“local p = {}; states = require('Module:State/List'); local getArgs = require('Module:Arguments').getArgs function p.state_name(frame) local args = getArgs(frame) return p._state_name(args) end function p._state_name(args) id = tonumber(args[1]) if not states[id] then return "<span style=\"color: red;\">Module:State/List does not have state:</span>" else return states[id].name end end function p.state_names(frame)…”)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
This module depends on the following other modules:
Module:State/List
Module:Arguments

The list of states with their information for the module is in Module:State/List.

Implements

  1. 重定向 Template:Tlx and
  2. 重定向 Template:Tlx.





local p = {};

states = require('Module:State/List');

local getArgs = require('Module:Arguments').getArgs

function p.state_name(frame)
    local args = getArgs(frame)
    return p._state_name(args)
end
function p._state_name(args)
    id = tonumber(args[1])
    if not states[id] then
        return "<span style=\"color: red;\">[[Module:State/List]] does not have state:</span>"
    else
        return states[id].name
    end
end
function p.state_names(frame)
    local args = getArgs(frame)
    return p._state_names(args)
end
function p._state_names(args)
    output = {}
    for i, j in pairs(args) do
        if type(i) == "number" then
            if not states[tonumber(j)] then
                return "<span style=\"color: red;\">[[Module:State/List]] does not have state: " .. j .. "</span>"
            end
            s = states[tonumber(j)].name
            if not args.nob then
                s = string.format("'''%s'''", s)
            end
            if not args.noid then
                s = s .. string.format(" ''(%s)''", j)
            end
            output[i] = s
        end
    end
    if args.sep then
        sep = args.sep:gsub("\\n", "\n"):gsub("_", " ")
        s = table.concat(output, sep)
    elseif #output == 1 then
        s = output[1]
    elseif #output == 2 then
        s = output[1] .. " and " .. output[2]
    else
        s = table.concat(output, ", ", 1, #output-1) .. ", and " .. output[#output]
    end
    return s
end

return p