モジュール:ko-pron

出典: フリー多機能辞典『ウィクショナリー日本語版(Wiktionary)』
ナビゲーションに移動 検索に移動

このモジュールについての説明文ページを モジュール:ko-pron/doc に作成できます

local export = {}

local m_IPA = require("モジュール:IPA")
local lang = require("モジュール:languages").getByCode("ko")

local gsub = mw.ustring.gsub
local match = mw.ustring.match
local sub = mw.ustring.sub
local char = mw.ustring.char
local codep = mw.ustring.codepoint

function export.revised(frame)
	local word = frame.args[1] or ''
	local convtype = frame.args[2] or 'rr'
	local nn = frame.args["nn"] or 'no'
	local rr = frame.args["rr"] or ''
	local ph = frame.args["ph"] or ''
	local ph2 = ''
	local ipa = frame.args["ipa"] or ''
	local mr = frame.args["mr"] or ''
	local yr = frame.args["yr"] or ''
	local rrr = frame.args["rrr"] or ''
	local long = frame.args["l"] or ''
	local com = frame.args["com"] or ''
	local cap = frame.args["cap"] or 'no'
	local ui = frame.args["ui"] or ''
	local nobc = frame.args["nobc"] or ''
	local ni = frame.args["ni"] or ''
	local bcred = frame.args["bcred"] or ''
	local svar = frame.args["svar"] or ''
	local iot = frame.args["iot"] or ''
	local yeored = frame.args["yeored"] or ''
	local pron2 = {}
	local wordpron = {}
	local varpron = ''
	local convtext = ''
	local initial = {}
	local vowel = {}
	local final = {}
	local syllable = {}
	local conv = {}
	local syllableindex = {}
	
	wordlen = mw.ustring.len(word)
	for i = 1,wordlen,1 do
		syllable[i] = sub(word,i,i)
		pron2[i] = syllable[i]
		if gsub(syllable[i],'[가-힣]','') == '' then
			syllableindex[i] = codep(syllable[i])- 0xAC00
			initial[i] = char(0x1100 + math.floor(syllableindex[i] / 588))
			vowel[i] = char(0x1161 + math.floor((syllableindex[i] % 588) / 28))
			final[i] = syllableindex[i] % 28
			if final[i] == 0 then
				final[i] = ''
			else
				final[i] = char(0x11A7 + final[i])
			end
		else
			initial[i],vowel[i],final[i]='','',''
		end
		if nobc ~= '' then
			if i == tonumber(nobc) then
				varpron = 'y'
				if final[i] == 'ᆺ' then
					pron2[i] = char(syllableindex[i] + 0xAC00 - 19)
				elseif final[i] == 'ᆻ' then
					pron2[i] = char(syllableindex[i] + 0xAC00 - 20)
				end
			end
			if i == tonumber(nobc) + 1 then
				if match(initial[i],'[ᄀᄃᄇᄉᄌ]') then
					pron2[i] = char(syllableindex[i] + 0xAC00 + 588)
				end
			end
		end
		if i == tonumber(svar) then
			varpron = 'y'
			pron2[i] = char(syllableindex[i] + 0xAC00 - 12)
		end
		if syllable[i] == '의' then
			if tonumber(ui) == i then
				varpron = 'y'
				pron2[i] = char(syllableindex[i] + 0xAC00 + 28)
			end
		end
		if syllable[i] == '어' and tonumber(iot) == i then
			varpron = 'y'
			pron2[i] = char(syllableindex[i] + 0xAC00 + 56)
		end
		if vowel[i] == 'ᅨ' then
			if initial[i] ~= 'ᄋ' then
				varpron = 'y'
				pron2[i] = char(syllableindex[i] + 0xAC00 - 56)
			end
		end
		if vowel[i] == 'ᅬ' then
			varpron = 'y'
			pron2[i] = char(syllableindex[i] + 0xAC00 + 112)
		end
	end
	syllable[wordlen+1],initial[wordlen+1],vowel[wordlen+1],final[wordlen+1]='','','',''

	if convtype == 'rr' then
		if rr == '' then
			for i = 1,wordlen,1 do
				if i == tonumber(bcred) then
					final[i] = gsub(final[i],'[ᆪᆹᆽᆾᆺᇀ]',{['ᆪ']='ᆨ',['ᆹ']='ᆸ',['ᆽ']='ᆮ',['ᆾ']='ᆮ',['ᆺ']='ᆮ',['ᇀ']='ᆮ'})
				end
				if ni ~= '' then
					if i + 1 == tonumber(ni) then
						initial[i+1] = 'ᄂ'
					end
				end
				if vowel[i+1] ~= '' then
					if gsub((final[i] .. syllable[i+1]),'[ᇀᆴ][이히]','') == '' then
						final[i] = 'ᆾ'
					end
					if gsub((final[i] .. syllable[i+1]),'ᆮ[이히]','') == '' then
						final[i] = gsub(syllable[i+1],'[이히]',{['이']='ᆽ',['히']='ᆾ'})
					end
					if gsub((final[i] .. initial[i+1]),'ᆺᄋ','') == '' then
						if gsub(syllable[i+1],'[이아어은으음읍을었았에]','') ~= '' then
							final[i] = 'ᆮ'
						end
					end
				end
				if initial[i+1] == 'ᄋ' then
					final[i] = gsub(final[i],'[ᆨᆩᆪᆬᆭᆮᆯᆰᆱᆲᆳᆴᆵᆶᆸᆹᆺᆻᆼᆽᆾᇂ]',{['ᆨ']='g',['ᆩ']='kk',['ᆪ']='ks',['ᆬ']='nj',['ᆭ']='n',['ᆮ']='d',['ᆯ']='r',['ᆰ']='lg',['ᆱ']='lm',['ᆲ']='lb',['ᆳ']='ls',['ᆴ']='lt',['ᆵ']='lp',['ᆶ']='r',['ᆸ']='b',['ᆹ']='ps',['ᆺ']='s',['ᆻ']='ss',['ᆼ']='ng-',['ᆽ']='j',['ᆾ']='ch',['ᇂ']=''})
				elseif syllable[i] == '밟' then
					final[i] = 'ᆸ'
				end
				if final[i] == 'ᆭ' then
					initial[i+1] = gsub(initial[i+1],'[ᄀᄁᄃᄄᄅᄇᄈᄌᄍ]',{['ᄀ']='k',['ᄁ']='k',['ᄃ']='t',['ᄄ']='t',['ᄅ']='n',['ᄇ']='p',['ᄈ']='p',['ᄌ']='ch',['ᄍ']='ch'})
				end	
				if final[i] == 'ᆶ' then
					initial[i+1] = gsub(initial[i+1],'[ᄀᄁᄂᄃᄄᄅᄇᄈᄌᄍ]',{['ᄀ']='k',['ᄁ']='k',['ᄂ']='l',['ᄃ']='t',['ᄄ']='t',['ᄅ']='l',['ᄇ']='p',['ᄈ']='p',['ᄌ']='ch',['ᄍ']='ch'})
				end
				if final[i] == 'ᇂ' then
					initial[i+1] = gsub(initial[i+1],'[ᄀᄁᄂᄃᄄᄅᄆᄇᄈᄌᄍ]',{['ᄀ']='k',['ᄁ']='k',['ᄂ']='nn',['ᄃ']='t',['ᄄ']='t',['ᄅ']='nn',['ᄆ']='nm',['ᄇ']='p',['ᄈ']='p',['ᄌ']='ch',['ᄍ']='ch'})
					if initial[i+1] == 'ᄎ' then
						final[i] = 't'
					end
				end
				if initial[i+1] == 'ᄂ' then
					if match(final[i],'[ᆯᆲᆴᆶ]') then
						final[i] = 'l'
						initial[i+1] = 'l'
					else
						final[i] = gsub(final[i],'[ᆨᆩᆪᆫᆬᆭᆮᆰᆱᆵᆷᆸᆹᆺᆻᆼᆽᆾᆿᇀᇁᇂ]',{['ᆨ']='ng',['ᆩ']='ng',['ᆪ']='ng',['ᆫ']='n',['ᆬ']='n',['ᆭ']='n',['ᆮ']='n',['ᆰ']='ng',['ᆱ']='m',['ᆵ']='m',['ᆷ']='m',['ᆸ']='m',['ᆹ']='m',['ᆺ']='n',['ᆻ']='n',['ᆼ']='ng',['ᆽ']='n',['ᆾ']='n',['ᆿ']='ng',['ᇀ']='n',['ᇁ']='m',['ᇂ']='n'})
					end
				end
				if initial[i+1] == 'ᄅ' then
					if final[i] == 'ᆫ' then
						if nn ~= 'y' then
							final[i] = 'l'
							initial[i+1] = 'l'
						else
							initial[i+1] = 'n'
						end
					elseif match(final[i],'[ᆯᆲᆴ]') then
						final[i] = 'l'
						initial[i+1] = 'l'
					else
						final[i] = gsub(final[i],'[ᆨᆩᆪᆬᆮᆰᆱᆵᆷᆸᆹᆺᆻᆼᆽᆾᆿᇀᇁ]',{['ᆨ']='ng',['ᆩ']='ng',['ᆪ']='ng',['ᆬ']='n',['ᆮ']='n',['ᆰ']='ng',['ᆱ']='m',['ᆵ']='m',['ᆷ']='m',['ᆸ']='m',['ᆹ']='m',['ᆺ']='n',['ᆻ']='n',['ᆼ']='ng',['ᆽ']='n',['ᆾ']='n',['ᆿ']='ng',['ᇀ']='n',['ᇁ']='m'})
						if final[i] ~= '' then
							initial[i+1] = 'n'
						end
					end
				end
				if initial[i+1] == 'ᄆ' then
					final[i] = gsub(final[i],'[ᆨᆩᆪᆮᆰᆵᆸᆹᆺᆻᆽᆾᆿᇀᇁ]',{['ᆨ']='ng',['ᆩ']='ng',['ᆪ']='ng',['ᆮ']='n',['ᆰ']='ng',['ᆵ']='m',['ᆸ']='m',['ᆹ']='m',['ᆺ']='n',['ᆻ']='n',['ᆽ']='n',['ᆾ']='n',['ᆿ']='ng',['ᇀ']='n',['ᇁ']='m'})
				end
				if final[i] == 'ᆰ' then
					if match(initial[i+1],'[ᄀᄁᄏ]') then
						final[i] = 'l'
					elseif initial[i+1] == 'ᄒ' then
						final[i] = 'l'
						initial[i+1] = 'k'
					end
				end
				if (final[i] .. initial[i+1]) == 'ᆫᄀ' then
					final[i] = 'n-'
				end
				if (final[i] .. initial[i+1]) == 'ᆽᄒ' then
					final[i] = 'c'
				end
				if (final[i] .. initial[i+1]) == 'ᆬᄒ' then
					final[i] = 'nc'
				end
				if (final[i] .. initial[i+1]) == 'ᆲᄒ' then
					final[i] = 'lp'
				end
				if vowel[i] ~= '' then
					if (final[i] .. initial[i+1]) == 'ᄋ' then
						final[i] = '…'
					end
				end
				final[i] = gsub(final[i],'[ᆨᆩᆪᆫᆬᆭᆮᆯᆰᆱᆲᆳᆴᆵᆶᆷᆸᆹᆺᆻᆼᆽᆾᆿᇀᇁᇂ]',{['ᆨ']='k',['ᆩ']='k',['ᆪ']='k',['ᆫ']='n',['ᆬ']='n',['ᆭ']='n',['ᆮ']='t',['ᆯ']='l',['ᆰ']='k',['ᆱ']='m',['ᆲ']='l',['ᆳ']='l',['ᆴ']='l',['ᆵ']='p',['ᆶ']='l',['ᆷ']='m',['ᆸ']='p',['ᆹ']='p',['ᆺ']='t',['ᆻ']='t',['ᆼ']='ng',['ᆽ']='t',['ᆾ']='t',['ᆿ']='k',['ᇀ']='t',['ᇁ']='p',['ᇂ']=''})
				initial[i] = gsub(initial[i],'[ᄀᄁᄂᄃᄄᄅᄆᄇᄈᄉᄊᄋᄌᄍᄎᄏᄐᄑᄒ]',{['ᄀ']='g',['ᄁ']='kk',['ᄂ']='n',['ᄃ']='d',['ᄄ']='tt',['ᄅ']='r',['ᄆ']='m',['ᄇ']='b',['ᄈ']='pp',['ᄉ']='s',['ᄊ']='ss',['ᄋ']='',['ᄌ']='j',['ᄍ']='jj',['ᄎ']='ch',['ᄏ']='k',['ᄐ']='t',['ᄑ']='p',['ᄒ']='h'})
				vowel[i] = gsub(vowel[i],'[ᅡᅢᅣᅤᅥᅦᅧᅨᅩᅪᅫᅬᅭᅮᅯᅰᅱᅲᅳᅴᅵ]',{['ᅡ']='a',['ᅢ']='ae',['ᅣ']='ya',['ᅤ']='yae',['ᅥ']='eo',['ᅦ']='e',['ᅧ']='yeo',['ᅨ']='ye',['ᅩ']='o',['ᅪ']='wa',['ᅫ']='wae',['ᅬ']='oe',['ᅭ']='yo',['ᅮ']='u',['ᅯ']='wo',['ᅰ']='we',['ᅱ']='wi',['ᅲ']='yu',['ᅳ']='eu',['ᅴ']='ui',['ᅵ']='i'})
				if i == tonumber(ni) then
					initial[i] = '<sup>' .. initial[i] .. '</sup>'
				end
				conv[i] = initial[i] .. vowel[i] .. final[i]
				if conv[i] == '' then
					if syllable[i] ~= '' then
						conv[i] = syllable[i]
					end
				end
			end
			rr = table.concat(conv,"")
			rr = gsub(gsub(gsub(gsub(gsub(gsub(rr,'o…e','o~e'),'e…([ou])','e~%1'),'a…e','a~e'),'u…i','u~i'),'…',''),'~','-')
		end
		convtext = rr

	elseif convtype == 'mr' then
		if mr == "" then
			for i = 1,wordlen,1 do
				if i == tonumber(bcred) then
					final[i] = gsub(final[i],'[ᆪᆹᆽᆾᆺᇀ]',{['ᆪ']='ᆨ',['ᆹ']='ᆸ',['ᆽ']='ᆮ',['ᆾ']='ᆮ',['ᆺ']='ᆮ',['ᇀ']='ᆮ'})
				end
				if ni ~= '' then
					if i + 1 == tonumber(ni) then
						initial[i+1] = 'ᄂ'
					end
				end
				if vowel[i+1] ~= "" then
					if gsub((final[i] .. syllable[i+1]),'[ᇀᆴ][이히]','') == '' then
						final[i] = 'ᆾ'
					end
					if gsub((final[i] .. syllable[i+1]),'ᆮ[이히]','') == '' then
						final[i] = gsub(syllable[i+1],'[이히]',{['이']='ᆽ',['히']='ᆾ'})
					end
					if gsub((final[i] .. initial[i+1]),"ᆺᄋ","") == "" then
						if gsub(syllable[i+1],"[이아어은으음읍을었았]","") ~= "" then
							final[i] = "ᆮ"
						end
					end
				end
				if initial[i+1] == "ᄋ" then
					final[i] = gsub(final[i],"[ᆨᆩᆪᆬᆭᆮᆯᆰᆱᆲᆳᆴᆵᆶᆸᆹᆺᆻᆼᆽᆾᇂᆿᇀᇁ]",{["ᆨ"]="g",["ᆩ"]="kk",["ᆪ"]="ks",["ᆬ"]="nj",["ᆭ"]="n",["ᆮ"]="d",["ᆯ"]="r",["ᆰ"]="lg",["ᆱ"]="lm",["ᆲ"]="lb",["ᆳ"]="ls",["ᆴ"]="lt",["ᆵ"]="lp",["ᆶ"]="r",["ᆸ"]="b",["ᆹ"]="ps",["ᆺ"]="s",["ᆻ"]="ss",["ᆼ"]="ng",["ᆽ"]="j",["ᆾ"]="ch",["ᇂ"]="",["ᆿ"]="k'",["ᇀ"]="t'",["ᇁ"]="p'"})
				elseif syllable[i] == "밟" then
					final[i] = "ᆸ"
				end
				if final[i] == "ᆭ" then
					initial[i+1] = gsub(initial[i+1],"[ᄀᄁᄃᄄᄅᄇᄈᄌᄍ]",{["ᄀ"]="k'",["ᄁ"]="k'",["ᄃ"]="t'",["ᄄ"]="t'",["ᄅ"]="n",["ᄇ"]="p'",["ᄈ"]="p'",["ᄌ"]="ch'",["ᄍ"]="ch'"})
				end	
				if final[i] == "ᆶ" then
					initial[i+1] = gsub(initial[i+1],"[ᄀᄁᄂᄃᄄᄅᄇᄈᄌᄍ]",{["ᄀ"]="k'",["ᄁ"]="k'",["ᄂ"]="l",["ᄃ"]="t'",["ᄄ"]="t'",["ᄅ"]="l",["ᄇ"]="p'",["ᄈ"]="p'",["ᄌ"]="ch'",["ᄍ"]="ch'"})
				end
				if final[i] == "ᇂ" then
					initial[i+1] = gsub(initial[i+1],"[ᄀᄁᄂᄃᄄᄅᄆᄇᄈᄌᄍ]",{["ᄀ"]="k'",["ᄁ"]="k'",["ᄂ"]="nn",["ᄃ"]="t'",["ᄄ"]="t'",["ᄅ"]="nn",["ᄆ"]="nm",["ᄇ"]="p'",["ᄈ"]="p'",["ᄌ"]="ch'",["ᄍ"]="ch'"})
					if initial[i+1] == 'ᄎ' then
						final[i] = 't'
					end
				end
				if initial[i+1] == "ᄂ" then
					if match(final[i],"[ᆯᆲᆴᆶ]") then
						final[i] = "l"
						initial[i+1] = "l"
					else
						final[i] = gsub(final[i],"[ᆨᆩᆪᆫᆬᆭᆮᆰᆱᆵᆷᆸᆹᆺᆻᆼᆽᆾᆿᇀᇁᇂ]",{["ᆨ"]="ng",["ᆩ"]="ng",["ᆪ"]="ng",["ᆫ"]="n",["ᆬ"]="n",["ᆭ"]="n",["ᆮ"]="n",["ᆰ"]="ng",["ᆱ"]="m",["ᆵ"]="m",["ᆷ"]="m",["ᆸ"]="m",["ᆹ"]="m",["ᆺ"]="n",["ᆻ"]="n",["ᆼ"]="ng",["ᆽ"]="n",["ᆾ"]="n",["ᆿ"]="ng",["ᇀ"]="n",["ᇁ"]="m",["ᇂ"]="n"})
					end
				end
				if initial[i+1] == "ᄅ" then
					if final[i] == "ᆫ" then
						if nn ~= "y" then
							final[i] = "l"
							initial[i+1] = "l"
						else
							initial[i+1] = "n"
						end
					elseif match(final[i],"[ᆯᆲᆴ]") then
						final[i] = "l"
						initial[i+1] = "l"
					else
						final[i] = gsub(final[i],"[ᆨᆩᆪᆬᆮᆰᆱᆵᆷᆸᆹᆺᆻᆼᆽᆾᆿᇀᇁ]",{["ᆨ"]="ng",["ᆩ"]="ng",["ᆪ"]="ng",["ᆬ"]="n",["ᆮ"]="n",["ᆰ"]="ng",["ᆱ"]="m",["ᆵ"]="m",["ᆷ"]="m",["ᆸ"]="m",["ᆹ"]="m",["ᆺ"]="n",["ᆻ"]="n",["ᆼ"]="ng",["ᆽ"]="n",["ᆾ"]="n",["ᆿ"]="ng",["ᇀ"]="n",["ᇁ"]="m"})
						if final[i] ~= "" then
							initial[i+1] = "n"
						end
					end
				end
				if initial[i+1] == "ᄆ" then
					final[i] = gsub(final[i],"[ᆨᆩᆪᆮᆰᆵᆸᆹᆺᆻᆽᆾᆿᇀᇁ]",{["ᆨ"]="ng",["ᆩ"]="ng",["ᆪ"]="ng",["ᆮ"]="n",["ᆰ"]="ng",["ᆵ"]="m",["ᆸ"]="m",["ᆹ"]="m",["ᆺ"]="n",["ᆻ"]="n",["ᆽ"]="n",["ᆾ"]="n",["ᆿ"]="ng",["ᇀ"]="n",["ᇁ"]="m"})
				end
				if final[i] == "ᆰ" then
					if match(initial[i+1],"[ᄀᄁᄏ]") then
						final[i] = "l"
					elseif initial[i+1] == "ᄒ" then
						final[i] = "l"
						initial[i+1] = "k'"
					end
				end
				if (final[i] .. initial[i+1]) == "ᆫᄀ" then
					final[i] = "n'"
				end
				if (final[i] .. initial[i+1]) == "ᆽᄒ" then
					final[i] = "c"
					initial[i+1] = "h'"
				end
				if (final[i] .. initial[i+1]) == "ᆬᄒ" then
					final[i] = "nc"
					initial[i+1] = "h'"
				end
				if (final[i] .. initial[i+1]) == 'ᆲᄒ' then
					final[i] = "lp"
					initial[i+1] = "h'"
				end
				if match((final[i] .. initial[i+1]),"[ᆨᆩᆮᆸᆺᆻᆽᆾᆿᇀᇁ][ᄀᄁᄃᄄᄇᄈᄉᄊᄌᄍᄎᄏᄐᄑ]") then
					initial[i+1] = gsub(initial[i+1],"[ᄀᄃᄇᄌ]",{["ᄀ"]="k",["ᄃ"]="t",["ᄇ"]="p",["ᄌ"]="ch"})
				end
				final[i] = gsub(final[i],"[ᆨᆩᆪᆫᆬᆭᆮᆯᆰᆱᆲᆳᆴᆵᆶᆷᆸᆹᆺᆻᆼᆽᆾᆿᇀᇁᇂ]",{["ᆨ"]="k",["ᆩ"]="k",["ᆪ"]="k",["ᆫ"]="n",["ᆬ"]="n",["ᆭ"]="n",["ᆮ"]="t",["ᆯ"]="l",["ᆰ"]="k",["ᆱ"]="m",["ᆲ"]="l",["ᆳ"]="l",["ᆴ"]="l",["ᆵ"]="p",["ᆶ"]="l",["ᆷ"]="m",["ᆸ"]="p",["ᆹ"]="p",["ᆺ"]="t",["ᆻ"]="t",["ᆼ"]="ng",["ᆽ"]="t",["ᆾ"]="t",["ᆿ"]="k",["ᇀ"]="t",["ᇁ"]="p",["ᇂ"]=""})
				if i == 1 then
					initial[i] = gsub(initial[i],"[ᄀᄁᄂᄃᄄᄅᄆᄇᄈᄉᄊᄋᄌᄍᄎᄏᄐᄑᄒ]",{["ᄀ"]="k",["ᄁ"]="kk",["ᄂ"]="n",["ᄃ"]="t",["ᄄ"]="tt",["ᄅ"]="r",["ᄆ"]="m",["ᄇ"]="p",["ᄈ"]="pp",["ᄉ"]="s",["ᄊ"]="ss",["ᄋ"]="",["ᄌ"]="ch",["ᄍ"]="tch",["ᄎ"]="ch'",["ᄏ"]="k'",["ᄐ"]="t'",["ᄑ"]="p'",["ᄒ"]="h"})
				else
					initial[i] = gsub(initial[i],"[ᄀᄁᄂᄃᄄᄅᄆᄇᄈᄉᄊᄋᄌᄍᄎᄏᄐᄑᄒ]",{["ᄀ"]="g",["ᄁ"]="kk",["ᄂ"]="n",["ᄃ"]="d",["ᄄ"]="tt",["ᄅ"]="r",["ᄆ"]="m",["ᄇ"]="b",["ᄈ"]="pp",["ᄉ"]="s",["ᄊ"]="ss",["ᄋ"]="",["ᄌ"]="j",["ᄍ"]="tch",["ᄎ"]="ch'",["ᄏ"]="k'",["ᄐ"]="t'",["ᄑ"]="p'",["ᄒ"]="h"})
				end
				vowel[i] = gsub(vowel[i],"[ᅡᅢᅣᅤᅥᅦᅧᅨᅩᅪᅫᅬᅭᅮᅯᅰᅱᅲᅳᅴᅵ]",{["ᅡ"]="a",["ᅢ"]="ae",["ᅣ"]="ya",["ᅤ"]="yae",["ᅥ"]="ŏ",["ᅦ"]="e",["ᅧ"]="yŏ",["ᅨ"]="ye",["ᅩ"]="o",["ᅪ"]="wa",["ᅫ"]="wae",["ᅬ"]="oe",["ᅭ"]="yo",["ᅮ"]="u",["ᅯ"]="wŏ",["ᅰ"]="we",["ᅱ"]="wi",["ᅲ"]="yu",["ᅳ"]="ŭ",["ᅴ"]="ŭi",["ᅵ"]="i"})
				if i == tonumber(ni) then
					initial[i] = '<sup>' .. initial[i] .. '</sup>'
				end
				conv[i] = initial[i] .. vowel[i] .. final[i]
				if conv[i] == "" then
					if syllable[i] ~= "" then
						conv[i] = syllable[i]
					end
				end
			end
			mr = gsub(table.concat(conv,""),'swi','shwi')
		end
		convtext = mr

	elseif convtype == 'yr' then
		if yr == '' then
			for i = 1,wordlen,1 do
				if ni ~= '' then
					if i + 1 == tonumber(ni) then
						initial[i+1] = 'ᄂ'
					end
				end
				if vowel[i+1] ~= '' then
					if vowel[i] ~= '' then
						if initial[i+1] == 'ᄋ' then
							initial[i+1] = ''
							initial[i+1] = gsub(final[i],'[ᆨᆩᆪᆫᆬᆭᆮᆯᆰᆱᆲᆳᆴᆵᆶᆷᆸᆹᆺᆻᆼᆽᆾᆿᇀᇁᇂ]','.')
						elseif initial[i+1] == 'ᄒ' then
							if match(final[i],'[ᆨᆩᆪᆫᆬᆮᆯᆰᆱᆲᆴᆵᆸᆻᆽᆾᆿᇀᇁᇂ]') then
								initial[i+1] = '.ᄒ'
							end
						else
							if match(final[i]..initial[i+1],'[^ᆭᆶᆫᆯᆳᆷᆼᇂ][^ᄂᄅᄆᄁᄄᄈᄊᄍᄎᄏᄐᄑ]') and not match(final[i]..initial[i+1], 'ᆱᄃ') and final[i] ~= '' then
								final[i] = final[i] .. 'q'
							end
						end
					end
				end
				if vowel[i] == 'ᅮ' then
					if match(initial[i],'[ᄆᄇᄈᄑ]') then
						vowel[i] = 'ᅳ'
					end
				end
				if i == tonumber(com) then
					final[i] = final[i] .. 'q'
				end
				initial[i] = gsub(initial[i],'[ᄀᄁᄂᄃᄄᄅᄆᄇᄈᄉᄊᄌᄍᄎᄋᄏᄐᄑᄒ]',{['ᄀ']='k',['ᄁ']='kk',['ᄂ']='n',['ᄃ']='t',['ᄄ']='tt',['ᄅ']='l',['ᄆ']='m',['ᄇ']='p',['ᄈ']='pp',['ᄉ']='s',['ᄊ']='ss',['ᄌ']='c',['ᄍ']='cc',['ᄋ']='',['ᄎ']='ch',['ᄏ']='kh',['ᄐ']='th',['ᄑ']='ph',['ᄒ']='h'})
				vowel[i] = gsub(vowel[i],'[ᅡᅢᅣᅤᅥᅦᅧᅨᅩᅪᅫᅬᅭᅮᅯᅰᅱᅲᅳᅴᅵ]',{['ᅡ']='a',['ᅢ']='ay',['ᅣ']='ya',['ᅤ']='yay',['ᅥ']='e',['ᅦ']='ey',['ᅧ']='ye',['ᅨ']='yey',['ᅩ']='o',['ᅪ']='wa',['ᅫ']='way',['ᅬ']='oy',['ᅭ']='yo',['ᅮ']='wu',['ᅯ']='we',['ᅰ']='wey',['ᅱ']='wi',['ᅲ']='yu',['ᅳ']='u',['ᅴ']='uy',['ᅵ']='i'})
				final[i] = gsub(final[i],'[ᆨᆩᆪᆫᆬᆭᆮᆯᆰᆱᆲᆳᆴᆵᆶᆷᆸᆹᆺᆻᆼᆽᆾᆿᇀᇁᇂ]',{['ᆨ']='k',['ᆩ']='kk',['ᆪ']='ks',['ᆫ']='n',['ᆬ']='nc',['ᆭ']='nh',['ᆮ']='t',['ᆯ']='l',['ᆰ']='lk',['ᆱ']='lm',['ᆲ']='lp',['ᆳ']='ls',['ᆴ']='lth',['ᆵ']='lph',['ᆶ']='lh',['ᆷ']='m',['ᆸ']='p',['ᆹ']='ps',['ᆺ']='s',['ᆻ']='ss',['ᆼ']='ng',['ᆽ']='c',['ᆾ']='ch',['ᆿ']='kh',['ᇀ']='th',['ᇁ']='ph',['ᇂ']='h'})
				if i == tonumber(ni) then
					initial[i] = '<sup>' .. initial[i] .. '</sup>'
				end
				if tonumber(com) == 0 and i == 1 then
					initial[i] = 'q' .. initial[i]
				end
				conv[i] = initial[i] .. vowel[i] .. final[i]
				if conv[i] == '' then
					conv[i] = syllable[i]
				end
			end
			if long ~= '' then
				conv[1] = gsub(conv[1],'[aeiou]',{['a']='ā',['e']='ē',['i']='ī',['o']='ō',['u']='ū'})
			end
			yr = table.concat(conv,"")
		end
		convtext = yr
		
	elseif convtype == 'rrr' then
		if rrr == '' then
			for i = 1,wordlen,1 do
				if ni ~= '' then
					if i + 1 == tonumber(ni) then
						initial[i+1] = 'ᄂ'
					end
				end
				if vowel[i+1] ~= '' then
					if vowel[i] ~= '' then
						if initial[i+1] == 'ᄋ' then
							initial[i+1] = ''
							initial[i+1] = gsub(final[i],'[ᆨᆩᆪᆫᆬᆭᆮᆯᆰᆱᆲᆳᆴᆵᆶᆷᆸᆹᆺᆻᆼᆽᆾᆿᇀᇁᇂ]','-')
						elseif initial[i+1] == 'ᄒ' then
							if match(final[i],'[ᆨᆩᆪᆫᆬᆮᆯᆰᆱᆲᆴᆵᆸᆻᆽᆾᆿᇀᇁᇂ]') then
								initial[i+1] = '-ᄒ'
							end
						end
					end
				end
				if vowel[i] ~= '' then
					if (final[i] .. initial[i+1]) == 'ᄋ' then
						final[i] = '…'
					end
				end
				initial[i] = gsub(initial[i],'[ᄀᄁᄂᄃᄄᄅᄆᄇᄈᄉᄊᄌᄍᄎᄋᄏᄐᄑᄒ]',{['ᄀ']='g',['ᄁ']='kk',['ᄂ']='n',['ᄃ']='d',['ᄄ']='tt',['ᄅ']='l',['ᄆ']='m',['ᄇ']='b',['ᄈ']='pp',['ᄉ']='s',['ᄊ']='ss',['ᄌ']='j',['ᄍ']='jj',['ᄋ']='',['ᄎ']='ch',['ᄏ']='k',['ᄐ']='t',['ᄑ']='p',['ᄒ']='h'})
				vowel[i] = gsub(vowel[i],'[ᅡᅢᅣᅤᅥᅦᅧᅨᅩᅪᅫᅬᅭᅮᅯᅰᅱᅲᅳᅴᅵ]',{['ᅡ']='a',['ᅢ']='ae',['ᅣ']='ya',['ᅤ']='yae',['ᅥ']='eo',['ᅦ']='e',['ᅧ']='yeo',['ᅨ']='ye',['ᅩ']='o',['ᅪ']='wa',['ᅫ']='wae',['ᅬ']='oe',['ᅭ']='yo',['ᅮ']='u',['ᅯ']='wo',['ᅰ']='we',['ᅱ']='wi',['ᅲ']='yu',['ᅳ']='eu',['ᅴ']='ui',['ᅵ']='i'})
				final[i] = gsub(final[i],'[ᆨᆩᆪᆫᆬᆭᆮᆯᆰᆱᆲᆳᆴᆵᆶᆷᆸᆹᆺᆻᆼᆽᆾᆿᇀᇁᇂ]',{['ᆨ']='g',['ᆩ']='kk',['ᆪ']='gs',['ᆫ']='n',['ᆬ']='nj',['ᆭ']='nh',['ᆮ']='d',['ᆯ']='l',['ᆰ']='lg',['ᆱ']='lm',['ᆲ']='lb',['ᆳ']='ls',['ᆴ']='lt',['ᆵ']='lp',['ᆶ']='lh',['ᆷ']='m',['ᆸ']='b',['ᆹ']='bs',['ᆺ']='s',['ᆻ']='ss',['ᆼ']='ng',['ᆽ']='j',['ᆾ']='ch',['ᆿ']='k',['ᇀ']='t',['ᇁ']='p',['ᇂ']='h'})
				if i == tonumber(ni) then
					initial[i] = '<sup>' .. initial[i] .. '</sup>'
				end
				conv[i] = initial[i] .. vowel[i] .. final[i]
				if conv[i] == '' then
					conv[i] = syllable[i]
				end
			end
			if long ~= '' then
				conv[1] = gsub(conv[1],'[aeiou]',{['a']='ā',['e']='ē',['i']='ī',['o']='ō',['u']='ū'})
			end
			rrr = table.concat(conv,"")
			rrr = gsub(gsub(gsub(gsub(gsub(gsub(rrr,'o…e','o~e'),'e…([ou])','e~%1'),'a…e','a~e'),'u…i','u~i'),'…',''),'~','-')
		end
		convtext = rrr

	else
		if ph == '' then
			wordpron[1] = word
			wordpron[2] = ''
			if varpron ~= '' then
				wordpron[2] = table.concat(pron2,"")
				wordpron[3] = ''
			end
			for i = 1,2,1 do
				if wordpron[i] ~= '' then
					for j = 1,wordlen,1 do
						syllable[j] = sub(wordpron[i],j,j)
						if gsub(syllable[j],'[가-힣]','') == '' then
							syllableindex[j] = codep(syllable[j])- 0xAC00
							initial[j] = char(0x1100 + math.floor(syllableindex[j] / 588))
							vowel[j] = char(0x1161 + math.floor((syllableindex[j] % 588) / 28))
							final[j] = syllableindex[j] % 28
							if final[j] == 0 then
								final[j] = ''
							else
								final[j] = char(0x11A7 + final[j])
							end
						else
							initial[j],vowel[j],final[j]='','',''
						end
					end
					for j = 1,wordlen,1 do
						if vowel[j] == 'ᅴ' then
							if syllable[j] ~= '의' then
								vowel[j] = 'ᅵ'
							end
						end
						if j == tonumber(bcred) then
							final[j] = gsub(final[j],'[ᆪᆹᆽᆾᆺᇀ]',{['ᆪ']='ᆨ',['ᆹ']='ᆸ',['ᆽ']='ᆮ',['ᆾ']='ᆮ',['ᆺ']='ᆮ',['ᇀ']='ᆮ'})
						end
						if j == tonumber(yeored) then
							vowel[j] = 'ᅥ'
						end
						if ni ~= '' then
							if j + 1 == tonumber(ni) then
								initial[j+1] = 'ᄂ'
							end
						end
						if j == tonumber(com) then
							initial[j+1] = gsub(initial[j+1],'[ᄀᄃᄇᄉᄌ]',{['ᄀ']='ᄁ',['ᄃ']='ᄄ',['ᄇ']='ᄈ',['ᄉ']='ᄊ',['ᄌ']='ᄍ'})
						end
						if j - 1 == tonumber(com) then
							initial[j] = gsub(initial[j],'[ᄀᄃᄇᄉᄌ]',{['ᄀ']='ᄁ',['ᄃ']='ᄄ',['ᄇ']='ᄈ',['ᄉ']='ᄊ',['ᄌ']='ᄍ'})
						end
						if vowel[j+1] ~= '' then
							if gsub((final[j] .. syllable[j+1]),'[ᇀᆴ][이히]','') == '' then
								final[j] = 'ᆾ'
							end
							if gsub((final[j] .. syllable[j+1]),'ᆮ[이히]','') == '' then
								final[j] = gsub(syllable[j+1],'[이히]',{['이']='ᆽ',['히']='ᆾ'})
							end
							if gsub((final[j] .. initial[j+1]),'ᆺᄋ','') == '' then
								if gsub(syllable[j+1],'[이아어은으음읍을었았]','') ~= '' then
									final[j] = 'ᆮ'
								end
							end
						end
						if initial[j+1] == 'ᄋ' then
							if final[j] ~= '' then
								initial[j+1] = gsub(final[j],'[ᆨᆩᆪᆫᆬᆭᆮᆯᆰᆱᆲᆳᆴᆵᆶᆷᆸᆹᆺᆻᆼᆽᆾᆿᇀᇁᇂ]',{['ᆨ']='ᄀ',['ᆩ']='ᄁ',['ᆪ']='ᄊ',['ᆫ']='ᄂ',['ᆬ']='ᄌ',['ᆭ']='ᄂ',['ᆮ']='ᄃ',['ᆯ']='ᄅ',['ᆰ']='ᄀ',['ᆱ']='ᄆ',['ᆲ']='ᄇ',['ᆳ']='ᄊ',['ᆴ']='ᄐ',['ᆵ']='ᄑ',['ᆶ']='ᄅ',['ᆷ']='ᄆ',['ᆸ']='ᄇ',['ᆹ']='ᄊ',['ᆺ']='ᄉ',['ᆻ']='ᄊ',['ᆼ']='ᄋ',['ᆽ']='ᄌ',['ᆾ']='ᄎ',['ᆿ']='ᄏ',['ᇀ']='ᄐ',['ᇁ']='ᄑ',['ᇂ']='ᄋ'})
								final[j] = gsub(final[j],'[ᆨᆩᆪᆫᆬᆭᆮᆯᆰᆱᆲᆳᆴᆵᆶᆷᆸᆹᆺᆻᆼᆽᆾᆿᇀᇁᇂ]',{['ᆨ']='',['ᆩ']='',['ᆪ']='ᆨ',['ᆫ']='',['ᆬ']='ᆫ',['ᆭ']='',['ᆮ']='',['ᆯ']='',['ᆰ']='ᆯ',['ᆱ']='ᆯ',['ᆲ']='ᆯ',['ᆳ']='ᆯ',['ᆴ']='ᆯ',['ᆵ']='ᆯ',['ᆶ']='',['ᆷ']='',['ᆸ']='',['ᆹ']='ᆸ',['ᆺ']='',['ᆻ']='',['ᆽ']='',['ᆾ']='',['ᆿ']='',['ᇀ']='',['ᇁ']='',['ᇂ']=''})
							else
								initial[j+1] = 'ᄋ'
							end
						elseif syllable[j] == '밟' then
							final[j] = 'ᆸ'
						end
						if syllable[j] == '넓' then
							if match(initial[j+1],'[ᄌᄉ]') then
								final[j] = 'ᆸ'
							elseif initial[j+1] == 'ᄃ' then
								if match(syllable[j+1],'[다디]') then
								else
									final[j] = 'ᆸ'
								end
							end
						end
						if final[j] == 'ᆭ' then
							initial[j+1] = gsub(initial[j+1],'[ᄀᄁᄃᄄᄅᄇᄈᄌᄍᄉ]',{['ᄀ']='ᄏ',['ᄁ']='ᄏ',['ᄃ']='ᄐ',['ᄄ']='ᄐ',['ᄅ']='ᄂ',['ᄇ']='ᄑ',['ᄈ']='ᄑ',['ᄌ']='ᄎ',['ᄍ']='ᄎ',['ᄉ']='ᄊ'})
						end	
						if final[j] == 'ᆶ' then
							initial[j+1] = gsub(initial[j+1],'[ᄀᄁᄂᄃᄄᄅᄇᄈᄌᄍᄉ]',{['ᄀ']='ᄏ',['ᄁ']='ᄏ',['ᄂ']='ᆯ',['ᄃ']='ᄐ',['ᄄ']='ᄐ',['ᄅ']='ᄅ',['ᄇ']='ᄑ',['ᄈ']='ᄑ',['ᄌ']='ᄎ',['ᄍ']='ᄎ',['ᄉ']='ᄊ'})
						end
						if final[j] == 'ᇂ' then
							if match(initial[j+1],'[ᄂᄅᄆ]') then
								initial[j+1] = gsub(initial[j+1],'[ᄂᄅᄆ]',{['ᄂ']='ᄂ',['ᄅ']='ᄂ',['ᄆ']='ᄆ'})
								final[j] = gsub(initial[j+1],'[ᄂᄅᄆ]',{['ᄂ']='ᆫ',['ᄅ']='ᆫ',['ᄆ']='ᆷ'})
							elseif match(initial[j+1],'[ᄀᄁᄃᄄᄇᄈᄌᄍᄉ]') then
								initial[j+1] = gsub(initial[j+1],'[ᄀᄁᄃᄄᄇᄈᄌᄍᄉ]',{['ᄀ']='ᄏ',['ᄁ']='ᄏ',['ᄃ']='ᄐ',['ᄄ']='ᄐ',['ᄇ']='ᄑ',['ᄈ']='ᄑ',['ᄌ']='ᄎ',['ᄍ']='ᄎ',['ᄉ']='ᄊ'})
								final[j] = ''
							elseif initial[j+1] == 'ᄎ' then
								final[j] = 'ᆮ'
							end
						end
						if match(final[j],'[ᆬᆲᆴ]') then
							initial[j+1] = gsub(initial[j+1],'[ᄀᄃᄇᄉᄌ]',{['ᄀ']='ᄁ',['ᄃ']='ᄄ',['ᄇ']='ᄈ',['ᄉ']='ᄊ',['ᄌ']='ᄍ'})
						elseif match(final[j],'ᆱ') then
							initial[j+1] = gsub(initial[j+1],'ᄃ','ᄄ')
						end
						if initial[j+1] == 'ᄂ' then
							if match(final[j],'[ᆯᆲᆴᆶ]') then
								final[j] = 'ᆯ'
								initial[j+1] = 'ᄅ'
							else
								final[j] = gsub(final[j],'[ᆨᆩᆪᆫᆬᆭᆮᆰᆱᆵᆷᆸᆹᆺᆻᆼᆽᆾᆿᇀᇁᇂ]',{['ᆨ']='ᆼ',['ᆩ']='ᆼ',['ᆪ']='ᆼ',['ᆫ']='ᆫ',['ᆬ']='ᆫ',['ᆭ']='ᆫ',['ᆮ']='ᆫ',['ᆰ']='ᆼ',['ᆱ']='ᆷ',['ᆵ']='ᆷ',['ᆷ']='ᆷ',['ᆸ']='ᆷ',['ᆹ']='ᆷ',['ᆺ']='ᆫ',['ᆻ']='ᆫ',['ᆼ']='ᆼ',['ᆽ']='ᆫ',['ᆾ']='ᆫ',['ᆿ']='ᆼ',['ᇀ']='ᆫ',['ᇁ']='ᆷ',['ᇂ']='ᆫ'})
							end
						elseif initial[j+1] == 'ᄅ' then
							if final[j] == 'ᆫ' then
								if nn ~= 'y' then
									final[j] = 'ᆯ'
									initial[j+1] = 'ᄅ'
								else
									initial[j+1] = 'ᄂ'
								end
							elseif match(final[j],'[ᆯᆲᆴᆶ]') then
								final[j] = 'ᆯ'
								initial[j+1] = 'ᄅ'
							else
								final[j] = gsub(final[j],'[ᆨᆩᆪᆬᆮᆰᆱᆵᆷᆸᆹᆺᆻᆼᆽᆾᆿᇀᇁ]',{['ᆨ']='ᆼ',['ᆩ']='ᆼ',['ᆪ']='ᆼ',['ᆬ']='ᆫ',['ᆮ']='ᆫ',['ᆰ']='ᆼ',['ᆱ']='ᆷ',['ᆵ']='ᆷ',['ᆷ']='ᆷ',['ᆸ']='ᆷ',['ᆹ']='ᆷ',['ᆺ']='ᆫ',['ᆻ']='ᆫ',['ᆼ']='ᆼ',['ᆽ']='ᆫ',['ᆾ']='ᆫ',['ᆿ']='ᆼ',['ᇀ']='ᆫ',['ᇁ']='ᆷ'})
								if final[j] ~= '' then
									initial[j+1] = 'ᄂ'
								end
							end
						end
						if initial[j+1] == 'ᄆ' then
							final[j] = gsub(final[j],'[ᆨᆩᆪᆮᆰᆵᆸᆹᆺᆻᆽᆾᆿᇀᇁ]',{['ᆨ']='ᆼ',['ᆩ']='ᆼ',['ᆪ']='ᆼ',['ᆮ']='ᆫ',['ᆰ']='ᆼ',['ᆵ']='ᆷ',['ᆸ']='ᆷ',['ᆹ']='ᆷ',['ᆺ']='ᆫ',['ᆻ']='ᆫ',['ᆽ']='ᆫ',['ᆾ']='ᆫ',['ᆿ']='ᆼ',['ᇀ']='ᆫ',['ᇁ']='ᆷ'})
						end
						if final[j] == 'ᆰ' then
							if match(initial[j+1],'[ᄀᄁᄏ]') then
								final[j] = 'ᆯ'
								initial[j+1] = gsub(initial[j+1],'ᄀ','ᄁ')
							elseif initial[j+1] == 'ᄒ' then
								final[j] = 'ᆯ'
								initial[j+1] = 'ᄏ'
							end
						end
						if initial[j+1] == 'ᄒ' then
							if final[j] ~= '' then
								initial[j+1] = gsub(final[j],'[ᆨᆩᆪᆫᆬᆮᆯᆰᆱᆲᆳᆴᆵᆷᆸᆹᆺᆻᆼᆽᆾᆿᇀᇁ]',{['ᆨ']='ᄏ',['ᆩ']='ᄏ',['ᆪ']='ᄏ',['ᆫ']='ᄒ',['ᆬ']='ᄎ',['ᆮ']='ᄐ',['ᆯ']='ᄒ',['ᆰ']='ᄏ',['ᆱ']='ᄒ',['ᆲ']='ᄑ',['ᆴ']='ᄐ',['ᆵ']='ᄑ',['ᆷ']='ᄒ',['ᆸ']='ᄑ',['ᆹ']='ᄑ',['ᆺ']='ᄐ',['ᆻ']='ᄐ',['ᆼ']='ᄒ',['ᆽ']='ᄎ',['ᆾ']='ᄎ',['ᆿ']='ᄏ',['ᇀ']='ᄐ',['ᇁ']='ᄑ'})
								final[j] = gsub(final[j],'[ᆨᆩᆪᆬᆮᆰᆱᆲᆳᆴᆵᆷᆸᆹᆺᆻᆽᆾᆿᇀᇁ]',{['ᆨ']='',['ᆩ']='',['ᆪ']='',['ᆬ']='ᆫ',['ᆮ']='',['ᆰ']='ᆯ',['ᆱ']='ᆯ',['ᆲ']='ᆯ',['ᆴ']='ᆯ',['ᆵ']='ᆯ',['ᆷ']='ᆷ',['ᆸ']='',['ᆹ']='',['ᆺ']='',['ᆻ']='',['ᆽ']='',['ᆾ']='',['ᆿ']='',['ᇀ']='',['ᇁ']=''})
							else
								initial[j+1] = 'ᄒ'
							end
						end
						final[j] = gsub(final[j],'[ᆩᆪᆬᆭᆰᆱᆲᆳᆴᆵᆶᆷᆹᆺᆻᆽᆾᆿᇀᇁᇂ]',{['ᆩ']='ᆨ',['ᆪ']='ᆨ',['ᆬ']='ᆫ',['ᆭ']='ᆫ',['ᆰ']='ᆨ',['ᆱ']='ᆷ',['ᆲ']='ᆯ',['ᆳ']='ᆯ',['ᆴ']='ᆯ',['ᆵ']='ᆸ',['ᆶ']='ᆯ',['ᆷ']='ᆷ',['ᆹ']='ᆸ',['ᆺ']='ᆮ',['ᆻ']='ᆮ',['ᆽ']='ᆮ',['ᆾ']='ᆮ',['ᆿ']='ᆨ',['ᇀ']='ᆮ',['ᇁ']='ᆸ',['ᇂ']=''})
						if match((final[j] .. initial[j+1]),'[ᆨᆩᆮᆸᆺᆻᆽᆾᆿᇀᇁ][ᄀᄁᄃᄄᄇᄈᄉᄊᄌᄍᄎᄏᄐᄑ]') then
							final[j] = gsub(final[j],'[ᆩᆺᆻᆽᆾᆿᇀᇁ]',{['ᆩ']='ᆨ',['ᆺ']='ᆮ',['ᆻ']='ᆮ',['ᆽ']='ᆮ',['ᆾ']='ᆮ',['ᆿ']='ᆨ',['ᇀ']='ᆮ',['ᇁ']='ᆸ'})
							initial[j+1] = gsub(initial[j+1],'[ᄀᄃᄇᄉᄌ]',{['ᄀ']='ᄁ',['ᄃ']='ᄄ',['ᄇ']='ᄈ',['ᄉ']='ᄊ',['ᄌ']='ᄍ'})
						end
						conv[j] = initial[j] .. vowel[j] .. final[j]
						if conv[j] == '' then
							if syllable[j] ~= '' then
								conv[j] = syllable[j]
							end
						end
					end
					if long ~= '' then
						conv[1] = conv[1] .. ':'
					end
					if ph == '' then
						ph = table.concat(conv,"")
						convtext = ph
					else
						if svar ~= '' then
							i = tonumber(svar) + 1
							conv[i] = gsub(conv[i],'ᄃ','ᄉ')
						end
						ph2 = table.concat(conv,"")
						convtext = convtext .. '/' .. ph2
					end
				end
			end
		else
			convtext = ph
		end
		if convtype == 'ipa' then
			if ipa == '' then
				ipa = convtext
				ipa = gsub(ipa,'(.?)([ᄀᄃᄇᄌᄒ])',function(a,b)
					if a == '' or a == ' ' or a == '/' then
						return a..gsub(b,'.',{['ᄀ']='k',['ᄃ']='t',['ᄇ']='p',['ᄌ']='t͡ɕ',['ᄒ']='h'})
					end end)
				ipa = gsub(ipa,'[ᆨᆫᆮᆯᆷᆸᆼᄀᄁᄂᄃᄄᄅᄆᄇᄈᄉᄊᄋᄌᄍᄎᄏᄐᄑᄒ]',{['ᆨ']='k̚',['ᆫ']='n',['ᆮ']='t̚',['ᆯ']='ɭ',['ᆷ']='m',['ᆸ']='p̚',['ᆼ']='ŋ',['ᄀ']='ɡ',['ᄁ']='k͈',['ᄂ']='n',['ᄃ']='d',['ᄄ']='t͈',['ᄅ']='ɾ',['ᄆ']='m',['ᄇ']='b',['ᄈ']='p͈',['ᄉ']='sʰ',['ᄊ']='s͈',['ᄋ']='',['ᄌ']='d͡ʑ',['ᄍ']='t͡ɕ͈',['ᄎ']='t͡ɕʰ',['ᄏ']='kʰ',['ᄐ']='tʰ',['ᄑ']='pʰ',['ᄒ']='ɦ'})
				ipa = gsub(ipa,'[ᅡᅢᅣᅤᅥᅦᅧᅨᅩᅪᅫᅬᅭᅮᅯᅰᅱᅲᅳᅴᅵ]',{['ᅡ']='a̠',['ᅢ']='ɛ̝',['ᅣ']='ja̠',['ᅤ']='jɛ̝',['ᅥ']='ʌ̹',['ᅦ']='e̞',['ᅧ']='jʌ̹',['ᅨ']='je̞',['ᅩ']='o̞',['ᅪ']='wa̠',['ᅫ']='wɛ̝',['ᅬ']='ø̞',['ᅭ']='jo',['ᅮ']='u',['ᅯ']='wʌ̹',['ᅰ']='we̞',['ᅱ']='ɥi',['ᅲ']='ju',['ᅳ']='ɯ',['ᅴ']='ɰi',['ᅵ']='i'})
				ipa = gsub(ipa,':','ː')
				ipa = gsub(ipa,'([mnŋkptlɭ][̚]?)ː','ː%1')
				ipa = gsub(ipa,'ʌ̹ː','ɘː')
				ipa = gsub(ipa,'([kp])̚s','%1s')
				ipa = gsub(ipa,'ɭɾ','ɭɭ')
				ipa = gsub(ipa,'ɭɭ([ji])','ɭʎ%1')
				ipa = gsub(ipa,'s([͈]?)ʰɥi','ʃ%1ʰɥi')
				ipa = gsub(ipa,'s([ʰ͈])([ji])','ɕ%1%2')
				ipa = gsub(ipa,'/','/ ~ /')
				ipa = gsub(ipa,'ɭɦ','ɾɦ')
				ipa = gsub(gsub(ipa,'kʰ[ijɯ]',{['kʰi']='kçi',['kʰj']='kçj',['kʰɯ']='kxɯ'}),'nj','ɲj')
				ipa = gsub(ipa,'[hɦ][ijɯouw]',{['hi']='çi',['hj']='çj',['hɯ']='xɯ',['ho']='ɸʷo',['hu']='ɸʷu',['hw']='ɸw',['ɦi']='ʝi',['ɦj']='ʝj',['ɦɯ']='ɣɯ',['ɦo']='βo',['ɦu']='βu',['ɦw']='βw'})
				if match(ipa,'ɥi') then
					ipa = ipa .. '/ ~ /' .. gsub(ipa,'ɥi','y')
				end
				if long ~= '' then
					ipa = 'ˈ' .. gsub(ipa, '/ ~ /', '/ ~ /ˈ')
				end
			end
			local title = mw.title.getCurrentTitle().text
			local no_count = mw.ustring.match(title, " ")
			convtext = m_IPA.format_IPA_full(lang, {{pron = "/" .. ipa .. "/"}}, nil, nil, nil, no_count)
		end
	end
	if cap == 'y' then
		convtext = mw.ustring.upper(sub(convtext,1,1)) .. sub(convtext,2,-1)
	end
	if convtype == 'ph' then
		local result = {}
		for wd in mw.text.gsplit(mw.ustring.toNFC(mw.ustring.gsub(convtext, ":", "")), "/") do
			local words = {}
			for i = 1, mw.ustring.len(wd) do
				local syllable = mw.ustring.sub(wd, i, i)
				if syllable ~= mw.ustring.sub(word, i, i) then
					table.insert(words, '<span style="font-size:110%; color:#006600"><b>'..syllable..'</b></span>')
				else
					table.insert(words, '<span style="font-size:110%">'..syllable..'</span>')
				end
			end
			if long ~= '' then
				table.insert(words, 2, '<span style="font-size:110%; color:#006600"><b>:</b></span>')
			end
			table.insert(result, table.concat(words))
		end
		convtext = table.concat(result, "/")
	end
	return convtext
