Module:zh-see

Mula Wiktionary

Ang dokumentasyon ng ng modyul na ito ay maaaring likhain sa Module:zh-see/doc

local export = {}
local sub = mw.ustring.sub
local match = mw.ustring.match

local function link(text, make_link)
	return '<span lang="zh" class="Hani">' .. (make_link and ('[[' .. text .. '#Chinese|' .. text .. ']]') or text) .. '</span>'
end

function export.show(frame)
	local non_lemma_type = {
		['s'] = 'pinapayak na', ['simp'] = 'pinapayak na', ['simplified'] = 'pinapayak na',
		['a'] = 'makalumang', ['ancient'] = 'makalumang',
		['o'] = 'hindi na ginagamit na', ['obsolete'] = 'hindi na ginagamit na',
		['v'] = 'baryenteng', ['var'] = 'baryenteng', ['variant'] = 'baryenteng',
		['av'] = 'makalumang baryenteng',
		['sv'] = 'pinapayak at tradisyonal na baryenteng',

		['all'] = 'pinapayak, hindi na ginagamit o baryenteng',
	}
	
	local args = frame:getParent().args
	local title = args[1]
	local curr_title = mw.title.getCurrentTitle().subpageText
	local content = mw.title.new(title):getContent() or ""
	local simp = args["simp"] or false
	local non_lemma_abbrev = args[2] or ""
	
	if title == curr_title then
		return error("The soft-directed item is the same as the page title.")
	end

	if not match(content, "==Chinese==") then
		require('Module:debug').track('zh-see/no Chinese section found')
	elseif not match(content, "zh%-pron") then
		require('Module:debug').track('zh-see/unidirectional reference to variant')
	elseif not match(content, curr_title) then
		require('Module:debug').track('zh-see/unidirectional reference variant→orthodox')
	end
	
	content = mw.ustring.gsub(content, "zh%-forms", "Ѭ")
	content = mw.ustring.gsub(content, "zh%-pron", "Ꙁ")
	if non_lemma_abbrev == "" and mw.title.new(title).exists then
		template = mw.ustring.match(content, "{{Ѭ[^}]*}}") or false
		if template then
			for forms_template in mw.ustring.gmatch(content, "{{Ѭ[^}]*}}") do
				if match(forms_template, curr_title) then
					if match(forms_template, "s[0-9]*=" .. curr_title) then
						non_lemma_abbrev = non_lemma_abbrev .. "s"
					end
					if match(forms_template, "t[0-9]*=" .. curr_title) then
						non_lemma_abbrev = non_lemma_abbrev .. "v"
					end
					break
				end
			end
		end
	end
	local non_lemma_cat = non_lemma_type[non_lemma_abbrev ~= "" and non_lemma_abbrev or 's'] or 'the simplified'
	local note = ((mw.title.new(title) or {}).exists and mw.title.getCurrentTitle().nsText == "") and "" or '[[Category:Chinese terms with uncreated forms]]'
	
	local box =
		'{| class="wikitable' .. (match(non_lemma_cat, 'simplified') and ' mw-collapsible mw-collapsed' or '') ..
			'" style="border:1px solid #797979; margin-left: 1px; text-align:left; min-width:70%"' ..
		
			'\n|-\n| style="background-color: #eeeeee; padding-left: 0.5em" | \'\'\'Para sa pagbaybay at kahulugan ng \'\'\'' .. link(mw.ustring.gsub(curr_title, '(.)', '[[%1]]'), false) .. 
			'\'\'\' – tignan ang <span style="font-size:120%">' .. link(title, true) .. '</span>' .. (args[3] and (' (“' .. args[3] .. '”)') or '') .. '.\'\'\'' ..
			
			'<br>(Ang ' .. (mw.ustring.len(title) == 1 and 'karakter na' or 'terminong' ) .. ', ' .. link(curr_title) .. ', ay isang ' .. ' \'\'' .. non_lemma_cat .. '\'\' anyo ng ' .. link(title) .. '' ..
			
			(simp and
				('<small>:&nbsp; ' .. link(sub(simp, 1, 1), true) .. ' → ' .. link(sub(simp, 2, 2), true) .. '</small>')
			or
				'') .. '.)' .. 
			
			(match(non_lemma_cat, 'simplified') and [=[

|-
| class="mw-collapsible-content" style="background-color: #F5DEB3; font-size: smaller" | <b>Notes:</b>
* Ang [[w:Simplified Chinese|Pinapayak na Tsino]] ay ginagamit sa PRC at Singapore.
* Ang [[w:Traditional Chinese|Tradisyonal na Tsino]] ay ginagamit sa Hong Kong, Macau at Taiwan.]=] or '') ..

			'\n|}' .. note
	
	local cat = { "variant", "simplified", "obsolete" }
	local m_cat = require("Module:zh-cat")
	
	categories = ''
	for _, word in ipairs(cat) do
		if match(non_lemma_cat, word) then
			categories = categories .. m_cat.categorize(word)
		end
	end
	
	if content then
		match_group = mw.ustring.len(mw.ustring.gsub(content, "[^Ѭ]", "")) == 1
			and mw.ustring.gmatch(content, '{{Ꙁ[^Ꙁ]+%|cat%=[^\n]+\n?}}')
			or mw.ustring.gmatch(content, '{{Ѭ[^%}]+' .. curr_title .. '[^%}]*}}[^ѬꙀ]+({{Ꙁ.+\n%|cat%=[^\n]+\n?}})')
		
		for match_result in match_group do
			local function find_pron(variety)
				return sub(match(match_result, variety .. '=[^|}]+') or '', mw.ustring.len(variety) + 2, -1)
			end
		
			categories = categories .. mw.getCurrentFrame():expandTemplate{
				title = "Template:zh-pron",
				args = {
					['m'] = find_pron('m'),
					['c'] = find_pron('c'),
					['g'] = find_pron('g'),
					['h'] = find_pron('h'),
					['j'] = find_pron('j'),
					['md'] = find_pron('md'),
					['mn'] = find_pron('mn'),
					['mn-t'] = find_pron('mn-t'),
					['w'] = find_pron('w'),
					['x'] = find_pron('x'),
					['cat'] = find_pron('cat'),
					['only_cat'] = 'yes',
					}
				}
		end
		
		match_cat = mw.ustring.match(content, "{{zh%-cat%|([^}]+)}}") or nil
		if match_cat then
			match_cat_group = mw.text.split(match_cat, "|")
			categories = categories .. mw.getCurrentFrame():expandTemplate{
				title = "Template:zh-cat",
				args = match_cat_group
			}
		end
		
		match_label = mw.ustring.gmatch(content, "{{lb%|zh%|([^}]+)}}") or nil
		if match_label then
			local lang = require("Module:languages").getByCode("zh")
			for match_label_item in match_label do
				match_label_group = mw.text.split(match_label_item, "|")
				local label_text = require("Module:labels").show_labels(match_label_group, lang)
				categories = categories .. (mw.ustring.match(label_text, "%[%[Category:[^%]]+%]%]") or "")
			end
		end
		
	end

	return box .. categories
end

return export