Pergi ke kandungan

Modul:zh-see

Daripada Wikikamus
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 .. '#Cina|' .. text .. ']]') or text) .. '</span>'
end

function export.show(frame)
	local non_lemma_type = {
		['s'] = 'ringkas', ['simp'] = 'ringkas', ['simplified'] = 'ringkas',
		['a'] = 'purba', ['ancient'] = 'purba',
		['o'] = 'usang', ['obsolete'] = 'usang',
		['v'] = 'pelbagai', ['var'] = 'pelbagai', ['variant'] = 'pelbagai',
		['all'] = 'ringkas, usang atau pelbagai',
	}
	
	local args = frame:getParent().args
	local title = args[1]
	local content = mw.title.new(title):getContent()
	local simp = args["simp"] or false
	local non_lemma_cat = non_lemma_type[args[2] or 's'] or 'ringkas'
	local non_lemma_cat_article = non_lemma_cat == 'ringkas' and ' ' or (non_lemma_cat == 'pelbagai' and ' ' or ' ')
	local curr_title = mw.title.getCurrentTitle().subpageText
	local note = (mw.title.new(title) or {}).exists and "" or '[[Kategori:Kata bahasa China dengan bentuk yang tidak dicipta]]'
	
	local box =
		'{| class="wikitable' .. (non_lemma_cat == 'ringkas' and ' mw-collapsible mw-collapsed' or '') ..
			'" style="border:1px solid #797979; margin-left: 1px; text-align:left; width:' .. (40 + mw.ustring.len(title) * 3) .. '%"' ..
		
			'\n|-\n| style="background-color: #eeeeee; padding-left: 0.5em" | \'\'\'Untuk sebutan dan takrifan bagi \'\'\'' .. link(curr_title) .. 
			'\'\'\' – lihat ' .. link(title, true) .. (args[3] and (' ("' .. args[3] .. '")') or '') .. '.\'\'\'' ..
			
			'<br>(Kata ini, ' .. link(curr_title) .. ', ialah bentuk ' .. non_lemma_cat_article .. ' \'\'' .. non_lemma_cat .. '\'\' ' .. link(title) .. '' ..
			
			(simp and
				('<small>:&nbsp; ' .. link(sub(simp, 1, 1), true) .. ' → ' .. link(sub(simp, 2, 2), true) .. '</small>')
			or
				'') .. '.)' .. 
			
			(non_lemma_cat ~= 'ringkas' and '' or [=[

|-
| style="background-color: #F5DEB3; font-size: smaller" | <b>Nota:</b>
<div class="mw-collapsible-content">
* [[w:ms:Tulisan Cina Ringkas|Tulisan Cina Ringkas]] biasanya digunakan di Tanah Besar China dan Singapura.
* [[:w:ms:Tulisan Cina Tradisional|Tulisan Cina Tradisional]] biasanya digunakan di Hong Kong, Macau and Taiwan.</div></div>]=]) ..

			'\n|}' .. note
	
	local code = content and mw.ustring.match(content, '{{zh%-pron[^}]+}}') or false
	
	local function find_pron(variety)
		return sub(match(code, variety .. '=[^|}]+') or '', mw.ustring.len(variety) + 2, -1)
	end
	
	local categories = (code and mw.getCurrentFrame():expandTemplate{
		title = "Template:zh-pron",
		args = {
			['m'] = find_pron('m'),
			['c'] = find_pron('c'),
			['h'] = find_pron('h'),
			['md'] = find_pron('md'),
			['mn'] = find_pron('mn'),
			['w'] = find_pron('w'),
			['cat'] = find_pron('cat'),
			['only_cat'] = 'yes',
			}
		} or '')
	
	return box .. categories
end

return export