This module will transliterate ภาษากะเหรี่ยงสะกอ text. 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:ksw-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 tt1 = {
	-- consonants
	["က"] = "ก", ["ခ"] = "ข", ["ဂ"] = "ค", ["ဃ"] = "ฆ", ["င"] = "ง",
	["စ"] = "จ", ["ဆ"] = "ฉ", ["ၡ"] = "ศ", ["ည"] = "ญ",
	["တ"] = "ต", ["ထ"] = "ถ", ["ဒ"] = "ท", ["န"] = "น",
	["ပ"] = "ป", ["ဖ"] = "ผ", ["ဘ"] = "ภ", ["မ"] = "ม",
	["ယ"] = "ย", ["ရ"] = "ร", ["လ"] = "ล", ["ဝ"] = "ว",
	["သ"] = "ส", ["ဟ"] = "ห", ["အ"] = "อ", ["ဧ"] = "ฮ",
	-- medials
	["ှ"] = "ฺค", ["ၠ"] = "ฺย", ["ြ"] = "ฺร", ["ျ"] = "ฺล", ["ွ"] = "ฺว",
	-- dependent vowels (excluding front type)
	["ါ"] = "า", ["ံ"] = "ี", ["ု"] = "ื", ["ူ"] = "ู", ["ီ"] = "อ̂",
	-- numerals
	["၀"] = "๐", ["၁"] = "๑", ["၂"] = "๒", ["၃"] = "๓", ["၄"] = "๔",
	["၅"] = "๕", ["၆"] = "๖", ["၇"] = "๗", ["၈"] = "๘", ["၉"] = "๙",
	-- zero-width space (display it if it hides in a word)
	[u(0x200B)] = "‼",
}

local adjust0 = {
	-- tones
	["ၢ်"] = "¹", ["ာ်"] = "²", ["း"] = "³", ["ၣ်"] = "⁴",
	["ၤ"] = "⁵", --prolonged
}

local adjust1 = {
	-- dependent vowels (front type)
	["ၢ"] = "เ%1อ̂", ["့"] = "เ%1", ["ဲ"] = "แ%1", ["ိ"] = "โ%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, k, v)
	end
	text = gsub(text, ".", tt1)
	for k, v in pairs(adjust1) do
		text = gsub(text, "([ก-ฮ])"..k, v)
	end

	text = gsub(text, "^([ก-ฮ])([¹²³⁴⁵])", "%1า%2")
	text = gsub(text, "([^เแโ])([ก-ฮ])([¹²³⁴⁵])", "%1%2า%3")

	return text
 
end
 
return export