Module:ko-utilities

Definition from Wiktionary, the free dictionary
Jump to: navigation, search
The following documentation is located at Module:ko-utilities/documentation. [edit]
Useful links: subpage listtransclusionstestcases

local M = {}
 
function M.extract_hanja(f)
    local text = f.args[1]
    local len = 1
    local result = ''
    len = mw.ustring.len(text)
    if mw.ustring.match(text, '[丁-龯㐀-䶵]') then
        result = '{{ko-hanjatab'
        for i = 1, len, 1 do
            char = mw.ustring.sub(text,i,i)
            result = (result .. '|' .. char)
        end
        result = (result .. '}}')
    end
    return result
end
 
-- makes hanjatab automatically
function M.hanjatab()
	local hanja = mw.ustring.gsub(mw.title.getCurrentTitle().text, '[^一-鿌]', '')
		local table_head = '<table align="right" border="0" cellpadding="3" cellspacing="0" style="border:1px solid #aaaaaa; margin-left:5px; margin-right:10px; font-size:8pt; text-align:center; margin: 0 0 1em 1em;" rules="all" frame="box"><tr><td colspan="' .. 
		mw.ustring.len(hanja) .. 
		'" bgcolor="#f9f9f9">[[hanja|Hanja]] in this word</td></tr><tr style="font-size: 2em">'
	return table_head .. 
		mw.ustring.gsub(hanja, '(.)', '<td><font lang="ko">[[%1#Korean|%1]]</font></td>') .. 
		'</table>'
end
 
-- return only non-hangeul contained in text
function M.remove_hangeul(f)
	local nonhangeul = mw.ustring.gsub(f.args[1], '[가-힣]', '')
	return nonhangeul
end
 
function M.usex_hangul(f)
	hangul = mw.ustring.gsub(f.args[1],'[%^%-]','')
	return hangul
end
 
function M.links(f)
	local word = f.args[1]
	if not mw.ustring.match(word,'[%[%]]') then
		if mw.ustring.gsub(word,'—.+—','') == '' then
			word = mw.ustring.gsub(word,'—(.+)—','—[[%1]]—')
		elseif mw.ustring.gsub(word,'—.+','') == '' then
			word = mw.ustring.gsub(word,'—(.+)','—[[%1]]')
		elseif mw.ustring.gsub(word,'.+—','') == '' then
			word = mw.ustring.gsub(word,'(.+)—','[[%1다|%1—]]')
		end
	end
	return word
end
 
return M