Module:si-translit

ពីWiktionary

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

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

local tt = {
	-- consonants
	["ක"] = "ក", ["ඛ"] = "ខ", ["ග"] = "គ", ["ඝ"] = "ឃ", ["ඞ"] = "ង", ["ඟ"] = "ង្គ",
	["ච"] = "ច", ["ඡ"] = "ឆ", ["ජ"] = "ជ", ["ඣ"] = "ឈ", ["ඤ"] = "ញ", ["ඥ"] = "ជ្ញ", ["ඦ"] = "ญฺช",
	["ට"] = "ដ", ["ඨ"] = "ឋ", ["ඩ"] = "ឌ", ["ඪ"] = "ឍ", ["ණ"] = "ណ", ["ඬ"] = "ណ្ឌ",
	["ත"] = "ត", ["ථ"] = "ថ", ["ද"] = "ទ", ["ධ"] = "ធ", ["න"] = "ន", ["ඳ"] = "ន្ទ",
	["ප"] = "ប", ["ඵ"] = "ផ", ["බ"] = "ព", ["භ"] = "ភ", ["ම"] = "ម", ["ඹ"] = "ម្ព",
	["ය"] = "យ", ["ර"] = "រ", ["ල"] = "ល", ["ව"] = "វ",
	["ශ"] = "ឝ", ["ෂ"] = "ឞ", ["ස"] = "ស", ["හ"] = "ហ", ["ළ"] = "ឡ", ["ෆ"] = "ហ្វ",
	-- independent vowels
	["අ"] = "អ", ["ආ"] = "អា", ["ඇ"] = "អ្ឯៈ", ["ඈ"] = "អ្ឯៈ",
	["ඉ"] = "ឥ", ["ඊ"] = "ឦ", ["උ"] = "ឧ", ["ඌ"] = "ឩ",
	["ඍ"] = "ឫ", ["ඎ"] = "ឬ", ["ඏ"] = "ឭ", ["ඐ"] = "ឮ",
	["එ"] = "ឯៈ", ["ඒ"] = "ឯ", ["ඓ"] = "ឰ", ["ඔ"] = "ឱៈ", ["ඕ"] = "ឱ", ["ඖ"] = "ឳ",
	-- dependent vowels and diacritics (excluding front type)
	["ා"] = "ា", ["ි"] = "ិ", ["ී"] = "ី", ["ු"] = "ុ", ["ූ"] = "ូ",
	["ෘ"] = "្ឫ", ["ෲ"] = "្ឬ", ["ෟ"] = "្ឭ", ["ෳ"] = "្ឮ",
	["ං"] = "ំ", ["ඃ"] = "ះ", ["්"] = "្", ["ැ"] = "ែៈ", ["ෑ"] = "ែ",
	["ෙ"] = "េៈ", ["ේ"] = "េ", ["ෛ"] = "ៃ",
	["ො"] = "ោៈ", ["ෝ"] = "ោ", ["ෞ"] = "ៅ",
	-- marks
	["෴"] = "។",
	-- numerals
	["෦"] = "០", ["෧"] = "១", ["෨"] = "២", ["෩"] = "៣", ["෪"] = "៤",
	["෫"] = "៥", ["෬"] = "៦", ["෭"] = "៧", ["෮"] = "៨", ["෯"] = "៩",
	["𑇡"] = "១", ["𑇢"] = "២", ["𑇣"] = "៣", ["𑇤"] = "៤",
	["𑇥"] = "៥", ["𑇦"] = "៦", ["𑇧"] = "៧", ["𑇨"] = "៨", ["𑇩"] = "៩",
	["𑇪"] = "[១០]", ["𑇫"] = "[២០]", ["𑇬"] = "[៣០]", ["𑇭"] = "[៤០]",
	["𑇮"] = "[៥០]", ["𑇯"] = "[៦០]", ["𑇰"] = "[៧០]", ["𑇱"] = "[៨០]", ["𑇲"] = "[៩០]",
	["𑇳"] = "[១០០]", ["𑇴"] = "[១០០០]",
	-- zero-width space (display it if it hides in a word)
	[u(0x200B)] = "‼",
	-- zero-width joiner (display it if it hides in a word)
	[u(0x200D)] = "₊",
}

local adjust0 = {
	-- for convenience
	["අ".."ා"] = "ආ", ["අ".."ැ"] = "ඇ", ["අ".."ෑ"] = "ඈ",
	["උ".."ෟ"] = "ඌ", ["ඍ".."ෘ"] = "ඎ", ["ඏ".."ෟ"] = "ඐ",
	["එ".."්"] = "ඒ", ["එ".."ෙ"] = "ඓ", ["ඔ".."ෟ"] = "ඖ",
	["ෙ".."්"] = "ේ", ["ෙ".."ෙ"] = "ෛ",
	["ෙ".."ා"] = "ො", ["ො".."්"] = "ෝ", ["ෙ".."ෟ"] = "ෞ",
}

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

	return text

end

return export