Module:zh-verb

From Wiktionary, the free dictionary
Jump to navigation Jump to search

local export = {}

function export.show(frame)
	local args = frame:getParent().args
	local title = args.pagename or mw.title.getCurrentTitle().text
	local inflections = {}

	if args.type then
		local wordtype, div_pos = args.type:match('([a-z]+)([1-9]*)')
		
		local valid_types = {
			['sp'] = 'subject-predicate',
			['vo'] = 'verb-object',
			['vc'] = 'verb-complement',
			['mv'] = 'modifier-verb',
		}

		wordtype = valid_types[wordtype] or error('Invalid value for parameter "type".')

		div_pos = tonumber(div_pos) or 1
		if mw.ustring.sub(title, div_pos+1, div_pos+1) ~= " " then
			title = mw.ustring.sub(title, 1, div_pos) .. "⫽" .. mw.ustring.sub(title, div_pos + 1)
		else
			title = mw.ustring.sub(title, 1, div_pos) .. "⫽" .. mw.ustring.sub(title, div_pos + 2)
		end
		inflections[1] = {label = wordtype}
	end
	return require('Module:headword').full_headword{
		lang = require('Module:languages').getByCode('zh'),
		sc = args.sc and require('Module:scripts').getByCode(args.sc) or nil,
		heads = {title},
		no_redundant_head_cat = true,
		inflections = inflections,
		categories = {'Chinese verbs'}
	}
end

return export