Module:Ahom-translit

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This module will transliterate text in the Ahom script. It is used to transliterate Ahom. The module should preferably not be called directly from templates or other modules. To use it from a template, use {{xlit}}. Within a module, use Module:languages#Language:transliterate.

For testcases, see Module:Ahom-translit/testcases.

Functions

tr(text, lang, sc)
Transliterates a given piece of text written in the script specified by the code sc, and language specified by the code lang.
When the transliteration fails, returns nil.

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