Module:LC zh

-- @var table local p = {}

-- @param langCode -- @param mode -- @param namespace -- @return string function p.getNamespaceName( langCode, mode, namespace ) local namespaceNames = { -- Prevent fallback ["zh"] = { -- 0 (Main) [""] = "",			-- 1			["Talk"] = "Talk", -- 2			["User"] = "User", -- 3			["User talk"] = "User talk", -- 4			["Project"] = "Project", -- 5			["Project talk"] = "Project talk", -- 6			["File"] = "File", -- 7			["File talk"] = "File talk", -- 8			["MediaWiki"] = "MediaWiki", -- 9			["MediaWiki talk"] = "MediaWiki talk", -- 10			["Template"] = "Template", -- 11			["Template talk"] = "Template talk", -- 12			["Help"] = "Help", -- 13			["Help talk"] = "Help talk", -- 14			["Category"] = "Category", -- 15			["Category talk"] = "Category talk", -- 90			["Thread"] = "Thread", -- 91			["Thread talk"] = "Thread talk", -- 92			["Summary"] = "Summary", -- 93			["Summary talk"] = "Summary talk", -- 100			["Manual"] = "Manual", -- 101			["Manual talk"] = "Manual talk", -- 102			["Extension"] = "Extension", -- 103			["Extension talk"] = "Extension talk", -- 104			["API"] = "API", -- 105			["API talk"] = "API talk", -- 106			["Skin"] = "Skin", -- 107			["Skin talk"] = "Skin talk", -- 486			["Data"] = "Data", -- 487			["Data talk"] = "Data talk", -- 828			["Module"] = "Module", -- 829			["Module talk"] = "Module talk", -- 1198			["Translations"] = "Translations", -- 1199			["Translations talk"] = "Translations talk", -- 2300			["Gadget"] = "Gadget", -- 2301			["Gadget talk"] = "Gadget talk", -- 2302			["Gadget definition"] = "Gadget definition", -- 2303			["Gadget definition talk"] = "Gadget definition talk", -- 2600			["Topic"] = "Topic", -- 5500			["Newsletter"] = "Newsletter", -- 5501			["Newsletter talk"] = "Newsletter talk", },		["zh-hans"] = { ["Talk"] = "讨论", ["User"] = "用户", ["User talk"] = "用户讨论", ["Project"] = "项目", ["Project talk"] = "项目讨论", ["File"] = "文件", ["File talk"] = "文件讨论", ["MediaWiki talk"] = "MediaWiki讨论", ["Template"] = "模板", ["Template talk"] = "模板讨论", ["Help"] = "帮助", ["Help talk"] = "帮助讨论", ["Category"] = "分类", ["Category talk"] = "分类讨论", ["Thread"] = "帖子", ["Thread talk"] = "帖子讨论", ["Summary"] = "摘要", ["Summary talk"] = "摘要讨论", ["Manual"] = "手册", ["Manual talk"] = "手册讨论", ["Extension"] = "扩展", ["Extension talk"] = "扩展讨论", ["API talk"] = "API讨论", ["Skin"] = "皮肤", ["Skin talk"] = "皮肤讨论", ["Data"] = "数据", ["Data talk"] = "数据讨论", ["Module"] = "模块", ["Module talk"] = "模块讨论", ["Translations"] = "翻译", ["Translations talk"] = "翻译讨论", ["Gadget"] = "小工具", ["Gadget talk"] = "小工具讨论", ["Gadget definition"] = "小工具定义", ["Gadget definition talk"] = "小工具定义讨论", ["Topic"] = "话题", ["Newsletter"] = "电子报", ["Newsletter talk"] = "电子报讨论", },		["zh-hant"] = { ["Talk"] = "討論", ["User"] = "使用者", ["User talk"] = "使用者討論", ["Project"] = "專案", ["Project talk"] = "專案討論", ["File"] = "檔案", ["File talk"] = "檔案討論", ["MediaWiki talk"] = "MediaWiki討論", ["Template"] = "模板", ["Template talk"] = "模板討論", ["Help"] = "說明", ["Help talk"] = "說明討論", ["Category"] = "分類", ["Category talk"] = "分類討論", ["Thread"] = "討論串", ["Thread talk"] = "討論串討論", ["Summary"] = "摘要", ["Summary talk"] = "摘要討論", ["Manual"] = "手冊", ["Manual talk"] = "手冊討論", ["Extension"] = "擴充功能", ["Extension talk"] = "擴充功能討論", ["API talk"] = "API討論", ["Skin"] = "外觀", ["Skin talk"] = "外觀討論", ["Data"] = "資料", ["Data talk"] = "資料討論", ["Module"] = "模組", ["Module talk"] = "模組討論", ["Translations"] = "翻譯", ["Translations talk"] = "翻譯討論", ["Gadget"] = "小工具", ["Gadget talk"] = "小工具討論", ["Gadget definition"] = "小工具定義", ["Gadget definition talk"] = "小工具定義討論", ["Topic"] = "話題", ["Newsletter"] = "電子報", ["Newsletter talk"] = "電子報討論", },		["zh-hk"] = { ["User"] = "用戶", ["User talk"] = "用戶討論", },	}

