Module: 地區用詞

local p =

local variants = {

	cn = 'hans',

	hk = 'hant',

	mo = 'hant',

	my = 'hans',

	sg = 'hans',

	tw = 'hant',

}

local lc = require ('Module:WikitextLC')

function p._main (args, frame)

	local values = 	-- dict => ,

						-- where "term" is the index of the relevant string in "terms"

	local terms = 	-- table of term objects:

						--		regions: table, regions that use this term

						--		hans, hant: string, term in different scripts

	local showLocal = args.showLocal and args.showLocal ~= 'no'

	local showForeign = args.showForeign and args.showForeign ~= 'no'

	-- fill region values, simp and trad, from explicit definitions

	for region, defaultScript in pairs (variants) do

		if args'zh-hans-' .. region ~= or args'zh-hant-' .. region ~= or args'zh-' .. region ~= then

			local term = {regions = { region} }

			if args'zh-hans-' .. region ~= then

				term.hans = args'zh-hans-' .. region

			elseif args'zh-' .. region ~= then

				term.hans = lc.converted (args'zh-' .. region, 'zh-hans')

			else

				term.hans = lc.converted (args'zh-hant-' .. region, 'zh-hans')

			end

			if args'zh-hant-' .. region ~= then

				term.hant = args'zh-hant-' .. region

			elseif args'zh-' .. region ~= then

				term.hant = lc.converted (args'zh-' .. region, 'zh-hant')

			else

				term.hant = lc.converted (args'zh-hans-' .. region, 'zh-hant')

			end

			table.insert (terms, term)

			valuesregion = {script = defaultScript, term = #terms}

		end

	end

	-- link up "equiv" aliases for missing regions

	for region, defaultScript in pairs (variants) do

		if valuesregion == nil and valuesargs'equiv-' .. region ~= nil then

			table.insert (termsvaluesargs'equiv-' .. region.term.regions, region)

			valuesregion = {script = defaultScript, term = valuesargs'equiv-' .. region.term}

		end

	end

	local localName =

	for region, value in pairs (values) do

		localName'zh-' .. region = termsvalue.termvalue.script

	end

	localName = args.beforeTerm .. lc.selective (localName) .. args.afterTerm

	local foreignName =

	for region, script in pairs (variants) do

		local snippets =

		for _, term in pairs (terms) do

			local termRegions =

			for _, termRegion in pairs (term.regions) do

				if not args.stripLocal or args.stripLocal == or termRegion ~= region and not (valuestermRegion and valuesregion and valuestermRegion.term == valuesregion.term) then

					table.insert (termRegions, termRegion)

				end

			end

			if #termRegions > 0 then

				table.sort (termRegions)

				local maybeNameKey = 'name-' .. table.concat (termRegions, '-')

				local name

				if argsmaybeNameKey and argsmaybeNameKey ~= then

					name = argsmaybeNameKey

				else

					local names =

					for _, termRegion in pairs (termRegions) do

						table.insert (names, args'name-' .. termRegion)

					end

					name = mw.text.listToText (names, args.nameComma, args.nameLastComma)

				end

				name = lc.converted (name .. args.colon, 'zh-' .. region)

				table.insert (snippets, name .. args.beforeTerm .. termscript .. args.afterTerm)

			end

		end

		foreignName'zh-' .. region = mw.text.listToText (snippets, lc.converted ( args.comma, 'zh-' .. region), lc.converted (args.lastComma, 'zh-' .. region) )

	end

	foreignName = lc.selective (foreignName)

	if showLocal then

		local ret = localName .. args.afterLocal

		if showForeign then

			ret = ret .. args.openBracket .. foreignName .. args.closeBracket

		end

		return ret

	elseif showForeign then

		return foreignName

	end

	error ('Module: 地區用詞: Nothing to show.')

end

function p.main (frame)

	local args =

	for k, v in pairs (frame:getParent .args ) do

		argsk = v

	end

	for k, v in pairs (frame.args) do

		argsk = v

	end

	return p._main (args, frame)

end

return p