end

local m_ko_utilities = require("モジュール:ko")
local m_data = mw.loadData("モジュール:ko-pron/data")

local gsub = mw.ustring.gsub
local match = mw.ustring.match
local sub = mw.ustring.sub
local char = mw.ustring.char
local codepoint = mw.ustring.codepoint

local PAGENAME = mw.title.getCurrentTitle().text

local system_lookup = {
	["ph"] = 1, ["rr"] = 2, ["rrr"] = 3,
	["mr"] = 4, ["yr"] = 5, ["ipa"] = 6,
}

local question_mark = "<sup><small>[[Wiktionary:About Korean/Romanization|?]]</small></sup>"

local system_list = {
	{ 
		abbreviation = "ph", 
		display = "Phonetic hangeul: ", 
		separator = "/",
	},
	{ 
		abbreviation = "rr", 
		display = "Revised Romanization" .. question_mark, 
		separator = "/",
	},
	{ 
		abbreviation = "rrr", 
		display = "Revised Romanization (translit.)" .. question_mark, 
		separator = "/"
	},
	{ 
		abbreviation = "mc", 
		display = "McCune–Reischauer" .. question_mark,
		separator = "/"
	},
	{ 
		abbreviation = "yr", 
		display = "Yale Romanization" .. question_mark,
		separator = "/"
	},
	{ 
		abbreviation = "ipa", 
		display = "(<i>[[w:South Korean standard language|SK Standard]]/[[w:Seoul dialect|Seoul]]</i>) [[Wiktionary:International Phonetic Alphabet|IPA]]<sup>([[Appendix:Korean pronunciation|key]])</sup>: ", 
		separator = " ~ "
	}
}

