This module will transliterate text in the อักษรไทเวียด. It is used to transliterate ไทดำ. 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:Tavt-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 tt = {
	-- consonants
	["ꪀ"] = "ก", ["ꪁ"] = "ก̱", ["ꪂ"] = "ข", ["ꪃ"] = "ค", ["ꪄ"] = "ฃ", ["ꪅ"] = "ฅ", ["ꪆ"] = "?", ["ꪇ"] = "?", ["ꪈ"] = "หฺง", ["ꪉ"] = "ง",
	["ꪊ"] = "จ", ["ꪋ"] = "จ̱", ["ꪌ"] = "ฉ", ["ꪍ"] = "ช", ["ꪎ"] = "ส", ["ꪏ"] = "ซ", ["ꪐ"] = "หฺญ", ["ꪑ"] = "ญ",
	["ꪒ"] = "ด", ["ꪓ"] = "ด̱", ["ꪔ"] = "ต", ["ꪕ"] = "ต̱", ["ꪖ"] = "ถ", ["ꪗ"] = "ท", ["ꪘ"] = "หฺน", ["ꪙ"] = "น",
	["ꪚ"] = "บ", ["ꪛ"] = "บ̱", ["ꪜ"] = "ป", ["ꪝ"] = "ป̱", ["ꪞ"] = "ผ", ["ꪟ"] = "พ", ["ꪠ"] = "ฝ", ["ꪡ"] = "ฟ", ["ꪢ"] = "หฺม", ["ꪣ"] = "ม",
	["ꪤ"] = "หฺย", ["ꪥ"] = "ย", ["ꪦ"] = "หฺร", ["ꪧ"] = "ร", ["ꪨ"] = "หฺล", ["ꪩ"] = "ล", ["ꪪ"] = "หฺว", ["ꪫ"] = "ว",
	["ꪬ"] = "ห", ["ꪭ"] = "ฮ", ["ꪮ"] = "อ", ["ꪯ"] = "อ̱",
	-- vowels and finals (visual ordering)
	["ꪰ"] = "ั", ["ꪱ"] = "า", ["ꪲ"] = "ิ", ["ꪳ"] = "ึ", ["ꪴ"] = "ุ", ["ꪵ"] = "แ", ["ꪶ"] = "โ",
	["ꪷ"] = "ํ", ["ꪸ"] = "ย̂", ["ꪹ"] = "เ", ["ꪺ"] = "ัว", ["ꪻ"] = "ใ", ["ꪼ"] = "ไ",
	["ꪽ"] = "ัน", ["ꪾ"] = "ำ",
	-- tones
	["꪿"] = "่", ["ꫀ"] = "¹", ["꫁"] = "้", ["ꫂ"] = "²",
	-- symbols
	["ꫛ"] = "โก̱น", ["ꫜ"] = "นึ่ง", ["ꫝ"] = "ๆ", ["꫞"] = "๏", ["꫟"] = "๛",
}

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, ".", tt)

	text = gsub(text, "([่้๋̱])([ัิีึืุู])", "%2%1")
	text = gsub(text, "([^%s%p%z])บำ", "%1ับ")
	text = gsub(text, "(ำ)([่้๋̱])", "%2%1")

	return text

end

return export