Module:mnw-translit

ពីWiktionary

Documentation for this module may be created at Module:mnw-translit/doc

local export = {}
local gsub = mw.ustring.gsub
local u = mw.ustring.char
local letter_with_mark = "(.["..u(0x0300).."-"..u(0x036F).."]?)"

local pre = {
	["ျ"] = "္ယ", ["ြ"] = "္ရ", ["ွ"] = "္ဝ", ["ှ"] = "္ဟ",
	["ၞ"] = "္န", ["ၟ"] = "္မ", ["ၠ"] = "္လ",
}

local tt1 = {
	-- consonants
	["က"] = "ក", ["ခ"] = "ខ", ["ဂ"] = "គ", ["ဃ"] = "ឃ", ["င"] = "ង", ["ၚ"] = "ង",
	["စ"] = "ច", ["ဆ"] = "ឆ", ["ဇ"] = "ជ", ["ၛ"] = "ឈ", ["ဉ"] = "ញ", ["ည"] = "ញ្ញ",
	["ဋ"] = "ដ", ["ဌ"] = "ឋ", ["ဍ"] = "ឌ", ["ဎ"] = "ឍ", ["ဏ"] = "ណ",
	["တ"] = "ត", ["ထ"] = "ថ", ["ဒ"] = "ទ", ["ဓ"] = "ធ", ["န"] = "ន",
	["ပ"] = "ប", ["ဖ"] = "ផ", ["ဗ"] = "ព", ["ဘ"] = "ភ", ["မ"] = "ម",
	["ယ"] = "យ", ["ရ"] = "រ", ["လ"] = "ល", ["ဝ"] = "វ", ["သ"] = "ស", ["ဿ"] = "ស្ស",
	["ဟ"] = "ហ", ["ဠ"] = "ឡ", ["ၜ"] = "ប៑", ["အ"] = "អ", ["ၝ"] = "ម្ប",
	-- independent vowels (1)
	["ဣ"] = "ឥ", ["ဥ"] = "ឧ",
	["ဨ"] = "ឯ", ["ဩ"] = "ឱ",
	-- dependent vowels and diacritics (1 char)
	["ါ"] = "ា", ["ာ"] = "ា", ["ိ"] = "ិ", ["ီ"] = "ឹ", ["ဳ"] = "ី", ["ု"] = "ុ", ["ူ"] = "ូ", ["ဲ"] = "័",
	["ဴ"] = "ោ", ["ေ"] = "េ", ["ဵ"] = "េ", 
	["ံ"] = "ំ", ["း"] = "ះ", ["္"] = "្", ["်"] = "៑", ["ါဲ"] = "ាយ", ["ာဲ"] = "ាយ",
	-- punctuation marks
	["၊"] = ",", ["။"] = "។", 
	-- numerals
	["၀"] = "០", ["၁"] = "១", ["၂"] = "២", ["၃"] = "៣", ["၄"] = "៤",
	["၅"] = "៥", ["၆"] = "៦", ["၇"] = "៧", ["၈"] = "៨", ["၉"] = "៩",
	-- zero-width space (display it if it hides in a word)
	[u(0x200B)] = "‼", [u(0x200C)] = "‼", [u(0x200D)] = "‼",
}

local tt2 = {
	-- vowels (2 chars)
	["ဣဳ"] = "ឦ", ["ဥု"] = "ឩ",
	["ုဲ"] = "%1ុយ", ["ဵု"] = "%1េុ",
}

local adjust = {
	["ិុ"] = "ុិ", ["ីុ"] = "ុី"
}

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

	for k, v in pairs(tt2) do
		text = gsub(text, letter_with_mark..k, v)
	end

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

    for k, v in pairs(adjust) do
		text = gsub(text, k, v)
	end

	return text
 
end
 
return export