模組:Vgr

被永久保护的模块
维基百科,自由的百科全书
文档图示 模块文档[查看] [编辑] [历史] [清除缓存]

用于{{Vgrelease}}。

local labels = {
    -- South Korea and Japan
    { 'KR', '-{zh-cn:韩国; zh-sg:南韩; zh-tw:南韓;}-' },
    { 'JP', '日本' },

    -- Western
    { 'WW', '全球' },
    { 'NA', '北美' },
    { 'PAL', '[[PAL区|PAL]]' },
    { 'EU', '欧洲' },
    { 'UK', '英国' },
    { 'AU', '澳-{}-洲' },
    { 'AUS', '澳-{}-洲' },
    { 'CIS', '[[独立国家联合体|<abbr title=\"独立国家联合体\">独联体</abbr>]]' },

    -- Chinese-speaking world
    { 'CN', '中国大陆' },
    { 'TWHK', '臺港' },
    { 'TWHKMO', '臺港澳' },
    { 'TW', '臺灣' },
    { 'HK', '香港' },
    { 'MO', '澳門' },

    -- Southeast Asia
    { 'SEA', '东南亚' },
    { 'SG', '新加坡' },
    { 'MY', '[[马来西亚|大馬]]' },

    -- Asia
    { 'AS', '亚洲' },

    -- Others
    { '?', '未知' },
}

require('Module:No globals')
local getArgs = require('Module:Arguments').getArgs
local list = require('Module:List').unbulleted
local yesno = require('Module:Yesno')
local lc = require('Module:WikitextLC').converted
local cd = require('Module:Chinese date')._main

local p = {}

local function getLabelName(input)
    if input == nil then
        return ''
    end

    for _, value in ipairs(labels) do
        if input == value[1] then
            return value[2] .. ':'
        end
    end

    return input .. ':'
end

local function itemBuilder(args, para1, para2)

    para1 = getLabelName(para1)

    if para2 == nil then
        para2 = ''
    elseif yesno(args.nocc) then
        para2 = lc(para2, { 'zh-hans', 'zh-hant' })
    else
        para2 = cd { para2, ['error'] = 'ignore', ['suf'] = 'yes' }
    end

    return (para1 .. para2 == '' and nil or para1 .. para2)

end

function p.main(frame)
    local args = getArgs(frame)
    return p._main(args)
end

function p._main(args)
    -- Main module code goes here.
    local tab = {}
    local maxIndex = 99 -- [[WP:VG/GL|专题指引]]不鼓励在信息框列出过多地区的发售信息,故将此数限制在20以内,即最多列出10个地区
    
    -- 只有一個參數時,該參數為內容,不帶地區標籤
    if args[1] and not args[2] then
        local oneParameter = true

        -- 防止只是漏輸入參數2
        for i = 3, maxIndex do
            if args[i] then
                oneParameter = false
                break
            end
        end

        if oneParameter then
            table.insert(tab, itemBuilder(args, nil, args[1]))
            return list(tab)
        end
    end

    -- 有複數參數時,生成「區域:內容」對
    for i = 1, maxIndex, 2 do
        table.insert(tab, itemBuilder(args, args[i], args[i + 1]))
    end

    return list(tab)
end

return p