This module will transliterate ภาษาอ่ายตน text. It is also used to transliterate อ่ายตน and พ่าเก. 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:aio-phk-translit/testcases.

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 = "([ကၵငꩡꩬၺတထꩫဒပၸမဗယꩺလဝꩭဢ])"
local med_cls = "([ျြၞ]?)"

local tt1 = {
	-- consonants
	["က"] = "ก", ["ၵ"] = "ข", ["င"] = "ง",
	["ꩡ"] = "จ", ["ꩬ"] = "ส", ["ၺ"] = "ญ",
	["တ"] = "ต", ["ထ"] = "ถ", ["ꩫ"] = "น", ["ဒ"] = "ด",
	["ပ"] = "ป", ["ၸ"] = "ผ", ["မ"] = "ม", ["ဗ"] = "บ",
	["ယ"] = "ย", ["ꩺ"] = "ร", ["လ"] = "ล", ["ဝ"] = "ว",
	["ꩭ"] = "ห", ["ဢ"] = "อ",
	-- medials
	["ျ"] = "ฺย", ["ြ"] = "ฺร", ["ၞ"] = "ฺว",
	-- dependent vowels and diacritics (excluding front type)
	["္"] = "ฺ", ["ႜ"] = "ะ", ["ႃ"] = "า", ["ိ"] = "ิ", ["ီ"] = "ี",
	["ု"] = "ุ", ["ူ"] = "ู", ["ွ"] = "อ̂", ["်"] = "์", ["ႝ"] = "ย์",
	["ေ"] = "↶เ", ["ံ"] = "ํ",
	-- punctuation marks
	["၊"] = ",", ["။"] = ".", ["꩷"] = "!",
	-- numerals
	["꩸"] = "1", ["꩹"] = "2",
	["၀"] = "0", ["၁"] = "1", ["၂"] = "2", ["၃"] = "3", ["၄"] = "4",
	["၅"] = "5", ["၆"] = "6", ["၇"] = "7", ["၈"] = "8", ["၉"] = "9",
	-- zero-width space (display it if it hides in a word)
	[u(0x200B)] = "‼",
}

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, u(0xFE00), "") -- remove VS01

	text = gsub(text, "ေ".."ႃ", "อ̂")
	text = gsub(text, "ိ".."ု", "ึ")
	text = gsub(text, "ွ".."်", "↶เา")
	text = gsub(text, "ၞ".."်", "↶ใ")

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

	text = gsub(text, "([ก-ฮ]์)([่้๊๋๎])", "%2%1")
	text = gsub(text, "(อ̂)([่้๊๋๎])", "%2%1")
	text = gsub(text, "(า)([่้๊๋๎])", "%2%1")

	text = gsub(text, "(.)↶([เแใไ])", "%2%1")

	return text
 
end
 
return export