模組:Vgn
外观
require("strict")
local getArgs = require("Module:Arguments").getArgs
local list = require('Module:List').unbulleted
local conv = require('Module:WikitextLC').converted
local region_labels = {
hans = '简体中文版',
hant = '繁體中文版',
cn = '中国大陆',
hk = '香港',
mo = '澳門',
my = '马来西亚',
sg = '新加坡',
tw = '臺灣',
}
local function nocc(text)
return conv(text, { 'zh', 'zh-hans', 'zh-hant' })
end
local function build_regions_label(region_codes_str)
if region_codes_str == nil then
return nil
end
local region_names = {}
local region_codes = mw.text.split(region_codes_str, ',', false)
for _, code in ipairs(region_codes) do
table.insert(region_names, region_labels[code])
end
if #region_names == 0 then
return nil
end
return "<small>(" .. table.concat(region_names, '、') .. ")</small>"
end
local function build_item(text)
local _, _, code, name = mw.ustring.find(text, "^%s-(.+)%s-:%s-(.+)%s-$")
local label = build_regions_label(code)
if label == nil then
return nocc(text)
end
return nocc(name) .. label
end
local function main(args)
local list_items = {}
for _, v in ipairs(args) do
table.insert(list_items, build_item(v))
end
return list(list_items)
end
local p = {}
local function makeInvokeFunc(funcName)
return function(frame)
local args = getArgs(frame)
return p[funcName](args)
end
end
p.main = makeInvokeFunc("_main")
function p._main(args)
return main(args)
end
return p