Module:Lang-zh
require('strict')
 
 local p = {}
 
 -- articles in which traditional Chinese preceeds simplified Chinese
 local t1st = {
 	[&quot;228 Incident&quot;] = true,
 	[&quot;Chinese calendar&quot;] = true,
 	[&quot;Lippo Centre, Hong Kong&quot;] = true,
 	[&quot;Republic of China&quot;] = true,
 	[&quot;Republic of China at the 1924 Summer Olympics&quot;] = true,
 	[&quot;Taiwan&quot;] = true,
 	[&quot;Taiwan (island)&quot;] = true,
 	[&quot;Taiwan Province&quot;] = true,
 	[&quot;Wei Boyang&quot;] = true,
 }
 
 -- the labels for each part 
 local labels = {
 	[&quot;c&quot;] = &quot;சீன மொழி&quot;,
 	[&quot;s&quot;] = &quot;simplified Chinese&quot;,
 	[&quot;t&quot;] = &quot;traditional Chinese&quot;,
 	[&quot;p&quot;] = &quot;பின்யின்&quot;,
 	[&quot;tp&quot;] = &quot;Tongyong Pinyin&quot;,
 	[&quot;w&quot;] = &quot;Wade–Giles&quot;,
 	[&quot;j&quot;] = &quot;Jyutping&quot;,
 	[&quot;cy&quot;] = &quot;Cantonese Yale&quot;,
 	[&quot;sl&quot;] = &quot;Sidney Lau&quot;,
 	[&quot;poj&quot;] = &quot;Pe̍h-ōe-jī&quot;,
 	[&quot;zhu&quot;] = &quot;Zhuyin Fuhao&quot;,
 	[&quot;l&quot;] = &quot;lit.&quot;,
 	[&quot;tr&quot;] = &quot;trans.&quot;,
 }
 
 -- article titles for wikilinks for each part
 local wlinks = {
 	[&quot;c&quot;] = &quot;சீன மொழி&quot;,
 	[&quot;s&quot;] = &quot;சீன எழுத்துக்கள்&quot;,
 	[&quot;t&quot;] = &quot;சீன எழுத்துக்கள்&quot;,
 	[&quot;p&quot;] = &quot;பின்யின்&quot;,
 	[&quot;tp&quot;] = &quot;Tongyong Pinyin&quot;,
 	[&quot;w&quot;] = &quot;Wade–Giles&quot;,
 	[&quot;j&quot;] = &quot;Jyutping&quot;,
 	[&quot;cy&quot;] = &quot;Yale romanization of Cantonese&quot;,
 	[&quot;sl&quot;] = &quot;Sidney Lau romanisation&quot;,
 	[&quot;poj&quot;] = &quot;Pe̍h-ōe-jī&quot;,
 	[&quot;zhu&quot;] = &quot;Bopomofo&quot;,
 	[&quot;l&quot;] = &quot;Literal translation&quot;,
 	[&quot;tr&quot;] = &quot;Translation&quot;,
 }
 
 -- for those parts which are to be treated as languages their ISO code
 local ISOlang = {
 	[&quot;c&quot;] = &quot;zh&quot;,
 	[&quot;t&quot;] = &quot;zh-Hant&quot;,
 	[&quot;s&quot;] = &quot;zh-Hans&quot;,
 	[&quot;p&quot;] = &quot;zh-Latn-pinyin&quot;,
 	[&quot;tp&quot;] = &quot;zh-Latn&quot;,
 	[&quot;w&quot;] = &quot;zh-Latn-wadegile&quot;,
 	[&quot;j&quot;] = &quot;yue-Latn-jyutping&quot;,
 	[&quot;cy&quot;] = &quot;yue-Latn&quot;,
 	[&quot;sl&quot;] = &quot;yue-Latn&quot;,
 	[&quot;poj&quot;] = &quot;nan-Latn&quot;,
 	[&quot;zhu&quot;] = &quot;zh-Bopo&quot;,
 }
 
 local italic = {
 	[&quot;p&quot;] = true,
 	[&quot;tp&quot;] = true,
 	[&quot;w&quot;] = true,
 	[&quot;j&quot;] = true,
 	[&quot;cy&quot;] = true,
 	[&quot;sl&quot;] = true,
 	[&quot;poj&quot;] = true,
 }
 
 local superscript = {
 	[&quot;w&quot;] = true,
 	[&quot;sl&quot;] = true,
 }
 -- Categories for different kinds of Chinese text
 local cats = {
 	[&quot;c&quot;] = &quot;[[பகுப்பு:சீன மொழி வார்த்தைகளைக் கொண்ட கட்டுரைகள்]]&quot;,
 	[&quot;s&quot;] = &quot;[[பகுப்பு:சீன மொழி வார்த்தைகளைக் கொண்ட கட்டுரைகள்]]&quot;,
 	[&quot;t&quot;] = &quot;[[பகுப்பு:சீன மொழி வார்த்தைகளைக் கொண்ட கட்டுரைகள்]]&quot;,
 }
 
 function p.Zh(frame)
 	-- load arguments module to simplify handling of args
 	local getArgs = require('Module:Arguments').getArgs
 	
 	local args = getArgs(frame)
 	return p._Zh(args)
 end
 	
 function p._Zh(args)
 	local uselinks = not (args[&quot;links&quot;] == &quot;no&quot;) -- whether to add links
 	local uselabels = not (args[&quot;labels&quot;] == &quot;no&quot;) -- whether to have labels
 	local capfirst = args[&quot;scase&quot;] ~= nil
  
 	local t1 = false -- whether traditional Chinese characters go first
 	local j1 = false -- whether Cantonese Romanisations go first
 	local testChar
 	if (args[&quot;first&quot;]) then
 	 	 for testChar in mw.ustring.gmatch(args[&quot;first&quot;], &quot;%a+&quot;) do
 			if (testChar == &quot;t&quot;) then
 				t1 = true
 			 end
 			if (testChar == &quot;j&quot;) then
 				j1 = true
 			 end
 		end
 	end
 	if (t1 == false) then
 		local title = mw.title.getCurrentTitle()
 		t1 = t1st[title.text] == true
 	end
 
 	-- based on setting/preference specify order
 	local orderlist = {&quot;c&quot;, &quot;s&quot;, &quot;t&quot;, &quot;p&quot;, &quot;tp&quot;, &quot;w&quot;, &quot;j&quot;, &quot;cy&quot;, &quot;sl&quot;, &quot;poj&quot;, &quot;zhu&quot;, &quot;l&quot;, &quot;tr&quot;}
 	if (t1) then
 		orderlist[2] = &quot;t&quot;
 		orderlist[3] = &quot;s&quot;
 	end
 	if (j1) then
 		orderlist[4] = &quot;j&quot;
 		orderlist[5] = &quot;cy&quot;
 		orderlist[6] = &quot;sl&quot;
 		orderlist[7] = &quot;p&quot;
 		orderlist[8] = &quot;tp&quot;
 		orderlist[9] = &quot;w&quot;
 	end
 	
 	-- rename rules. Rules to change parameters and labels based on other parameters
 	if args[&quot;hp&quot;] then
 		-- hp an alias for p ([hanyu] pinyin)
 		args[&quot;p&quot;] = args[&quot;hp&quot;]
 	end
 	if args[&quot;tp&quot;] then
 		-- if also Tongyu pinyin use full name for Hanyu pinyin
 		labels[&quot;p&quot;] = &quot;Hanyu Pinyin&quot;
 	end
 	
 	if (args[&quot;s&quot;] and args[&quot;s&quot;] == args[&quot;t&quot;]) then
 		-- Treat simplified + traditional as Chinese if they're the same
 		args[&quot;c&quot;] = args[&quot;s&quot;]
 		args[&quot;s&quot;] = nil
 		args[&quot;t&quot;] = nil
 	elseif (not (args[&quot;s&quot;] and args[&quot;t&quot;])) then
 		-- use short label if only one of simplified and traditional
 		labels[&quot;s&quot;] = labels[&quot;c&quot;]
 		labels[&quot;t&quot;] = labels[&quot;c&quot;]
 	end
 
 	local body = &quot;&quot; -- the output string
 	local params -- for creating HTML spans
 	local label -- the label, i.e. the bit preceeding the supplied text
 	local val -- the supplied text
 	
 	-- go through all possible fields in loop, adding them to the output
 	for i, part in ipairs(orderlist) do
 		if (args[part]) then
 			-- build label
 			label = &quot;&quot;
 			if (uselabels) then
 				label = labels[part]
 				if (capfirst) then
 					label = mw.language.getContentLanguage():ucfirst(label)
 					capfirst = false
 				end
 				if (uselinks) then
 					label = &quot;[[&quot; .. wlinks[part] .. &quot;|&quot; .. label .. &quot;]]&quot;
 				end
 				if (labels[part] ~= &quot;lit.&quot;) then
 					label = label .. &quot;&amp;#58;&quot;
 				else
 					label = &quot;&lt;small&gt;&quot; .. label .. &quot;&lt;/small&gt;&quot;
 				end
 				label = label .. &quot; &quot;
 			end
 			-- build value
 			val = args[part]
 			if (cats[part]) and mw.title.getCurrentTitle().namespace == 0 then
 				-- if has associated category AND current page in article namespace, add category
 				val = cats[part] .. val
 			end
 			if (ISOlang[part]) then
 				-- add span for language if needed
 				params = {[&quot;lang&quot;] = ISOlang[part]}
 				val = mw.text.tag({name=&quot;span&quot;,attrs=params, content=val})
 			elseif ((part == &quot;l&quot;) or (part == &quot;tr&quot;)) then
 				-- put literals in quotes
 				val = &quot;'&quot; .. val .. &quot;'&quot;
 			end
 			if (italic[part]) then
 				-- italicise
 				val = &quot;&lt;i&gt;&quot; .. val .. &quot;&lt;/i&gt;&quot;
 			end
 			if string.match(val, &quot;&lt;/?sup&gt;&quot;) then val = val..&quot;[[Category:Pages using template Zh with sup tags]]&quot; end
 			if (superscript[part]) then
 				-- superscript
 				val = val:gsub(&quot;(%d)&quot;, &quot;&lt;sup&gt;%1&lt;/sup&gt;&quot;):gsub(&quot;(%d)&lt;/sup&gt;%*&lt;sup&gt;(%d)&quot;, &quot;%1*%2&quot;):gsub(&quot;&lt;sup&gt;&lt;sup&gt;([%d%*]+)&lt;/sup&gt;&lt;/sup&gt;&quot;, &quot;&lt;sup&gt;%1&lt;/sup&gt;&quot;)
 			end
 			-- add both to body
 			body = body .. label .. val .. &quot;; &quot;
 		end
 	end
 	
 	if (body &gt; &quot;&quot;) then -- check for empty string
 		return string.sub(body, 1, -3) -- chop off final semicolon and space
 	else --no named parameters; see if there's a first parameter, ignoring its name
 		if (args[1]) then
 			-- if there is treat it as Chinese
 			label = &quot;&quot;
 			if (uselabels) then
 				label = labels[&quot;c&quot;]
 				if (uselinks) then
 					label = &quot;[[&quot; .. wlinks[&quot;c&quot;] .. &quot;|&quot; .. label .. &quot;]]&quot;
 				end
 				label = label .. &quot;&amp;#58; &quot;
 			end
 			-- default to show links and labels as no options given
 			if mw.title.getCurrentTitle().namespace == 0 then
 				-- if current page in article namespace
 				val = cats[&quot;c&quot;] .. args[1]
 			else
 				val = args[1]
 			end
 			params = {[&quot;lang&quot;] = ISOlang[&quot;c&quot;]}
 			val = mw.text.tag({name=&quot;span&quot;,attrs=params, content=val})
 			return label .. val
 		end
 		return &quot;&quot;
 	end
 end