模块:SpecialConversion
来自The Land of StarLight
此模块的文档可以在模块:SpecialConversion/doc创建
local p = {}
--X zh-cn
--Y zh-tw
--Z zh-hk
local all = mw.loadData('Module:SpecialConversion/All')
local snap = mw.loadData('Module:SpecialConversion/Snapshot')
function p.all(type)
if type == 'advdesc' then
type = 'advancements'
end
if type ~= 'all' then
return p.insertAll(type)
else
return p.insertAll('advancements', 'stats', 'subtitles')
end
end
function p.insertAll(...)
local t = {}
for k in pairs(all) do
for _, name in ipairs {...} do
if k:find('^' .. name .. '.') then
table.insert(t, '-{H|zh-cn:' .. all[k][1] .. ';zh-tw:' .. all[k][2] ..';zh-hk:'..all[k][3].. '}-')
end
end
end
table.sort(t)
return table.concat(t)
end
function p.one(t, key, mode, argX, argY, argZ)
local resultX = ''--X zh-cn
local resultY = ''--Y zh-tw
local resultZ = ''--Z zh-hk
mode = mode ~= '' and mode .. '|' or mode
if t[key] then
resultX = t[key][1] --zh-cn
resultY = t[key][2] --zh-tw
resultZ = t[key][3] --zh-hk
else
return nil
end
argX = padArg(argX, resultX)
argY = padArg(argY, resultY)
argZ = padArg(argZ, resultZ)
if resultX ~= '' and resultY ~= '' and resultZ ~= '' then
return table.concat {
'-{',
mode,
'zh-cn:',
resultX:format(unpack(argX)),
';zh-tw:',
resultY:format(unpack(argY)),
';zh-hk:',
resultZ:format(unpack(argZ)),
'}-'
}
end
if resultX ~= '' and resultY == '' then
return resultX:format(unpack(argX)) .. '[[Category:缺少zh-tw翻译]]'
elseif resultX ~= '' and resultZ == '' then
return resultX:format(unpack(argX)) .. '[[Category:缺少zh-hk翻译]]'
else return ''
end
end
function padArg(arg, pattern)
local t = arg or {}
local i = 1
for _ in pattern:gmatch('%%s') do
t[i] = t[i] or '%s'
i = i + 1
end
return t
end
function getPrefixedArgs(args, prefix)
local t = {}
local n
for k, v in pairs(args) do
if type(k) == 'string' and k:match('^' .. prefix .. '%d+$') then
n = tonumber(k:match('^' .. prefix .. '(%d+)$'))
t[n] = v
end
end
return #t ~= 0 and t or nil
end
function p.convert(f)
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
end
local type = args.type -- advancements (advdesc), stat, subtitles
local mode = args.mode or '' -- H
local argX = getPrefixedArgs(args, 's')
local argY = getPrefixedArgs(args, 't') or argX
local argZ = getPrefixedArgs(args, 'h') or argY
local key = mw.text.trim(args[1])
local cat = ''
if args[1] == 'all' then
return p.all(type)
else
local conv = p.one(all, key, mode, argX, argY, argZ)
local convsnap = p.one(snap, key, mode, argX, argY, argZ)
local convresult = convsnap or conv
if conv ~= convsnap and (convsnap ~= '' and convsnap ~= nil)then
cat = '[[Category:快照转换内容]]'
end
if convresult ~= '' and convresult ~= nil then
return convresult..cat
else
cat = '[[Category:未知的本地化键名]]'
return "'''" .. key .. "'''" .. cat
end
end
end
function p.list(f)
local args = f
if f == mw.getCurrentFrame() then
args = f:getParent().args
end
local p1=args[1]
local p2=args[2]
local p3=args[3]
local title=args['title'] or '类别'
local body ={'{| class="wikitable"\n|-\n!本地化键名 !! 游戏内字符串 '}
local find = false
local look =''
if (p1 or p2 or p3 or false) == false then
return "'''空参数'''[[Category:未知的本地化键名]]"
end
if p1 then
look = look ..p1..'%.'
end
if p2 then
look = look ..p2..'%.'
end
if p3 then
look = look ..p3..'%.'
end
for k in pairs(all) do
if string.find(k,look) == 1 then
find = find or true
table.insert(
body,
table.concat(
{
'|-\n',
'| ',
'<code>'..k..'</code>',
'|| ',
table.concat(
{
'-{zh-cn:',
all[k][1],
';zh-tw:',
all[k][2],
';zh-hk:',
all[k][3],
'}-'
}
)
}
)
)
end
end
table.insert(
body,
'|}'
)
if find then
table.sort(body)
return table.concat(body, '\n')
else
return "'''未知的本地化键名前缀[[Category:未知的本地化键名]]'''"
end
end
return p