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:Tale-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
-- pattern ([ᥐ-ᥢ])([ᥣ-ᥬ]?)([ᥐᥒᥖᥙᥛᥝᥢᥭ]?)([ᥰ-ᥴ{dia-tones}]?)

local tt = {
	-- consonants
	["ᥐ"] = "ก", ["ᥑ"] = "ฃ", ["ᥒ"] = "ง", ["ᥓ"] = "จ", ["ᥔ"] = "ส", ["ᥕ"] = "ย",
	["ᥖ"] = "ต", ["ᥗ"] = "ถ", ["ᥘ"] = "ล", ["ᥙ"] = "ป", ["ᥚ"] = "ผ", ["ᥛ"] = "ม",
	["ᥜ"] = "ฝ", ["ᥝ"] = "ว", ["ᥞ"] = "ห", ["ᥟ"] = "อ", ["ᥠ"] = "ข", ["ᥡ"] = "ฉ", ["ᥢ"] = "น",
	-- vowels
	["ᥣ"] = "า", ["ᥤ"] = "ี", ["ᥥ"] = "↶เ", ["ᥦ"] = "↶แ", ["ᥧ"] = "ู",
	["ᥨ"] = "↶โ", ["ᥩ"] = "อ̂", ["ᥪ"] = "ื", ["ᥫ"] = "↶เอ̂", ["ᥬ"] = "↶ใ",
	["ᥭ"] = "ย",
	-- tones (different order from Unicode) http://www.seasite.niu.edu/tai/TaiDehong/index.htm
	["ᥰ"] = "๊", [u(0x0308)] = "๊", [u(0x00A8)] = "๊", -- tone 2
	["ᥱ"] = "่", [u(0x030C)] = "่", [u(0x02C7)] = "่", -- tone 3
	["ᥲ"] = "้", [u(0x0300)] = "้", [u(0x0060)] = "้", [u(0x02CB)] = "้", -- tone 4
	["ᥳ"] = "๎", [u(0x0307)] = "๎", [u(0x02D9)] = "๎", -- tone 5
	["ᥴ"] = "๋", [u(0x0301)] = "๋", [u(0x00B4)] = "๋", [u(0x02CA)] = "๋", -- tone 1
	-- tone 6 unmarked
}

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, "([ᥐ-ᥢ])([ᥐᥒᥖᥙᥛᥝᥢᥭ])", "%1ั%2")

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

	text = gsub(text, "([ก-ฮ])ัว", "%1↶เา")

	text = gsub(text, "([ัาีืูเแโใ])([ก-ฮ])([่้๊๋๎])", "%1%3%2")
	text = gsub(text, "(อ̂)([ก-ฮ])([่้๊๋๎])", "%1%3%2")
	text = gsub(text, "(า)([่้๊๋๎])", "%2%1")
	text = gsub(text, "(อ̂)([่้๊๋๎])", "%2%1")

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

	return text

end

return export