Module:my-translit

ពីWiktionary

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

local export = {}
local gsub = mw.ustring.gsub
local u = mw.ustring.char

local tt = {
	-- consonants
	["က"] = "ក", ["ခ"] = "ខ", ["ဂ"] = "គ", ["ဃ"] = "ឃ", ["င"] = "ង",
	["စ"] = "ច", ["ဆ"] = "ឆ", ["ဇ"] = "ជ", ["ဈ"] = "ឈ", ["ဉ"] = "ញ", ["ည"] = "ញ្ញ",
	["ဋ"] = "ដ", ["ဌ"] = "ឋ", ["ဍ"] = "ឌ", ["ဎ"] = "ឍ", ["ဏ"] = "ណ",
	["တ"] = "ត", ["ထ"] = "ថ", ["ဒ"] = "ទ", ["ဓ"] = "ធ", ["န"] = "ន",
	["ပ"] = "ប", ["ဖ"] = "ផ", ["ဗ"] = "ព", ["ဘ"] = "ភ", ["မ"] = "ម",
	["ယ"] = "យ", ["ရ"] = "រ", ["လ"] = "ល", ["ဝ"] = "វ",
	["သ"] = "ស", ["ဟ"] = "ហ", ["ဠ"] = "ឡ", ["အ"] = "អ",
	["ဿ"] = "ស្ស",
	-- independent vowels
	["ဣ"] = "ឥ", ["ဤ"] = "ឦ", ["ဥ"] = "ឧ", ["ဦ"] = "ឩ",
	["ဧ"] = "ឯ", ["ဩ"] = "ឱ", ["ဪ"] = "ឳ",
	-- dependent vowels and diacritics (excluding front type)
	["ါ"] = "ា", ["ာ"] = "ា", ["ီ"] = "ី", ["ု"] = "ុ", ["ူ"] = "ូ", ["ိ"] = "ិ",	["ံ"] = "ំ", ["့"] = "៓",  ["း"] = "ះ", ["္"] = "្",   ["်"] = "៑"  , ["ျ"] = "្យ", ["ြ"] = "្រ", ["ွ"] = "្វ", ["ေ"] = "េ", ["ဲ"] = "ៃ",
	-- marks
	["၊"] = ",", ["။"] = "។",
	["၌"] = "ហ្នុិក៑", ["၍"] = "រ្វេ៓", ["၎"] = "〃", ["၏"] = "អិ",
	-- numerals
	["၀"] = "0", ["၁"] = "1", ["၂"] = "2", ["၃"] = "3", ["၄"] = "4",
	["၅"] = "5", ["၆"] = "6", ["၇"] = "7", ["၈"] = "8", ["၉"] = "9",
	-- zero-width space (display it if it hides in a word)
	[u(0x200B)] = "‼",
}

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, "(့)([ါ-ှ])", "%2%1") -- swap tone-3 mark and vowel
	text = gsub(text, ".", tt)

    text = gsub(text, "(.)ှ", "ហ្%1")

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

	return text
 
end
 
return export