Jump to content

Module:Korean/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Grapesurgeon (talk | contribs) at 19:41, 12 April 2025 (none). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
require('strict');
local p = {}

function p.ko(frame)
	local getArgs = require('Module:Arguments').getArgs
	local args = getArgs(frame)
	return p._ko(args)
end

function p._ko(args)
	local lang_module = require('Module:Lang')     -- used for wrapping non-English text
	local translit = require('Module:Ko-translit') -- used for automatic romanization
	local ipa_module = require('Module:IPA')       -- used for IPA (duh)
	local template = 'Korean' 
	
	return ipa_module._main({'ko', 'asdf', ['label'] = ''})
	-- -- assign positional params
	-- local hangul, hanja
	-- if args['hangul'] then hangul = args['hangul'] else hangul = args[1] end
	-- if args['hanja'] then hanja = args['hanja'] else hanja = args[2] end
	
	-- -- validate input
	-- if not hangul then return p.format_error('Must provide Hangul.') end
	-- if args['hanjaref'] and not hanja then
	-- 	return p.format_error('No Hanja provided for given Hanja ref.')
	-- end
	-- if args['iparef'] and not args['ipa'] then
	-- 	return p.format_error('No IPA provided for given IPA ref.')
	-- end
	
	-- -- apply name mode
	-- if args['namemode'] == 'yes' then
	-- 	hangul = '%' .. hangul
	-- end
	
	-- -- apply capitalization
	-- if args['capitalize'] == 'yes' then
	-- 	hangul = '^' .. hangul
	-- end
	
	-- -- romanize
	-- local rr_out
	-- if args['rr'] == 'yes' then
	-- 	rr_out = translit.rr(hangul)                                            -- generate automatic RR
	-- 	rr_out = lang_module._xlit({'ko', 'rr', rr_out, ['template']=template}) -- wrap in {{translit|ko|rr}}
	-- end
	-- local mr_out
	-- if args['mr'] == 'yes' then
	-- 	mr_out = translit.mr(hangul)
	-- 	mr_out = lang_module._xlit({'ko', 'mr', mr_out, ['template']=template})
	-- end
	
	-- -- prep hangul for display
	-- hangul = translit.cleanHangul(hangul)                                       -- remove syntax characters
	-- hangul = lang_module._lang({'ko', hangul, ['template']=template})              -- wrap in lang template
	
	-- -- prep hanja for display
	-- if hanja then
	-- 	hanja = lang_module._lang({'ko', hanja, ['template']=template})
	-- end
	
	-- -- prep display order string
	-- local order
	-- if args['order'] then
	-- 	order = args['order']
		
	-- 	-- check if order is malformed
	-- 	if not string.find(order, 'h') then return p.format_error('Order is missing "h".') end
	-- 	if not (hanja and string.find(order, 'z')) then return p.format_error('Order is missing "z" or Hanja not provided.') end
	-- 	if not (args['rr'] and string.find(order, 'r')) then return p.format_error('Order is missing "r" or RR not provided.') end
	-- 	if not (args['mr'] and string.find(order, 'm')) then return p.format_error('Order is missing "m" or RR not provided.') end
	-- 	if (string.find(order, 'l') and not args['lit']) then return p.format_error('Order has "l" but literal translation not provided.') end
	-- else
	-- 	-- default order (hangul, hangulref, ipa, iparef, hanja, hanjaref, rr, mr, lit) if none given
	-- 	order = 'h'
	-- 	if args['ipa'] then order = order .. 'i' end
	-- 	if hanja then order = order .. 'z' end
	-- 	if args['rr'] == 'yes' then order = order .. 'r' end
	-- 	if args['mr'] == 'yes' then order = order .. 'm' end
	-- 	if args['lit'] then order = order .. 'l' end
	-- end
	
	-- -- iterate through the order and add elements to output
	-- local result = {}
	-- local c, label
	-- for i = 1, #order do
	--     c = order:sub(i, i)
	    
	--     -- hangul processing
	--     if c == 'h' then
	--     	-- language label insertion (more complicated conditionals in function)
	--     	if args['links'] == 'no' then
	--     		label = 'Korean: '
 --   		else
 --   			label = '[[Korean language|Korean]]: '
	-- 		end
	--     	result = p._prep_label(result, label, args, i)
	    	
 --   		-- hangul insertion
	--     	table.insert(result, hangul)
	    	
	--     	-- hangul ref insertion
	--     	if args['hangulref'] then table.insert(result, args['hangulref']) end
 --   	end
    	
	--     -- hanja processing
	--     if c == 'z' then
	--     	if args['links'] == 'no' then
	--     		if args['context'] == 'nk' then label = 'Hancha: ' else label = 'Hanja: ' end
 --   		else
 --   			if args['context'] == 'nk' then label = '[[Hanja|Hancha]]: ' else label = '[[Hanja]]: ' end
	-- 		end
	--     	result = p._prep_label(result, label, args, i)
	--     	table.insert(result, hanja)
	--     	if args['hanjaref'] then table.insert(result, args['hanjaref']) end
 --   	end
    	
 --   	-- rr processing
	--     if c == 'r' then
	--     	if args['links'] == 'no' then
	--     		label = 'RR: '
 --   		else
 --   			label = '[[Revised Romanization of Korean|RR]]: '
	-- 		end
	--     	result = p._prep_label(result, label, args, i)
	--     	table.insert(result, rr_out)
 --   	end

 --   	-- mr processing
	--     if c == 'm' then
	--     	if args['links'] == 'no' then
	--     		label = 'MR: '
 --   		else
 --   			label = '[[McCune–Reischauer|MR]]: '
	-- 		end
	--     	result = p._prep_label(result, label, args, i)
	--     	table.insert(result, mr_out)
 --   	end
    	
	-- 	-- ipa processing
 --   	if c == 'i' then
	-- 		label = '<span style="font-size:85%;">lit.</span> '
	-- 		result = p._prep_label(result, label, args, i)
	-- 		table.insert(result, args['lit'])
 --   	end
    	
 --   	-- literal translation processing
 --   	if c == 'l' then
	-- 		label = '<span style="font-size:85%;">lit.</span> '
	-- 		result = p._prep_label(result, label, args, i)
	-- 		table.insert(result, args['lit'])
 --   	end
	
	--     -- add semicolon
	--     if i < #order then
	--     	if not (args['out'] == 'yes' and i == 1) then
	--     		table.insert(result, '; ')
 --   		end
 --   	end
	--     -- add parentheses if needed 
	-- 	if (i == 1 and args['out'] == 'yes') then table.insert(result, ' (') end
	-- 	if (i == #order and args['out'] == 'yes') then table.insert(result, ')') end
	-- end
	-- return unpack(result)
end

-- common label prepping to make loop more readable
function p._prep_label(result, label, args, i)
	if args['labels'] ~= 'no' then
		-- labels for every case except for optional first term outside parentheses
		if (args['out'] ~= 'yes') or (args['out'] == 'yes' and i > 1) then
			table.insert(result, label)
		end
	end
	return result
end

-- function to generate error message
function p.format_error(message)
	local result = {
		'<span class="error"><code style="color:inherit; border:inherit; padding:inherit;">{{Korean}} error. ',
		message,
		' ([[Template:Korean|Help]])</code></span>',
		'[[Category:Korean template errors]]'
	}
	return table.concat(result)
end

return p