Module:Ahom-translit

local export = {}
local gsub = mw.ustring.gsub
local u = mw.ustring.char
local con_cls = "([๐‘œ€-๐‘œš๐‘€-๐‘†][๐‘œ".."๐‘œž".."๐‘œŸ]?)"

-- see also https://www.unicode.org/L2/L2020/20258-add-tai-ahom.pdf
-- ๐‘œŠ represents both j and y
local tt = {
	-- consonants
	["๐‘œ€"] = "k", ["๐‘œ"] = "kh", ["๐‘œ‚"] = "แน…", ["๐‘œƒ"] = "n", ["๐‘œ„"] = "t", ["๐‘œ…"] = "t",
	["๐‘œ†"] = "p", ["๐‘œ‡"] = "ph", ["๐‘œˆ"] = "b", ["๐‘œ‰"] = "m", ["๐‘œŠ"] = "jสธ", ["๐‘œ‹"] = "ch",
	["๐‘œŒ"] = "th", ["๐‘œ"] = "r", ["๐‘œŽ"] = "l", ["๐‘œ"] = "s", ["๐‘œ"] = "รฑ", ["๐‘œ‘"] = "h",
	["๐‘œ’"] = "สผ", ["๐‘œ“"] = "d", ["๐‘œ”"] = "dh", ["๐‘œ•"] = "g", ["๐‘œ–"] = "g", ["๐‘œ—"] = "gh",
	["๐‘œ˜"] = "bh", ["๐‘œ™"] = "jh", ["๐‘œš"] = "v",
	["๐‘€"] = "c", ["๐‘"] = "แนญ", ["๐‘‚"] = "แนญh", ["๐‘ƒ"] = "แธ", ["๐‘„"] = "แธh", ["๐‘…"] = "แน‡", ["๐‘†"] = "แธท",
	-- medials
	["๐‘œ"] = "l", ["๐‘œž"] = "r", ["๐‘œŸ"] = "r",
	-- vowels (excluding composition)
	["๐‘œ "] = "a", ["๐‘œก"] = "ฤ", ["๐‘œข"] = "i", ["๐‘œฃ"] = "ฤซ",
	["๐‘œค"] = "u", ["๐‘œฅ"] = "ลซ", ["๐‘œง"] = "w", ["๐‘œฉ"] = "y",
	["๐‘œฆ"] = "e", ["๐‘œจ"] = "o",
	["๐‘œช"] = "แนƒ", ["๐‘œซ"] = "",
	-- numerals
	["๐‘œฐ"] = "0", ["๐‘œฑ"] = "1", ["๐‘œฒ"] = "2", ["๐‘œณ"] = "3", ["๐‘œด"] = "4",
	["๐‘œต"] = "5", ["๐‘œถ"] = "6", ["๐‘œท"] = "7", ["๐‘œธ"] = "8", ["๐‘œน"] = "9",
	["๐‘œบ"] = "[10]", ["๐‘œป"] = "[20]",
	-- punctuations and symbols
	["๐‘œผ"] = ",", ["๐‘œฝ"] = ".", ["๐‘œพ"] = "@", ["๐‘œฟ"] = "vi",
	-- zero-width space (display it if it hides in a word)
	[u(0x200B)] = "โ€ผ",
}

local adjust0 = {
	-- vowels (composition)
	["๐‘œข".."๐‘œค"] = "รผ",
	["๐‘œฆ".."๐‘œก"] = "ล",
	["๐‘œจ".."๐‘œฆ".."๐‘œก"] = "wล",
	["๐‘œฆ".."๐‘œง"] = "ฤ“",
	["๐‘œฉ".."๐‘œค"] = "ฤy",
	["๐‘œง".."๐‘œค"] = "ฤw",
}

function export.tr(text, lang, sc, debug_mode)

	if type(text) == "table" then -- called directly from a template
		text = text.args[1]
	end

	text = gsub(text, "[๐‘œˆ๐‘œš](๐‘œซ)", "w%1") -- final -b (or -v) becomes -w
	text = gsub(text, con_cls.."([๐‘œ€-๐‘œš๐‘€-๐‘†w])๐‘œซ", "%1a%2")
	text = gsub(text, con_cls.."([๐‘œง".."๐‘œฉ".."๐‘œช])", "%1a%2")

	for k, v in pairs(adjust0) do
		text = gsub(text, con_cls..k, "%1"..v)
	end

	text = gsub(text, ".", tt)

	return text

end

return export