--[[

vowel_variation:
	rules for vowel transformation.
	key:
		the number of a syllable's vowel (vowel_id):
			math.floor(((codepoint('가') - 0xAC00) % 588) / 28) = 0
			math.floor(((codepoint('개') - 0xAC00) % 588) / 28) = 1
	value:
		an integer that is added to the decimal codepoint of the syllable
				char(codepoint('개') + 112) = '게'

allowed_vowel_scheme:
	a list of which systems vowel transformation is reflected in.
	key:
		vowel_id .. "-" .. system_index
		system_index: see system_list above. IPA is #6
	value:
		1, representing true

]]

local final_syllable_conversion = { [""] = "Ø", ["X"] = "" }
local com_mc = { ["g"] = "k", ["d"] = "t", ["b"] = "p", ["j"] = "ch", ["sy"] = "s", ["s"] = "ss" }
local com_ph = { ["ᄀ"] = "ᄁ", ["ᄃ"] = "ᄄ", ["ᄇ"] = "ᄈ", ["ᄉ"] = "ᄊ", ["ᄌ"] = "ᄍ" }
local vowel_variation = {
	[1] = 112,  -- 개→게
	[3] = 112,  -- 걔→계
	[10] = 140, -- 괘→궤

	[7] = -56,  -- 계→게

	[11] = 112, -- 괴→궤
	[16] = 0,   -- 귀→귀
}
local allowed_vowel_scheme = {
	["1-1"] = 1,
	["1-6"] = 1,
	["3-1"] = 1,
	["3-6"] = 1,
	["10-1"] = 1,
	["10-6"] = 1,

	["7-1"] = 1,
	["7-6"] = 1,

	["11-1"] = 1,
	["11-6"] = 1,
	["16-6"] = 1,
}
local ambiguous_intersyllabic_rr = { ["oe"] = 1, ["eo"] = 1, ["eu"] = 1, ["ae"] = 1, ["ui"] = 1 }

