Module:lo-translit

ពីWiktionary

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

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

local tt = {
	-- consonants
	["ກ"] = "ក", ["ຂ"] = "ខ", ["ຄ"] = "គ", ["ງ"] = "ង", ["ຈ"] = "ច",
	["ຊ"] = "ជ", ["ຍ"] = "យ្យ", ["ດ"] = "ត", ["ຕ"] = "ត", ["ຖ"] = "ថ",
	["ທ"] = "ទ", ["ນ"] = "ន", ["ບ"] = "ប", ["ປ"] = "ប្វ", ["ຜ"] = "ផ",
	["ຝ"] = "ផ្វ", ["ພ"] = "ព", ["ຟ"] = "ព្វ", ["ມ"] = "ម", ["ຢ"] = "យ",
	["ຣ"] = "រ", ["ລ"] = "ល", ["ວ"] = "វ", ["ສ"] = "ស", ["ຫ"] = "ហ",
	["ອ"] = "អ", ["ຮ"] = "អ្ហ", ["ຼ"] = "្ល", ["ຽ"] = "្យ",
	["ໜ"] = "ហ្ន", ["ໝ"] = "ហ្ម", ["ໞ"] = "ហ្ក", ["ໟ"] = "ហ្យ",
	-- Pali and Sanskrit
	["ຆ"] = "ឃ", ["ຉ"] = "ឆ", ["ຌ"] = "ឈ", ["ຎ"] = "ញ",
	["ຏ"] = "ដ", ["ຐ"] = "ឋ", ["ຑ"] = "ឌ", ["ຒ"] = "ឍ", ["ຓ"] = "ណ",
	["ຘ"] = "ធ", ["ຠ"] = "ភ", ["ຨ"] = "ឝ", ["ຩ"] = "ឞ", ["ຬ"] = "ឡ", ["຺"] = "្",
	-- punctuations
	["ຯ"] = "។", ["ໆ"] = "ៗ",
		-- vowels
	["ະ"] = "ៈ", ["ັ"] = "័", ["າ"] = "ា", ["ຳ"] = "ាំ",
	["ິ"] = "ិ", ["ີ"] = "ី", ["ຶ"] = "ឹ", ["ື"] = "ឺ",
	["ຸ"] = "ុ", ["ູ"] = "ូ", ["ົ"] = "៏",
	-- tones and diacritics
	["່"] = "់", ["້"] = "៉", ["໊"] = "៊", ["໋"] = "៎", ["໌"] = "៍", ["ໍ"] = "ំ",
	-- numerals
	["໐"] = "០", ["໑"] = "១", ["໒"] = "២", ["໓"] = "៣", ["໔"] = "៤",
	["໕"] = "៥", ["໖"] = "៦", ["໗"] = "៧", ["໘"] = "៨", ["໙"] = "៩",
	-- zero-width space (display it if it hides in a word)
	[u(0x200B)] = "‼", [u(0x200C)] = "‼", [u(0x200D)] = "‼",
}

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

    text = gsub(text, "ເ(.)", "%1េ")
    text = gsub(text, "ແ(.)", "%1ែ")
    text = gsub(text, "ໂ(.)", "%1ោ")
    text = gsub(text, "ໃ(.)", "%1ៃ")
    text = gsub(text, "ໄ(.)", "%1ៃ") 

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

    if lang == "pi" or lang == "sa" then
		text = gsub(text, "ປ", "ບ")
		text = gsub(text, u(0x0303), "")
	end

	return text

end

return export