모듈:ko-headword-hanja

관련 모듈

편집

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

local strings = {
    ['e'] = '음',
    ['eh'] = '[[음훈]]',
    ['dueumBeopchik'] = '[[두음 법칙]]',
}

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 = '한자'
    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('이 한자의 발음은 제공되지 않았습니다.')
    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

    -- Apply inline styles to relevant parts of the headword
    fullHeadword = mw.ustring.gsub(fullHeadword, '(<strong class="[^"]* headword" lang="ko">[^<]*</strong>)', '<span style="font-size:1.25em;">%1</span>')
    fullHeadword = mw.ustring.gsub(fullHeadword, '(<b class="[^"]*" lang="ko">[^<]*</b>)', '<span style="font-size:1.25em;">%1</span>')

    return fullHeadword
end

return export