Jump to content

Module:ko-headword-hanja

From Wiktionary, the free dictionary

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local export = {}
local m_head = require('Module:headword')
local m_lang = require('Module:languages')

local strings = {
	['e'] = 'eum',
	['eh'] = '[[음훈#Korean|eumhun]]',
	['dueumBeopchik'] = '[[두음 법칙#Korean|word-initial]] (South Korea)',
}

function clone(table)
	local table_new = {}

	for k, v in pairs(table) do
		table_new[k] = v
	end

	return table_new
end

function export.show(frame)
	local params = {
		[1] = { list = true, allow_empty = true },
	}
	local args = require('Module:parameters').process(frame:getParent().args, params)

	local hunPage, hunText, hunLink, eum, eumDueumBeopchik

	if args[1][#args[1] - 1] == '' then
		eumDueumBeopchik = table.remove(args[1])
		table.remove(args[1])
	end
	eum = table.remove(args[1])
	hunText = table.remove(args[1])
	hunPage = table.remove(args[1])

	if hunText and string.match(hunText, '%[%[.+%]%]') then
		hunLink = hunText
	elseif hunPage then
		hunLink = '[[' .. hunPage .. '|' .. hunText .. ']]'
	elseif hunText then
		hunLink = '[[' .. hunText .. ']]'
	end

	local data = {}

	data.lang = m_lang.getByCode('ko')
	data.translits = {'-'}
	data.pos_category = 'hanja'
	data.categories = {}
	data.inflections = {}
	data.sort_key = eum -- or should this be radical+strokenumber?
	
	if eum then
		table.insert(data.inflections, {
			label = (hunLink and strings.eh or strings.e),
			(hunLink and hunLink .. ' ' or '') .. ('[[' .. eum .. ']]'),
			enable_auto_translit = true,
		})
	else
		error('The pronunciation of this hanja has not been provided.')
	end

	if eumDueumBeopchik then
		table.insert(data.inflections, {
			label = (strings.dueumBeopchik),
			(hunLink and hunLink .. ' ' or '')  .. ('[[' .. eumDueumBeopchik .. ']]'),
			enable_auto_translit = true,
		})
	end

	local fullHeadword = m_head.full_headword(data)

	fullHeadword = mw.ustring.gsub(fullHeadword, "eumhuneum", "eumhun-eum") -- XXX

	return fullHeadword
end

return export