非補題の中国のページのためにソフトリダイレクトモジュール。見ている{{zh-see}}のためのより多くを見てください。



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 .. '#中国語|' .. text .. ']]') or text) .. '</span>'
end

function export.show(frame)
	local non_lemma_type = {
		['s'] = '簡略化', ['simp'] = '簡略化', ['simplified'] = '簡略化',
		['a'] = '古代の', ['ancient'] = '古代の',
		['o'] = '時代遅れの', ['obsolete'] = '時代遅れの',
		['v'] = '変化', ['var'] = '変化', ['variant'] = '変化',
		['av'] = '古代の変種',
		['sv'] = '簡易型&#x304A;&#x3088;&#x3073;変化型の伝統的な',
		['all'] = '簡単な、時代遅れのまたは変化',
	}
	
	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
	
	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:まだ存在しない形で中国語]]'
	
	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" | \'\'\'発音との定義のための\'\'\'' .. link(mw.ustring.gsub(curr_title, '(.)', '[[%1]]'), false) .. 
			'\'\'\' <span style="font-size:120%">' .. link(title, true) .. '</span>' .. (args[3] and (' (“' .. args[3] .. '”)') or '') .. '\'\'\'を見てください。\'\'\'' ..
			
			'<br>(この ' .. (mw.ustring.len(title) == 1 and '文字' or '項' ) .. '' .. link(curr_title) .. ',' .. ' \'\'' .. link(title) ..  'の' .. non_lemma_cat ..   '' ..
			
			(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>ノート:</b>
* 簡体字中国語は主に中国本土とシンガポールで使われます。
* 繁体字中国語主に香港で使われている、と台湾マカウ。]=] or '') ..

			'\n|}' .. note
	
	local cat = { "variant", "simplified", "obsolete" }

	
	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
	end

	return box .. categories
end

return export