模組:NS1
外观
local p = {}
function p.main(frame)
local getArgs = require('Module:Arguments').getArgs
local args = getArgs(frame)
local lang = args[1] or frame:callParserFunction{ name = 'int', args = {'Conversionname'} }
local nsInput = args[2] or mw.title.getCurrentTitle().namespace
return p._main(lang, nsInput)
end
function p._main(lang, nsInput)
-- 1. 使用系統 API 驗證命名空間是否存在(支援 ID 或名稱輸入)
local nsKey = tonumber(nsInput) or nsInput
local nsInfo = mw.site.namespaces[nsKey]
if not nsInfo then
error('輸入命名空間錯誤')
end
local nsData = mw.loadData('Module:NS1/data')
local row = nsData[nsInfo.id]
if row then
--調用Lan模組的fallbackList
local fallbackList = require('Module:Lan').fallbackList
local fallback = fallbackList[lang]
if not fallback then
error('輸入語言錯誤')
end
for _,langName in ipairs(fallback) do
langName = langName:match('zh%-(%w+)') or langName
if row[langName] then
return row[langName]
end
end
end
return nsInfo.name
end
return p