Module:documentation/functions/zh data

From Wiktionary, the free dictionary
Jump to navigation Jump to search


return function (title, cats)
	local output = require("Module:array")()
	
	local function zh_link(lang, word)
		return require("Module:links").full_link{
			lang = lang,
			term = word,
			tr = "-"
		}
	end
	
	local zh_data_subpage, lang_code, reconstruction, last_segment =
		mw.ustring.match(title.fullText,
			"^Module:zh/data/((%l%l%l)%-pron%-?([^/]-))/(.+)$")
	if zh_data_subpage == "ltc-pron" or zh_data_subpage == "och-pron-BS"
			or zh_data_subpage == "och-pron-ZS" then
		require('Module:zh-track').track_data_module(title.fullText)
		
		local lang = require "Module:languages".getByCode(lang_code)
		
		local characters, extra
		-- Last segment is either a Han character or three hexadecimal digits
		-- (the first three digits of the code point).
		if mw.ustring.len(last_segment) == 1 then
			characters = zh_link(lang, last_segment)
			extra = ""
		else
			local code_point_prefix = last_segment
			local function make_code_point(digit)
				return tonumber(code_point_prefix .. (digit):rep(6 - #code_point_prefix), 16)
			end
			characters = (("characters in the range U+%04X–U+%04X"):format(
				make_code_point("0"), make_code_point("F")))
			
			extra = " is only a test and is unused. It"
		end
		output:insert(('This module%s contains data on the pronunciation of %s')
			:format(extra, characters))
		
		local see_also_link
		if reconstruction == "BS" then
			see_also_link = 'Wiktionary:About Proto-Sino-Tibetan#Reconstruction by Baxter-Sagart (2014)'
		elseif reconstruction == "ZS" then
			see_also_link = 'Wiktionary:About Proto-Sino-Tibetan#Reconstruction by Zhengzhang (2003)'
		else
			reconstruction = nil
		end
		
		local lang_link = lang:makeCategoryLink()
		if reconstruction then
			output:insert(("in the reconstruction of %s by %s.")
				:format(lang_link, reconstruction == "BS" and "Baxter-Sagart" or "Zhengzhang"))
		else
			output:insert(("in %s."):format(lang_link))
		end
		
		if see_also_link then
			output:insert("See " .. require("Module:links").section_link(see_also_link)
				.. " for more information.")
		end
		
		return output:concat(" ") .. "\n\nIf you see an error, please post an edit "
			.. "request in the [[WT:TEA|Tea Room]]."
	end
end