Module:User:Lunabunn/ko-translit

Hello, you have come here looking for the meaning of the word Module:User:Lunabunn/ko-translit. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:User:Lunabunn/ko-translit, but we will also tell you about its etymology, its characteristics and you will know how to say Module:User:Lunabunn/ko-translit in singular and plural. Everything you need to know about the word Module:User:Lunabunn/ko-translit you have here. The definition of the word Module:User:Lunabunn/ko-translit will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:User:Lunabunn/ko-translit, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

Language code in page name (User:Lunabunn/ko) not recognized.


local export = {}

local u = require("Module:string/char")
local urange = function (a, b) return u(a) .. "-" .. u(b) end
local data = mw.loadData("Module:User:Lunabunn/ko-translit/data")

local syllable_start = u(0xE000)
local syllable_end = u(0xE001)

local cho_range = urange(0x1100, 0x115F)
local jung_range = urange(0x1160, 0x11A7)
local jong_range = urange(0x11A8, 0x11FF)

local base = {
	{"ㅊ", "ch"},
	{"ㅋ", "kh"},
	{"ㅌ", "th"},
	{"ㅍ", "ph"},
	{"ㄱ", "k"},
	{"ㆁ", "ng"},
	{"ㄴ", "n"},
	{"ㄷ", "t"},
	{"ㄹ", "l"},
	{"ㅁ", "m"},
	{"ㅂ", "p"},
	{"ㅅ", "s"},
	{"ㅇ", "G"},
	{"ㅈ", "c"},
	{"ㅎ", "h"},
	{"ㅏ", "a"},
	{"ㅓ", "e"},
	{"ㅗ", "wo"},
	{"ㅜ", "wu"},
	{"ㅡ", "u"},
	{"ㅣ", "i"},
	{"ㆍ", "o"},
	{"@", "y"},
	{"ㅿ", "z"},
	{"ㆆ", "q"},
	{"ㅸ", "W"},
	{"ㅱ", "W"},
}


function export.raw(text)
	text = mw.ustring.toNFD(text)
	
	text = mw.ustring.gsub(text, "()", syllable_start .. "%1")
	text = mw.ustring.gsub(text, "()()", "%1" .. syllable_end .. "%2")
	text = mw.ustring.gsub(text, "()$", "%1" .. syllable_end)
	text = mw.ustring.gsub(text, "()", "%1" .. syllable_end)
	
	text = mw.ustring.gsub(text, ".", data.jamo_cho)
	text = mw.ustring.gsub(text, ".", data.jamo_jung)
	text = mw.ustring.gsub(text, ".", data.jamo_jong)
	
	for _, e in ipairs(base) do
		local k, v = e, e
		text = mw.ustring.gsub(text, k, v)
	end
	
	return text
end

function export.raw_swap(text)
	text = mw.ustring.gsub(
		text,
		syllable_start .. "(-)(-)(*)" .. syllable_end,
		function (cho, jung, jong)
			for _, e in ipairs(base) do
				local v, k = e, e
				cho = mw.ustring.gsub(cho, k, v)
				jung = mw.ustring.gsub(jung, k, v)
				jong = mw.ustring.gsub(jong, k, v)
			end
			cho = data.jamo_cho_swap
			jung = data.jamo_jung_swap
			if jong ~= "" then
				jong = data.jamo_jong_swap
			end
			return cho .. jung .. jong
		end
	)
	
	text = mw.ustring.toNFC(text)
	
	return text
end

function export.gsub(s, pattern, repl, init, n)
	local ss = syllable_start
	local se = syllable_end
	pattern = mw.ustring.gsub(pattern, "^%^%^", "%f" .. ss)
	pattern = mw.ustring.gsub(pattern, "^%^", ss)
	pattern = mw.ustring.gsub(pattern, "()%^", "%1" .. ss)
	pattern = mw.ustring.gsub(pattern, "%$", se)
	pattern = mw.ustring.gsub(pattern, "#", se .. "%(?ː?%)?" .. ss)
	if type(repl) == "string" then
		repl = mw.ustring.gsub(repl, "%^", ss)
		repl = mw.ustring.gsub(repl, "%$", se)
	end
	if init then
		return mw.ustring.sub(s, 1, init - 1) .. mw.ustring.gsub(mw.ustring.sub(s, init), pattern, repl, n)
	end
	return mw.ustring.gsub(s, pattern, repl, n)
end

function export.strip_separators(text)
	local stripped = mw.ustring.gsub(text, "", "")
	return stripped
end

function postprocess(text)
	text = text:gsub("%^" .. syllable_start .. "()", function (c) return syllable_start .. string.upper(c) end)
	return export.strip_separators(text)
end

function export.yale(text, coda_G_ng, wo_o)
	text = export.raw(text)
	text = export.gsub(text, "^G", "^")
	text = export.gsub(text, "G$", coda_G_ng and "ng$" or "G$")
	text = export.gsub(text, "wy?()", "w%1")
	text = export.gsub(text, "wo", wo_o and "o" or "wo")
	return postprocess(text)
end

function export.rr(text, translit)
	text = export.raw(text)
	-- consonants
	-- onset
	if translit then
		text = export.gsub(text, "p()", "b%1")
		text = export.gsub(text, "t()", "d%1")
		text = export.gsub(text, "k()", "g%1")
	else
		text = export.gsub(text, "^p()", "^b%1")
		text = export.gsub(text, "p(#)", "b%1")
		text = export.gsub(text, "^t()", "^d%1")
		text = export.gsub(text, "t(#)", "d%1")
		text = export.gsub(text, "^k()", "^g%1")
		text = export.gsub(text, "k(#)", "g%1")
		text = export.gsub(text, "h(#)b", "%1p")
		text = export.gsub(text, "h(#)d", "%1t")
		text = export.gsub(text, "h(#)g", "%1k")
	end
	text = export.gsub(text, "^l", "^r")
	text = export.gsub(text, "l(#)", "r%1")
	if translit then
		text = export.gsub(text, "(#)G", "%1'")
	end
	text = export.gsub(text, "^G", "^")
	text = export.gsub(text, "^cc", "jj")
	text = export.gsub(text, "^c()", "j%1")
	-- coda
	text = export.gsub(text, "kk$", "k$")
	text = export.gsub(text, "ss?$", "t$")
	text = export.gsub(text, "G", "ng")
	text = export.gsub(text, "ch?$", "t$")
	text = export.gsub(text, "h$", "t$")
	-- vowels
	-- monophthongs
	text = export.gsub(text, "o", "aw")
	text = export.gsub(text, "e", "eo")
	text = export.gsub(text, "waw", "o")
	text = export.gsub(text, "u", "eu")
	text = export.gsub(text, "weu", "u")
	-- diphthongs
	text = export.gsub(text, "ay", "ae")
	text = export.gsub(text, "eoy", "e")
	text = export.gsub(text, "oa", "wa")
	text = export.gsub(text, "oy", "oe")
	text = export.gsub(text, "ueo", "wo")
	text = export.gsub(text, "ue", "we")
	text = export.gsub(text, "euy", "ui")
	text = export.gsub(text, "uy", "wi")
	-- disambiguation
	if not translit then
		text = export.gsub(text, "ng(#)", "ng'%1")
		text = export.gsub(text, "e(#)u", "e'%1u")
		text = export.gsub(text, "n(#)g", "n'%1g")
	end
	return postprocess(text)
end

function export.okm_yale(text)
	return export.yale(text, false, false)
end

export.syllable_start = syllable_start
export.syllable_end = syllable_end

return export