logo

Module:Zh-see是什么意思_Module:Zh-see读音|解释_Module:Zh-see同义词|反义词

Module:Zh-see



local export = {}
local m_zh = require("Module:zh")
local sub = mw.ustring.sub
local gsub = mw.ustring.gsub
local match = mw.ustring.match

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

local function get_occurrence(content)
	local _, occurrence = content:gsub("zh%-pron", "zh-see"):gsub("zh%-see", "")
	return occurrence
end

function export.show(frame)
	local non_lemma_type = {
		['s'] = '簡化字', ['simp'] = '簡化字', ['simplified'] = '簡化字', ['簡化字'] = '簡化字', ['简化字'] = '簡化字', ['簡化'] = '簡化字', ['简化'] = '簡化字', ['簡'] = '簡化字', ['简'] = '簡化字', ['j'] = '簡化字', ['jian'] = '簡化字',
		['fs'] = '一簡字(1964-1986)',
		['fsv'] = '一簡字(1964-1986)和異體字',
		['ss'] = '二簡字',
		['ssv'] = '二簡字和異體字',
		['sgs'] = '新加坡簡體字(1969–1976)',
		['sgsv'] = '新加坡簡體字(1969–1976)和異體字',
		['sgss'] = '新加坡簡體字(1969–1976)和二簡字',
		['sgssv'] = '新加坡簡體字(1969–1976)、二簡字和異體字',
		['rocs'] = '第一批簡體字表(1935–1936)', -- 中華民國教育部
		['rocsv'] = '第一批簡體字表(1935–1936)和異體字',
		['rocss'] = '第一批簡體字表(1935–1936)和二簡字',
		['rocssv'] = '第一批簡體字表(1935–1936)、二簡字和異體字',
		['rocsgs'] = '第一批簡體字表(1935–1936)和新加坡簡體字(1969–1976)',
		['rocsgsv'] = '第一批簡體字表(1935–1936)、新加坡簡體字(1969–1976)和異體字',
		['rocsgssv'] = '第一批簡體字表(1935–1936)、新加坡簡體字(1969–1976),二簡字和異體字',
		['rocfs'] = '第一批簡體字表(1935–1936)和一簡字(1964-1986)',
		['rocfsv'] = '第一批簡體字表(1935–1936)、一簡字(1964-1986)和異體字',
		['rocfsgs'] = '第一批簡體字表(1935–1936)、一簡字(1964-1986)和新加坡簡體字(1969–1976)',
		['rocfsgsv'] = '第一批簡體字表(1935–1936)、一簡字(1964-1986)、新加坡簡體字(1969–1976)和異體字',
		['rocfsgssv'] = '第一批簡體字表(1935–1936)、一簡字(1964-1986)、新加坡簡體字(1969–1976)、二簡字和異體字',
		['ds'] = '漢字簡化方案草案(1955)', -- 中華人民共和國國務院
		['dsv'] = '漢字簡化方案草案(1955)和異體字',
		['dss'] = '漢字簡化方案草案(1955)和二簡字',
		['dssv'] = '漢字簡化方案草案(1955)、二簡字和異體字',
		['dsgs'] = '漢字簡化方案草案(1955)和新加坡簡體字(1969–1976)',
		['dsgsv'] = '漢字簡化方案草案(1955)、新加坡簡體字(1969–1976)和異體字',
		['dsgssv'] = '漢字簡化方案草案(1955)、新加坡簡體字(1969–1976)、二簡字和異體字',
		['rocds'] = '第一批簡體字表(1935–1936)和漢字簡化方案草案(1955)',
		['rocdsv'] = '第一批簡體字表(1935–1936)、漢字簡化方案草案(1955)和異體字',
		['rocdss'] = '第一批簡體字表(1935–1936)、漢字簡化方案草案(1955)和二簡字',
		['rocdssv'] = '第一批簡體字表(1935–1936)、漢字簡化方案草案(1955)、二簡字和異體字',
		['rocdsgs'] = '第一批簡體字表(1935–1936)、漢字簡化方案草案(1955)和新加坡簡體字(1969–1976)',
		['rocdsgsv'] = '第一批簡體字表(1935–1936)、漢字簡化方案草案(1955)、新加坡簡體字(1969–1976)和異體字',
		['rocdsgssv'] = '第一批簡體字表(1935–1936)、漢字簡化方案草案(1955)、新加坡簡體字(1969–1976)、二簡字和異體字',
		['ns'] = '非標準簡化字',
		['a'] = '古字', ['ancient'] = '古字', ['古字'] = '古字', ['古'] = '古字', ['g'] = '古字', ['gu'] = '古字',
		['o'] = '淘汰舊字', ['obsolete'] = '淘汰舊字',
		['v'] = '異體字', ['var'] = '異體字', ['variant'] = '異體字', ['異體'] = '異體字', ['异体'] = '異體字', ['異'] = '異體字', ['异'] = '異體字', ['y'] = '異體字', ['yi'] = '異體字',
		['vt'] = '傳統異體字',
		['av'] = '古代異體字',
		['is'] = '網路俚語異體字',
		['sv'] = '簡體字和異體字',
		['svt'] = '簡體字和傳統異體字',
		['hv'] = '有辭書收錄過的異體字',
		['hdv'] = '有辭書收錄過的異體字',
		['hduo'] = '有辭書收錄過的非正體字',
		['ha'] = '有辭書收錄過的古體字',
		['hda'] = '有辭書收錄過的古體字',
		['poj'] = '[[白話字]]',
		['err'] = '訛字', ['corrupt'] = '訛字', ['c'] = '訛字', ['訛'] = '訛字', ['讹'] = '訛字', ['e'] = '訛字',
		['l'] = '借字',

		['all'] = '簡體字、異體字、淘汰舊字或異體字',
	}

	local args = frame:getParent().args
	local title = args[1]
	local curr_title = mw.title.getCurrentTitle().subpageText
	local content = mw.title.new(title):getContent()
	local title_exists = content ~= nil
	local simp = args["simp"] or false
	local non_lemma_abbrev = args[2] or ""
	local categories = ''

	if title == curr_title then
		return error("The soft-directed item is the same as the page title.")
	end

	if content then
		if not match(content, "==漢語==") then
			categories = categories .. '[[Category:漢語紅鏈/zh-see]]'
		elseif not match(content, "zh%-pron") and not match(content, "zh%-see") 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

		occurrence = get_occurrence(content)
		if match(content, "zh%-see") and occurrence == 1 then
			new_title = match(content, "zh%-see%|([^%|%}]+)")
			if non_lemma_abbrev == "" and occurrence == 1 and match(content, "zh%-see%|([^%|%}]+)%|v") then
				chain = true
			end
			content = mw.title.new(new_title):getContent()
		end
	end
	
	if content then
		content = gsub(content, "zh%-forms", "Ѭ")
		content = gsub(content, "zh%-pron", "Ꙁ")
		if non_lemma_abbrev == "" 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 .. "vt"
						end
						if match(forms_template, "|alt=[^|}\n]*" .. curr_title) then
							non_lemma_abbrev = non_lemma_abbrev .. "v"
						end
						break
					end
				end
			end
		end
	end

	local non_lemma_cat = non_lemma_type[non_lemma_abbrev ~= "" and non_lemma_abbrev or 's'] or '簡體字'
	local note = (content or mw.title.getCurrentTitle().nsText ~= "") and "" or '[[Category:未有頁面的漢字]]'

	local gloss_text = args[3] or (content and require("Module:zh/extract").extract_gloss(gsub(content, "Ѭ", "zh%-forms"), true) or "")
	local box =
		'{| class="wikitable' .. (match(non_lemma_cat, '簡') and ' mw-collapsible mw-collapsed' or '') ..
			'" style="border:1px solid #797979; margin-left: 1px; text-align:left; min-width:' .. (chain and 80 or 70) .. '%"' ..

			'\n|-\n| style="background-color: #eeeeee; padding-left: 0.5em" | \'\'\'關於「\'\'\'' .. (non_lemma_abbrev=="poj" and curr_title or link(mw.ustring.gsub(curr_title, '(.)', '-{[[%1#漢語|%1]]}-'), false)) ..
			'\'\'\'」的發音和釋義,請看<span style="font-size:120%">「-{' .. link(title, true) .. '}-」</span>' .. (gloss_text ~= "" and ('(「' .. gloss_text .. '」)') or '') .. '。\'\'\'' ..

			'<br>此' .. (mw.ustring.len(title) == 1 and '字' or '詞' ) .. '「-{' .. link(curr_title) .. '}-」是「-{' .. link(title) .. '}-」的' .. non_lemma_cat ..'。'..

			(match(non_lemma_cat, '簡') and [=[

|-
| class="mw-collapsible-content" style="background-color: #F5DEB3; font-size: smaller" | <b>註解:</b>
* [[w:簡體中文|簡體字]]主要在中國大陸、馬來西亞和新加坡使用。
* [[w:繁體中文|繁體字]]主要在香港、澳門和臺灣使用。]=] or '') ..

			'\n|}' .. note

	local cat = { "variant", "simplified", "obsolete" }
	local m_cat = require("Module:zh-cat")

	for _, word in ipairs(cat) do
		if match(non_lemma_cat, word) then
			categories = categories .. m_cat.categorize(word)
		end
	end

	if content then
		local part_a, part_b, part_c = '{{Ѭ[^%}]+' .. curr_title .. '[^%}]*}}', '[^ѬꙀ]+', '({{Ꙁ.+\n%|cat%=[^\n]*\n?}})'
		local match_group = mw.ustring.len(gsub(content, "[^Ѭ]", "")) == 1
			and mw.ustring.gmatch(content, '{{Ꙁ[^Ꙁ]+%|cat%=[^\n]*\n?}}')
			or (match(content, part_a)
				and (match(content, part_a .. part_b .. part_c)
					and mw.ustring.gmatch(content, part_a .. part_b .. part_c)
					or mw.ustring.gmatch(content, part_c .. part_b .. part_a))
				or mw.ustring.gmatch(content, part_c))

		for match_result in match_group do
			local function find_pron(variety)
				return match(match_result, '|' .. variety .. '=([^|}\n]*)') or ''
			end
			if non_lemma_abbrev == "poj" then
				categories = categories .. frame:expandTemplate{
					title = "Template:zh-pron",
					args = {
						['mn'] = find_pron('mn'),
						['cat'] = find_pron('cat'),
						['only_cat'] = 'yes',
						}
					}
			else
				categories = categories .. frame:expandTemplate{
					title = "Template:zh-pron",
					args = {
						['m'] = find_pron('m'),
						['c'] = find_pron('c'),
						['c-t'] = find_pron('c%-t'),
						['dg'] = find_pron('dg'),
						['g'] = find_pron('g'),
						['h'] = find_pron('h'),
						['j'] = find_pron('j'),
						['mb'] = find_pron('mb'),
						['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
		end

		if non_lemma_abbrev ~= "poj" then
			local match_cat = mw.ustring.match(content, "{{zh%-cat%|([^}]+)}}") or nil
			if match_cat then
				match_cat_group = mw.text.split(match_cat, "|")
				categories = categories .. frame:expandTemplate{
					title = "Template:zh-cat",
					args = match_cat_group
				}
			end

			--local 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
			--		local 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

			local match_char_comp = mw.ustring.match(content, "{{zh%-character component%|") or nil
			--mw.log(match_char_comp)
			if match_char_comp then
				categories = categories .. frame:expandTemplate{
					title = "Template:zh-cat",
					args = { "漢字部件" }
				}
			end
		else
			categories = categories .. "[[Category:閩南語白話字]]"
		end
	end

	return box .. categories
end

return export