Module:Ahom-translit

From Linguifex
Jump to navigation Jump to search

Documentation for this module may be created at Module:Ahom-translit/doc

local export = {}
local gsub = mw.ustring.gsub
local u = require("Module:string/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)

	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