Module:State:修订间差异

无编辑摘要
标签已被回退
(撤销Katty von Keksburg讨论)的版本26001)
标签撤销
第1行: 第1行:
local p = {}
local p = {};


-- 导入州名数据模块
states = require('Module:State/List');
local states = require('Module:State/List')


-- 导入参数处理模块
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs


-- 根据ID获取州名(包括name2和name)
function p.state_name(frame)
   local args = getArgs(frame)
   return p._state_name(args)
end
function p._state_name(args)
function p._state_name(args)
    local id = tonumber(args[1])
    id = tonumber(args[1])
    if not states[id] then
    if not states[id] then
      return "<span style=\"color: red;\">[[Module:State/List]] does not have state:</span>"
      return "<span style=\"color: red;\">[[Module:State/List]] does not have state:</span>"
    else
    else
      local name2 = states[id].name2 or ""
      return states[id].name
     local name = states[id].name or ""
     -- 返回name2和name
     return name2 .. " (" .. name .. ")"
    end
    end
end
end
 
function p.state_names(frame)
-- 根据多个ID获取州名列表(包括name2和name)
   local args = getArgs(frame)
   return p._state_names(args)
end
function p._state_names(args)
function p._state_names(args)
    local output = {}
    output = {}
    for i, j in pairs(args) do
    for i, j in pairs(args) do
      if type(i) == "number" then
      if type(i) == "number" then
第28行: 第28行:
          return "<span style=\"color: red;\">[[Module:State/List]] does not have state: " .. j .. "</span>"
          return "<span style=\"color: red;\">[[Module:State/List]] does not have state: " .. j .. "</span>"
        end
        end
        -- 返回name2和name
        s = states[tonumber(j)].name
       local name2 = states[tonumber(j)].name2 or ""
       local name = states[tonumber(j)].name or ""
        if not args.nob then
        if not args.nob then
          name = string.format("'''%s'''", name)
          s = string.format("'''%s'''", s)
        end
        end
        if not args.noid then
        if not args.noid then
          name = name .. string.format(" ''(%s)''", j)
          s = s .. string.format(" ''(%s)''", j)
        end
        end
        output[i] = name2 .. " (" .. name .. ")"
        output[i] = s
      end
      end
    end
    end
   -- 根据参数中的分隔符进行分隔
    if args.sep then
    if args.sep then
      local sep = args.sep:gsub("\\n", "\n"):gsub("_", " ")
      sep = args.sep:gsub("\\n", "\n"):gsub("_", " ")
      return table.concat(output, sep)
      s = table.concat(output, sep)
    elseif #output == 1 then
    elseif #output == 1 then
      return output[1]
      s = output[1]
    elseif #output == 2 then
    elseif #output == 2 then
      return output[1] .. " and " .. output[2]
      s = output[1] .. " and " .. output[2]
    else
    else
      return table.concat(output, ", ", 1, #output-1) .. ", and " .. output[#output]
      s = table.concat(output, ", ", 1, #output-1) .. ", and " .. output[#output]
    end
    end
   return s
end
end


-- 导出模块
return p
return p

2024年5月13日 (一) 21:42的版本

可在Module:State/doc创建此模块的帮助文档

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