模組:Vgname/testcases
外观
![]() | 這是Module:Vgname的測試樣例頁,測試結果請見討論頁。 |
local languageList = mw.loadData('Module:Vgname/languages')
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local wikitextLC = require('Module:WikitextLC')
local function refSeparator( a )
a = a or ''
local refPattern = '\127UNIQ%x+%-ref%-%x+%-QINU\127'
local p, _ = string.find( a, refPattern )
local contentPart, refPart
if p then
contentPart, refPart = string.sub( a, 1, p - 1 ), string.sub( a, p )
else
contentPart, refPart = a, ''
end
return contentPart, refPart
end
local function bold( a )
local cont, ref = refSeparator( a )
if yesno( _bold ) then
cont = '<b>' .. cont .. '</b>' .. ref
end
return cont
end
local function italic( a )
local cont, ref = refSeparator( a )
if yesno( _italic ) then
cont = '<i>' .. cont ..'</i>' .. ref
end
return cont
end
local function isDiff( args )
if yesno( _diff ) or args.na or args.eu then
return true
end
end
local function lang( langcode, a )
local span = mw.html.create( 'span' )
local content, ref = refSeparator( a )
span
:attr( 'lang', langcode )
:wikitext( '-{' .. content .. '}-' )
return tostring( span ) .. ref
end
local function regionName( region , args)
local varient = {
{ 'cn', '中国大陆', args.cn },
{ 'hk', '香港', args.hk },
{ 'tw', '台湾', args.hk },
{ 'cn-hk', '中国大陆和香港', args.cn },
{ 'cn-tw', '中国大陆和台湾', args.cn },
{ 'hk-tw', '香港和台湾', args.tw },
}
local ret = ''
for i, v in ipairs( varient ) do
if region == v[1] then
if v[3] == 'en' then
ret = v[2] .. '常用英文'
else
ret = '-{zh; zh-hans; zh-hant;|' .. bold( v[3] ) .. '}-'
ret = v[2] .. '译作「' .. ret .. '」'
end
break
end
end
return ret
end
local varList = {
['hk-tw'] = {
['zh'] = { 'cn', 'hk-tw' },
['zh-hans'] = { 'tw', 'cn-hk' },
['zh-hant'] = { 'tw', 'cn-hk' },
['zh-cn'] = { 'hk-tw' },
['zh-hk'] = { 'cn' },
['zh-mo'] = { 'cn' },
['zh-sg'] = { 'cn', 'hk-tw' },
['zh-tw'] = { 'cn' }
},
['cn-hk'] = {
['zh'] = { 'cn-hk', 'tw' },
['zh-hans'] = { 'cn-hk', 'tw' },
['zh-hant'] = { 'cn-hk', 'tw' },
['zh-cn'] = { 'tw' },
['zh-hk'] = { 'cn-hk' },
['zh-mo'] = { 'tw' },
['zh-sg'] = { 'cn-hk', 'tw' },
['zh-tw'] = { 'cn-hk' },
},
['cn-tw'] = {
['zh'] = { 'cn-tw', 'hk' },
['zh-hans'] = { 'cn-tw', 'hk' },
['zh-hant'] = { 'cn-tw', 'hk' },
['zh-cn'] = { 'hk' },
['zh-hk'] = { 'cn-tw' },
['zh-mo'] = { 'cn-tw' },
['zh-sg'] = { 'cn-tw', 'hk' },
['zh-tw'] = { 'hk' }
},
['default'] = {
['zh'] = { 'cn', 'hk', 'tw' },
['zh-hans'] = { 'cn', 'hk', 'tw' },
['zh-hant'] = { 'cn', 'hk', 'tw' },
['zh-cn'] = { 'hk', 'tw' },
['zh-hk'] = { 'cn', 'tw' },
['zh-mo'] = { 'cn', 'tw' },
['zh-sg'] = { 'cn', 'hk', 'tw' },
['zh-tw'] = { 'cn', 'hk' },
}
}
--------------------------------------------------------------------------
local function intro( args )
local ret = args[1]
ret = bold( ret )
if yesno( _bracket ) then
ret = '《' .. ret .. '》'
end
return ret
end
local function original( args )
local ret = ''
for i, v in ipairs( languageList ) do
if args[v[1]] then
if isDiff( args ) then
ret = v[3] .. ':' .. lang( v[1], args[v[1]] )
else
ret = v[2] .. ':' .. lang( v[1], args[v[1]] )
end
break
end
end
return ret
end
local function english( args )
local ret
if args.na then
ret = '美版名:' .. italic( lang( 'en', args.na ) )
end
if args.eu then
ret = ret and ( ret .. ',' ) or ''
ret = ret .. '欧版名:' .. italic( lang( 'en', args.eu ) )
end
if args.en and ret == nil then
ret = isDiff( args ) and '英文版名' or '英文名'
ret = ret .. ':' .. italic( lang( 'en', args.en ) )
end
return ret or ''
end
local function chinese( args )
local ret, temp
if args.hk == 'tw' then
temp = 'hk-tw'
elseif args.hk == 'cn' then
temp = 'cn-hk'
elseif args.tw == 'cn' then
temp = 'cn-tw'
else
temp = 'default'
end
ret = '-{'
for i, v in pairs( varList[temp] ) do
ret = ret .. i .. ':'
for j, w in ipairs( v ) do
ret = ret .. regionName( w, args ) .. ','
end
ret = string.sub( ret, 1, -4 ) .. '; '
end
ret = ret .. '}-'
return ret
end
--------------------------------------------------------------------------
local p = {}
function p.main(frame)
local args = getArgs(frame)
_bold = args.bold or 'yes'
_italic = args.italic or 'yes'
_bracket = args.italic or 'yes'
args.hk = args.hk or 'tw'
if string.lower( args.cn ) == 'tw' then
args.cn = args.tw
args.tw = 'cn'
end
return p._main(args)
end
function p._main(args)
-- return intro( args ) .. original( args ) .. english( args )
return chinese( args )
end
return p