Module:zh-track

From Wiktionary, the free dictionary
Jump to navigation Jump to search
This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local export = {}

local match = mw.ustring.match
local split = mw.text.split

function export.track_data_module(page)
	if not page then page = mw.title.getCurrentTitle().fullText end
	if type(page) == 'table' then page = page.args[1] end
	page_part = split(page, "/")
	page_type = page_part[3] 
	page_param = page_part[3] == "ltc-pron" and "|mc=[1-9y]" or "|oc=[1-9y]" 
	page_char = page_part[4] 
	if not (mw.title.new(page_char) or {}).exists then
		require('Module:debug').track('zh-track/' .. page_type .. '/character page not found')
		return
	end
	local content = mw.title.new(page_char):getContent() or ""
	if not match(content, "==Chinese==") then
		if match(content, "==Mandarin==") then
			require('Module:debug').track('zh-track/' .. page_type .. '/ununified character page')
		else
			require('Module:debug').track('zh-track/' .. page_type .. '/no Chinese section found')
		end
	elseif not match(content, "zh%-pron") then
		if match(content, "zh%-see") then
			require('Module:debug').track('zh-track/' .. page_type .. '/variant or simplified character')
		else
			require('Module:debug').track('zh-track/' .. page_type .. '/no character pronunciation')
		end
	elseif not match(content, page_param) then
		require('Module:debug').track('zh-track/' .. page_type .. '/unused data module')
	end
end

return export