Module:LC zh

-- @var table local p = {}

-- @return table Merged argument table function p.getMergedArgs local args = {} local f = mw.getCurrentFrame -- 	local origArgs = f.args -- 	local parentArgs = f:getParent.args

for k, v in pairs( origArgs ) do		v = mw.text.trim( tostring( v ) ) args[k] = v	end

for k, v in pairs( parentArgs ) do		v = mw.text.trim( v ) args[k] = v	end

return args end

-- @param langCode MediaWiki internal language code -- @param mode --  - LC: Convertable (language converter syntax) --  - LL: Unconvertable (was referring to Template:Localized_link which was --     unconvertable) -- @param namespace en canonical namespace name, use whitespace instead of --  underscore -- @return string Localized namespace name 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 tv = {} local variants = p.getVariants for _, variant in ipairs(variants) do			if namespaceNames[variant] and namespaceNames[variant][namespace] ~= nil and namespaceNames[variant][namespace] ~= "" then tv[#tv+1] = { variant, namespaceNames[variant][namespace] } end end if tv[2] ~= nil then for _, nskv in pairs(tv) do t[#t+1] = nskv[1] .. ":" .. nskv[2] .. ";"			end return "-{" .. table.concat( t ) .. "}-"		end return (tv[1] and tv[1][2]) 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 string langCode MediaWiki internal language code -- @param string sourceMode --  - C: Content wikitext --  - T: Full display title text -- @param string convMode --  - LC: Convertable (language converter syntax) --  - LL: Unconvertable (was referring to Template:Localized_link which was --     unconvertable) -- @param table args Merged argument table -- @return string Wikitext function p.getWikitext( langCode, sourceMode, convMode, args ) local t = {} if convMode == "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 if sourceMode == "T" then return t[1] or args[4] or "" end if sourceMode == "C" then return t[1] or args[2] or "" end return t[1] or "" end

if convMode == "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

-- @return table Array of language variants in MediaWiki internal language codes function p.getVariants return { "zh", "zh-hans", "zh-hant", "zh-cn", "zh-tw", "zh-hk", "zh-mo", "zh-sg", "zh-my", } end

-- @param string MediaWiki internal language code -- @return bool Whether is one of zh language variant 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 int|bool|string -- Whether used in non-lannguage-conversion-supported area and hide nsp local isLLnNsp = args.nons == 0 or args.nons == "0" -- @var int|bool|string Used as bool local hideNamespace = args.hide_ns or args[2] == 0 or args[2] == "0" or args.nsp == 0 or args.nsp == "0" -- @var string local namespace = args[3]

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

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

if sourceMode == "T" then if isLLnNsp then return p.getWikitext( userLangCode, sourceMode, "LL", args ) elseif hideNamespace then return p.getWikitext( pageLangCode, sourceMode, "LC", args ) -- return p.getWikitext( userLangCode, sourceMode, "LL", args ) end if p.getNamespaceName( pageLangCode, "LC", namespace ) ~= nil and p.getNamespaceName( pageLangCode, "LC", namespace ) ~= "" then return p.getNamespaceName( pageLangCode, "LC", namespace ) .. ":" ..				p.getWikitext( pageLangCode, sourceMode, "LC", args ) end return p.getWikitext( pageLangCode, sourceMode, "LC", args ) elseif sourceMode == "C" then return p.getWikitext( pageLangCode, sourceMode, "LC", 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 = p.getMergedArgs return p._main( args ) end

return p