local function decompose_syllable(word)
	local decomposed_syllables = {}
	for syllable in mw.text.gsplit(word, "") do
		table.insert(decomposed_syllables, m_ko_utilities.decompose_jamo(syllable))
	end
	return decomposed_syllables
end

local function tidy_phonetic(original, romanised)
	local j, k, w = 1, 1, {}
	for i = 1, mw.ustring.len(romanised) do
		local romanised_syllable = mw.ustring.sub(romanised, k, k)
		local original_syllable = mw.ustring.sub(original, j, j)
		if romanised_syllable ~= original_syllable then
			table.insert(w, '<b>'..romanised_syllable..'</b>')
			if match(original_syllable, "[^ː ]") then k = k + 1 end
			if match(romanised_syllable, "[^ː ]") then j = j + 1 end
		else
			table.insert(w, '<span>'..romanised_syllable..'</span>')
			j, k = j + 1, k + 1
		end
	end
	return table.concat(w)
end

local function tidy_ipa(ipa)
	ipa = gsub(ipa, "ʌ̹ː", "ɘː")
	ipa = gsub(ipa, "ɭɭ([ji])", "ʎʎ%1")
	ipa = gsub(ipa, "s([ʰ͈])ɥi" ,"ʃ%1ɥi")
	ipa = gsub(ipa, "ss͈([ji])" ,"ɕɕ͈%1")
	ipa = gsub(ipa, "s([ʰ͈])([ji])" ,"ɕ%1%2")
	ipa = gsub(ipa, "nj", "ɲj")
	ipa = gsub(ipa, "([ʑɕ])([ʰ͈]?)j", "%1%2")
	
	ipa = gsub(ipa, "kʰ[ijɯ]", { 
		["kʰi"] = "kçi", 
		["kʰj"] = "kçj", 
		["kʰɯ"] = "kxɯ" }
	)
	ipa = gsub(ipa, "[hɦ][ijɯouw]", {
		["hi"] = "çi",
		["hj"] = "çj",
		["hɯ"] = "xɯ",
		["ho"] = "ɸʷo",
		["hu"] = "ɸʷu",
		["hw"] = "ɸw",
		["ɦi"] = "ʝi",
		["ɦj"] = "ʝj",
		["ɦɯ"] = "ɣɯ",
		["ɦo"] = "βo",
		["ɦu"] = "βu",
		["ɦw"] = "βw" }
	)
	
	if match(ipa, "ɥi") then
		local midpoint = math.floor(mw.ustring.len(ipa) / 2)
		ipa = sub(ipa, 1, midpoint) .. gsub(sub(ipa, midpoint+1, -1), "ɥi", "y")
	end
	
	return ipa
