มอดูล:Ahom-translit

จาก วิกิพจนานุกรม พจนานุกรมเสรี

This module will transliterate text in the อักษรอาหม. It is used to transliterate อาหม (aho). 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 = 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
	["𑜀"] = "ก", ["𑜁"] = "ข", ["𑜂"] = "ง", ["𑜃"] = "น", ["𑜄"] = "ต", ["𑜅"] = "ต",
	["𑜆"] = "ป", ["𑜇"] = "ผ", ["𑜈"] = "บ", ["𑜉"] = "ม", ["𑜊"] = "ย", ["𑜋"] = "ฉ",
	["𑜌"] = "ถ", ["𑜍"] = "ร", ["𑜎"] = "ล", ["𑜏"] = "ส", ["𑜐"] = "ญ", ["𑜑"] = "ห",
	["𑜒"] = "อ", ["𑜓"] = "ด", ["𑜔"] = "ธ", ["𑜕"] = "ค", ["𑜖"] = "ค", ["𑜗"] = "ฆ",
	["𑜘"] = "ภ", ["𑜙"] = "ฌ", ["𑜚"] = "ว",
	["𑝀"] = "จ", ["𑝁"] = "ฏ", ["𑝂"] = "ฐ", ["𑝃"] = "ฑ", ["𑝄"] = "ฒ", ["𑝅"] = "ณ", ["𑝆"] = "ฬ",
	-- medials
	["𑜝"] = "ฺล", ["𑜞"] = "ฺร", ["𑜟"] = "ฺร",
	-- vowels (excluding front type)
	["𑜠"] = "ะ", ["𑜡"] = "า", ["𑜢"] = "ิ", ["𑜣"] = "ี",
	["𑜤"] = "ุ", ["𑜥"] = "ู", ["𑜧"] = "ว์", ["𑜩"] = "ย์",
	["𑜨"] = "อ̂",
	["𑜪"] = "ํ", ["𑜫"] = "์",
	-- numerals
	["𑜰"] = "0", ["𑜱"] = "1", ["𑜲"] = "2", ["𑜳"] = "3", ["𑜴"] = "4",
	["𑜵"] = "5", ["𑜶"] = "6", ["𑜷"] = "7", ["𑜸"] = "8", ["𑜹"] = "9",
	["𑜺"] = "[10]", ["𑜻"] = "[20]",
	-- punctuations and symbols
	["𑜼"] = "ฯ", ["𑜽"] = "๚", ["𑜾"] = "@", ["𑜿"] = "วิ",
	-- zero-width space (display it if it hides in a word)
	[u(0x200B)] = "‼",
}

local adjust0 = {
	-- vowels (composition)
	["𑜢".."𑜤"] = "%1ึ",
	["𑜦".."𑜡"] = "%1อ̂",
	["𑜨".."𑜦".."𑜡"] = "%1ฺวอ̂",
	["𑜦".."𑜧"] = "เ%1",
	["𑜩".."𑜤"] = "%1าย์",
	["𑜧".."𑜤"] = "%1าว์",
}

local adjust1 = {
	-- vowels (front type)
	["𑜦"] = "เ%1",
}

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

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

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

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

	text = gsub(text, "บ์", "ว์")

	return text

end

return export