缺氧 wiki 编辑团队提示:注册账号并登录后体验更佳,且可通过参数设置定制优化您的浏览体验!

该站点为镜像站点,如果你想帮助这个由玩家志愿编辑的 wiki 站点,请前往原站点参与编辑,
同时欢迎加入编辑讨论群 851803695 与其他编辑者一起参与建设!

全站通知:

模块:Po

来自缺氧WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

此模块的文档可以在模块:Po/doc创建

-- Module:Po
local p = {}
local fstr = mw.ustring.format -- shortcut for formattig a string
local getArgs = require('Module:Dev/Arguments').getArgs
local i18n = require([[Module:I18n]])

function p.po(args)
    local key = args
    if type(args) == 'table' then key = args[1]:upper() end
    local subModule = mw.text.split(key, '.', true)[2]
    local msgModule = 'Module:i18n/' ..
                          subModule:lower():gsub("^%l", string.upper)
                              :gsub("_", "")
    local __ = i18n.loadMessages(msgModule)
    local msg = __:msg(key)
    if type(args) == 'table' and args.format ~= nil then
        for k, v in pairs(args) do
            if type(k) == "string" and k ~= 'format' then
            	if (k:sub(1,1) == '$') then k = k:sub(2) end
                msg = mw.ustring.gsub(msg, fstr("{%s}", k), v)
            end
        end
    end
    return msg
end

-- test by: = p.po("STRINGS.DUPLICANTS.TRAITS.CANTRESEARCH.NAME")
-- test by: = p.po({"STRINGS.DUPLICANTS.trAITS.CANTRESEARCH.NAME"})
-- test by: = p.po({"STRINGS.UI.BUILDCATEGORIES.EQUIPMENT.TOOLTIP"})
-- test by: = p.po({"STRINGS.UI.BUILDCATEGORIES.EQUIPMENT.TOOLTIP", format=1, Hotkey='[E]'})
-- test by: = p.po({"STRINGS.COLONY_ACHIEVEMENTS.MISC_REQUIREMENTS.BUILD_NATURE_RESERVES_DESCRIPTION", format=1, ['$0']='000', ['$1']='111'})
function p.main(frame) return p.po(getArgs(frame)) end

return p