end

function export.romanise(text_param, system_index, args)
	local p, optional_params = {}, { "nn", "l", "com", "cap", "ni" }
	for _, pm in ipairs(optional_params) do
		p[pm] = { }
		if args[pm] then
			for pp in mw.text.gsplit(args[pm], ",") do p[pm][tonumber(pp) or pp] = 1 end
		end
	end
		
	local vowel_ui_i, vowel_ui_e, no_batchim, batchim_reduce, s_variation, iotation, yeo_reduce = 
		args.ui, args.uie, args.nobc, args.bcred, args.svar, args.iot, args.yeored
	
	system_index = system_lookup[system_index] or system_index
	text_param = gsub(text_param, '[%-"](.)', "%1")
	
	for primitive_word in mw.ustring.gmatch(text_param, "[ᄀ-ᄒ".."ᅡ-ᅵ".."ᆨ-ᇂ" .. "ㄱ-ㆎ가-힣' ]+") do
		local the_original = primitive_word
		primitive_word = gsub(primitive_word, "'''", "ß")
		local bold_position, bold_count = {}, 0
		while match(primitive_word, "ß") do
			bold_position[(mw.ustring.find(primitive_word, "ß")) + bold_count] = true
			primitive_word = gsub(primitive_word, "ß", "", 1)
			bold_count = bold_count + 1
		end
		
		local has_vowel = {}
		for ch in mw.ustring.gmatch(primitive_word, ".") do
			local jungseong = math.floor(((codepoint(ch) - 0xAC00) % 588) / 28)
			if not match(ch, "[예옛례롄]") and match(ch, "[가-힣]") then has_vowel[jungseong] = true end
		end
		local word_set = { primitive_word }
		
		local function add_respelling(variable, modification, modification2)
			modification2 = modification2 or function(x) return x end
			if variable and match(system_index, "[16]") then
				variable = tonumber(variable)
				local pre_length = #word_set
				for i = 1, pre_length do
					local item = mw.text.split(word_set[i], "")
					item[variable] = modification(item[variable])
					item[variable + 1] = modification2(item[variable + 1])
					word_set[pre_length + i] = table.concat(item)
				end
			end
		end
		add_respelling(vowel_ui_i, function(x) return "이" end)
		add_respelling(vowel_ui_e, function(x) return "에" end)
		
		add_respelling(no_batchim, 
			function(x) return char(codepoint(x) - (codepoint(x) - 0xAC00) % 28) end, 
			function(y) return char(codepoint(y) + 588) end)
		
		add_respelling(s_variation, function(x) return char(codepoint(x) - 12) end)
		add_respelling(iotation, function(x) return char(codepoint(x) + 56) end)
		add_respelling(yeo_reduce, function(x) return char(codepoint(x) - 56) end)
		
		for vowel_id, vowel_variation_increment in pairs(vowel_variation) do
			if has_vowel[vowel_id] and allowed_vowel_scheme[vowel_id .. "-" .. system_index] then
				local pre_length = #word_set
				for i = 1, pre_length do
					local item = mw.text.split(word_set[i], "")
					for num, it in ipairs(item) do
						if math.floor(((codepoint(it) - 0xAC00) % 588) / 28) == vowel_id then
							item[num] = char(codepoint(it) + vowel_variation_increment)
						end
					end
					if vowel_id == 11 then
						table.insert(word_set, i, table.concat(item))
					else
						table.insert(word_set, table.concat(item))
					end
				end
			end
		end
		
		local word_set_romanisations = {}
		for _, respelling in ipairs(word_set) do
			local decomposed_syllables = decompose_syllable(respelling)
			local romanisation = {}
			local bold_insert_count = 0
			for index = 0, #decomposed_syllables, 1 do
				local this_syllable = index ~= 0 and sub(respelling, index, index) or ""
					local syllable = decomposed_syllables[index] or { initial = "Ø", vowel = "Ø", final = "X" }
					local next_syllable = decomposed_syllables[index + 1] or { initial = "Ø", vowel = "Ø", final = "Ø" }
					syllable.final = final_syllable_conversion[syllable.final] or syllable.final
					
					if system_index == 5 and syllable.vowel == "ᅮ" and match(syllable.initial, "[ᄆᄇᄈᄑ]") then
						syllable.vowel = "ᅳ"
					end
					
					if match(system_index, "[16]") then
						if syllable.vowel == "ᅴ" and this_syllable ~= "의" then
							syllable.vowel = "ᅵ"
						end
					end
					if match(system_index, "[1246]") then
						if this_syllable == "넓" then
							if match(next_syllable.initial, "[ᄌᄉ]") then
								syllable.final = "ᆸ"
								
							elseif next_syllable.initial == "ᄃ" then
								if match(next_syllable.vowel, "[^ᅡᅵ]") then
									syllable.final = "ᆸ"
								end
							end
						end
					end
					
					local vowel = m_data.vowels[syllable.vowel][system_index]
					
					if p.nn[index + 1] then
						next_syllable.initial = "ᄂ"
					end
					if p.com[index] and match(system_index, "[16]") then
						next_syllable.initial = com_ph[next_syllable.initial] or next_syllable.initial
					end
					
					if p.ni[index + 1] and system_index ~= 3 then
						next_syllable.initial = (system_index == 5 and syllable.final == "ᆯ") and "ᄅ" or "ᄂ"
					end
					
					if match(system_index, "[^35]") then
						if tonumber(batchim_reduce or -1) == index then
							syllable.final = m_data.boundary[syllable.final .. "-Ø"][1]
						end
					
						if index ~= 0 and this_syllable == "밟" then
							syllable.final = "ᆸ"
						end
						
						if match(syllable.final .. next_syllable.initial .. next_syllable.vowel, "[ᇀᆴ][ᄋᄒ]ᅵ") then
							syllable.final = "ᆾ"
						
						elseif match(syllable.final .. next_syllable.initial .. next_syllable.vowel, "ᆮ이") then
							syllable.final = "ᆽ"
						
						elseif match(syllable.final .. next_syllable.initial .. next_syllable.vowel, "ᆮ히") then
							syllable.final = "ᆾ"
						
						elseif syllable.final .. next_syllable.initial == "ᆺᄋ" and not
							match(sub(respelling, index+1, index+1), "[이아어은으음읍을었았있없에입의]") then
								syllable.final = "ᆮ"
						end
					end
					
					local bound = syllable.final .. "-" .. next_syllable.initial
					if not m_data.boundary[bound] then
						require("モジュール:debug").track("ko-pron/no boundary data")
						mw.log("No boundary data for " .. bound .. ".")
						return nil
					end
					local junction = m_data.boundary[bound][system_index]
					
					if bold_position[index + bold_insert_count + 1] and system_index == 2 then
						junction = gsub(junction, "^.*$", function(matched)
							local a, b = match(matched, "^(ng%-?)(.?)$")
							if not a or not b then a, b = match(matched, "^(.?%-?)(.*)$") end
							return match(syllable.final .. next_syllable.initial, "^Ø?[ᄀ-ᄒ]$")
								and "'''" .. (a or "") .. (b or "")
								or (a or "") .. "'''" .. (b or "") end)
							
						bold_insert_count = bold_insert_count + 1
					end
					
					if p.l[index] or (p.l["y"] and index == 1) then
						if system_index == 1 then
							if #junction == 0 then
								junction = junction .. "ː"
							else
								junction = gsub(junction, "^(.)(.?)$", function(a, b)
									return match(a, "[ᆨ-ᇂ]") and a .. "ː" .. b or "ː" .. a .. b end)
							end
							
						elseif system_index == 5 then
							vowel = gsub(vowel, "([aeiou])", "%1̄")
							
						elseif system_index == 6 then
							vowel = vowel .. "ː[[Category:Korean terms with long vowels in the first syllable]]"
						end
					end
					
					if (p.l["y"] or p.l[1]) and index == 0 and system_index == 6 and #decomposed_syllables > 1 then
						vowel = vowel .. "ˈ"
					end
				
					if p.com[index] then
						junction = gsub(junction, "(.)$", function(next_letter)
							return 
								(system_index == 5 and "q" or "") .. 
								(system_index == 4
									and (com_mc[next_letter..(p.cap["y"] or "")] or com_mc[next_letter] or next_letter)
									or next_letter) end)
					end
					
					if p.ni[index + 1] and system_index == 5 then
						junction = gsub(junction, "([nl])$", "<sup>%1</sup>")
					end
					
					table.insert(romanisation, vowel .. junction)
				end
			
			local temp_romanisation = table.concat(romanisation)
			if p.cap["y"] and match(system_index, "[^16]") then
				temp_romanisation = mw.ustring.upper(sub(temp_romanisation, 1, 1)) .. sub(temp_romanisation, 2, -1)
			end
			
			if system_index == 1 then
				temp_romanisation = tidy_phonetic(primitive_word, mw.ustring.toNFC(temp_romanisation))
			
			elseif match(system_index, "[23]") then
				for i = 1, 2 do
					temp_romanisation = gsub(temp_romanisation, "(.)…(.)", function(a, b)
						return a .. (ambiguous_intersyllabic_rr[a .. b] and "-" or "") .. b end)
				end
			
			elseif system_index == 4 then
				temp_romanisation = gsub(temp_romanisation, "swi", "shwi")

			elseif system_index == 6 then
				temp_romanisation = "[" .. temp_romanisation .. "]"
			end

			if match(system_index, "[16]") then
				temp_romanisation = mw.ustring.gsub(temp_romanisation, "ː", "(ː)")
			end
			
			table.insert(word_set_romanisations, temp_romanisation)
		end
		
		text_param = gsub(
			text_param, 
			the_original, 
			table.concat(word_set_romanisations, system_list[system_index].separator), 
			1
		)
	end

	if system_index == 6 then
		text_param = tidy_ipa(text_param)
	end
	
	return text_param
