无编辑摘要 标签:已被回退 |
无编辑摘要 |
||
(未显示同一用户的1个中间版本) | |||
第1行: | 第1行: | ||
local p = {} | local p = {}; | ||
states = require('Module:State/List'); | |||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
function p.state_name(frame) | |||
local args = getArgs(frame) | |||
return p._state_name(args) | |||
end | |||
function p.state_name2(frame) | |||
local args = getArgs(frame) | |||
return p._state_name2(args) | |||
end | |||
function p._state_name(args) | 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_name2(args) | |||
local id = tonumber(args[1]) | local 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 | ||
return states[id].name2 | |||
end | end | ||
end | end | ||
function p.state_names(frame) | |||
local args = getArgs(frame) | |||
return p._state_names(args) | |||
end | |||
function p.state_names2(frame) | |||
local args = getArgs(frame) | |||
return p._state_names2(args) | |||
end | |||
function p._state_names(args) | function p._state_names(args) | ||
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 | ||
if not states[tonumber(j)] then | if not states[tonumber(j)] then | ||
return "<span style=\"color: red;\">[[Module:State/List]] | return "<span style=\"color: red;\">[[Module:State/List]] 没有中文名:" .. j .. "</span>" | ||
end | |||
s = states[tonumber(j)].name | |||
if not states[tonumber(j)] then | |||
return "<span style=\"color: red;\">[[Module:State/List]]没有英文名: " .. j .. "</span>" | |||
end | end | ||
s = states[tonumber(j)].name2 | |||
if not args.nob then | if not args.nob then | ||
s = string.format("'''%s'''", s) | |||
end | end | ||
if not args.noid then | if not args.noid then | ||
s = s .. string.format(" ''(%s)''", j) | |||
end | end | ||
output[i] = | output[i] = s | ||
end | end | ||
end | end | ||
if args.sep then | if args.sep then | ||
sep = args.sep:gsub("\\n", "\n"):gsub("_", " ") | |||
s = table.concat(output, sep) | |||
elseif #output == 1 then | elseif #output == 1 then | ||
s = output[1] | |||
elseif #output == 2 then | elseif #output == 2 then | ||
s = output[1] .. " and " .. output[2] | |||
else | else | ||
s = table.concat(output, ", ", 1, #output-1) .. ", and " .. output[#output] | |||
end | end | ||
return s | |||
end | end | ||
return p | return p |
2024年5月13日 (一) 21:52的最新版本
可在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_name2(frame) local args = getArgs(frame) return p._state_name2(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_name2(args) local 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].name2 end end function p.state_names(frame) local args = getArgs(frame) return p._state_names(args) end function p.state_names2(frame) local args = getArgs(frame) return p._state_names2(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]] 没有中文名:" .. j .. "</span>" end s = states[tonumber(j)].name if not states[tonumber(j)] then return "<span style=\"color: red;\">[[Module:State/List]]没有英文名: " .. j .. "</span>" end s = states[tonumber(j)].name2 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