if mode == "LC" then local t = {} local variants = p.getVariants for _, variant in ipairs(variants) do			if namespaceNames[variant] and namespaceNames[variant][namespace] ~= nil then t[#t+1] = variant .. ":" ..					namespaceNames[variant][namespace] .. ";"			end end if t[2] ~= nil then return "-{" .. table.concat( t ) .. "}-"		end return t[1] or namespace end

if mode == "LL" then if namespaceNames[langCode] and namespaceNames[langCode][namespace] ~= nil then return namespaceNames[langCode][namespace] end local variantFallbacks = p.getVariantFallbacks[langCode] for _, variant in ipairs(variantFallbacks) do			if namespaceNames[variant] and namespaceNames[variant][namespace] ~= nil then return namespaceNames[variant][namespace] end end end

return namespace end

-- @param langCode -- @param mode -- @param args -- @return string function p.getWikitext( langCode, mode, args ) local t = {} if mode == "LC" then local variants = p.getVariants for _, variant in ipairs(variants) do			if args[variant] ~= nil then t[#t+1] = variant .. ":" .. args[variant] .. ";"			end end if t[2] ~= nil then return "-{" .. table.concat( t ) .. "}-"		end return t[1] or "" end

if mode == "LL" then if args[langCode] ~= nil then return args[langCode] end local variantFallbacks = p.getVariantFallbacks[langCode] for _, variant in ipairs(variantFallbacks) do			if args[variant] ~= nil then return args[variant] end end end

return "" end

function p.getVariants return { "zh", "zh-hans", "zh-hant", "zh-cn", "zh-tw", "zh-hk", "zh-mo", "zh-sg", "zh-my", } end

function p.hasVariant( langCode ) local variants = p.getVariants for _, variant in ipairs(variants) do       if langCode == variant then return true end end

return false end

-- LanguageConverter -- * ZhConverter -- -- @return table function p.getVariantFallbacks return { ["zh"] = { "zh-hans", "zh-hant", "zh-cn", "zh-tw", "zh-hk", "zh-mo", "zh-sg", "zh-my", },		["zh-hans"] = { "zh-cn", "zh-sg", "zh-my", "zh" }, ["zh-hant"] = { "zh-tw", "zh-hk", "zh-mo", "zh" }, ["zh-cn"] = { "zh-hans", "zh-my", "zh-sg", "zh" }, ["zh-sg"] = { "zh-my", "zh-hans", "zh-cn", "zh" }, ["zh-my"] = { "zh-sg", "zh-hans", "zh-cn", "zh" }, ["zh-tw"] = { "zh-hant", "zh-hk", "zh-mo", "zh" }, ["zh-hk"] = { "zh-mo", "zh-hant", "zh-tw", "zh" }, ["zh-mo"] = { "zh-hk", "zh-hant", "zh-tw", "zh" }, } end

--- -- Source modes: -- * T: full page title name -- * C: wikitext content -- -- @param table args -- @return string function p._main( args ) -- @var frame local frame = mw.getCurrentFrame -- @var table local variants = p.getVariants -- @var string local sourceMode = args[1] -- @var string local pageLangCode = frame:preprocess{ "" } -- @var string local userLangCode = frame:callParserFunction{ name = "int", args = { "lang" } }	-- @var string local namespace = args[2] -- @var int|bool|string -- Whether used in Template:Localized link and hide nsp local isLLnNsp = args.nsp == 0 or args.nsp == "0" -- @var int|bool|string Used as bool local hideNamespace = args.hide_ns

if pageLangCode == "zh" then if sourceMode == "T" then if isLLnNsp then if p.hasVariant( userLangCode ) then return p.getWikitext( userLangCode, "LL", args ) end return p.getWikitext( pageLangCode, "LL", args ) elseif hideNamespace then return p.getWikitext( pageLangCode, "LC", args ) end return p.getNamespaceName( pageLangCode, "LC", namespace ) .. ":" ..				p.getWikitext( pageLangCode, "LC", args ) elseif sourceMode == "C" then return p.getWikitext( pageLangCode, "LC", args ) end end

if not p.hasVariant( userLangCode ) then userLangCode = "zh" end

if sourceMode == "T" then if isLLnNsp or hideNamespace then return p.getWikitext( userLangCode, "LL", args ) end return p.getNamespaceName( userLangCode, "LL", namespace ) .. ":" ..			p.getWikitext( userLangCode, "LL", args ) elseif sourceMode == "C" then return p.getWikitext( userLangCode, "LL", args ) end

return "" end

-- @param frame frame -- @return string function p.main( frame ) local getArgs local args if not getArgs then getArgs = require( Module:Arguments ).getArgs end args = getArgs( frame, { parentFirst = true } ) if args["zh-hans"] == nil then return "error" end return p._main( args ) end

return p