end

function export.make(frame, scheme)
	local params = {
		[1] = { default = PAGENAME, list = true },
		
		["a"] = {},
		["audio"] = { alias_of = "a" },
		
		["nn"] = {},
		["l"] = {},
		["com"] = {},
		["cap"] = {},
		["ui"] = {},
		["uie"] = {},
		["nobc"] = {},
		["ni"] = {},
		["bcred"] = {},
		["svar"] = {},
		["iot"] = {},
		["yeored"] = {},
	}
	
	local args = require("モジュール:parameters").process(frame:getParent().args, params)
	
	local results = {}
	for _, text_param in ipairs(args[1]) do
		local current_word_dataset = {}
		for system_index, system in pairs(system_list) do
			local romanised = export.romanise(text_param, system_index, args)
			table.insert(current_word_dataset, romanised)
		end
		table.insert(results, current_word_dataset)
	end
	
	local output_result = { [1] = {}, [2] = {}, [3] = {}, [4] = {}, [5] = {}, [6] = {} }
	for _, result in ipairs(results) do
		for result_index, value in ipairs(result) do
			table.insert(output_result[result_index], value)
		end
	end

	local html_ul = mw.html.create( "ul" )
	:done()
	local html_li_ipa = mw.html.create( "li" )
		:wikitext( system_list[6].display )
		:tag( "span" )
			:addClass( "IPA" )
			:wikitext( table.concat(output_result[6], system_list[6].separator) )
		:done()
	:done()
	local html_li_ph = mw.html.create( "li" )
		:addClass( "ko-pron__ph" )
		:wikitext( system_list[1].display )
		:tag( "span" )
			:addClass( "Kore" )
			:attr( "lang", "ko" )
			:wikitext( "[" .. table.concat(output_result[1], system_list[1].separator) .. "]" )
		:done()
	:done()

	if args.a then
		html_li_ipa
			:tag( "ul" )
				:tag( "li" )
					:wikitext( mw.getCurrentFrame():expandTemplate{ 
						title = "Template:audio", 
						args = { "ko", args.a == "y" and "Ko-" .. PAGENAME .. ".ogg" or args.a }} )
				:done()
			:done()
		:done()
	end

	if args.l then
		html_li_ph
			:tag( "ul" )
				:tag( "li" )
					:addClass( "ko-pron__note-vowel-length" )
					:wikitext( 'Though still prescriptive in Standard Korean, the great majority of speakers (in both Koreas) no longer distinguish vowel length.' )
				:done()
			:done()
		:done()
	end

	html_ul
		:node( html_li_ipa )
		:node( html_li_ph )
	:done()

	local html_table = mw.html.create( "table" )
		:addClass( "ko-pron" )
		:addClass( "mw-collapsible" )
		:addClass( "mw-collapsed" )
		:tag( "tr" )
			:tag( "th" )
				:attr( "colspan", 2 )
				:wikitext( "Romanizations" )
			:done()
		:done()
	:done()
		
	for roman_index = 2, 5 do
		html_table
			:tag( "tr" )
				:tag( "th" )
					:wikitext( system_list[roman_index].display )
				:done()
				:tag( "td" )
					:addClass( "IPA" )
					:wikitext( table.concat(output_result[roman_index], system_list[roman_index].separator) )
				:done()
			:done()
		:done()
	end
		
	return tostring(html_ul) .. tostring(html_table) .. require("モジュール:TemplateStyles")("Template:ko-IPA/style.css")
end

function export.make_hanja(frame, scheme)
	local params = {
		[1] = { list = true },

		["l"] = {},
	}

	local args = require("モジュール:parameters").process(frame:getParent().args, params)

	local results = {
		[1] = {},
		[6] = {},
	}
	for _, text_param in ipairs(args[1]) do
		for _, system_index in pairs({1, 6}) do
			local romanised = export.romanise(text_param, system_index, args)
			table.insert(results[system_index], romanised)
		end
	end

	local html_ul = mw.html.create( "ul" )
	:done()
	local html_li_ipa = mw.html.create( "li" )
		:wikitext( system_list[6].display )
		:tag( "span" )
			:addClass( "IPA" )
			:wikitext( table.concat(results[6], system_list[6].separator) )
		:done()
	:done()
	local html_li_ph = mw.html.create( "li" )
		:addClass( "ko-pron__ph" )
		:wikitext( system_list[1].display )
		:tag( "span" )
			:addClass( "Kore" )
			:attr( "lang", "ko" )
			:wikitext( "[" .. table.concat(results[1], system_list[1].separator) .. "]" )
		:done()
	:done()

	if args.l then
		html_li_ph
			:tag( "ul" )
				:tag( "li" )
					:addClass( "ko-pron__note-vowel-length" )
					:wikitext( 'Long vowel distinction only applies at the initial position. Most speakers no longer distinguish vowel length at any position.' )
				:done()
			:done()
		:done()
	end

	html_ul
		:node( html_li_ipa )
		:node( html_li_ph )
	:done()

	return tostring(html_ul) .. require("モジュール:TemplateStyles")("Template:ko-IPA/style.css")
end


return export