Module:th-translit

ពីWiktionary

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

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

local tt = {
	-- consonants
    ["ก"] = "ក", ["ข"] = "ខ", ["ซ"] = "ខ", ["ค"] = "គ", ["ฅ"] = "គ", ["ฆ"] = "ឃ", ["ง"] = "ង", 
    ["จ"] = "ច", ["ฉ"] = "ឆ", ["ช"] = "ជ", ["ซ"] = "ជ្ស",  ["ฌ"] = "ឈ", ["ญ"] = "ញ", 
    ["ฎ"] = "ដ", ["ฏ"] = "ត", ["ฐ"] = "ឋ", ["ฑ"] = "ឌ", ["ฒ"] = "ឍ", ["ณ"] = "ណ", 
    ["ด"] = "ដ", ["ต"] = "ត", ["ถ"] = "ថ", ["ท"] = "ទ", ["ธ"] = "ធ", ["น"] = "ន", 
    ["บ"] = "ប", ["ป"] = "ប្វ", ["ผ"] = "ផ", ["ฝ"] = "ផ្វ", ["พ"] = "ព", ["ฟ"] = "ព្វ", ["ภ"] = "ភ", ["ม"] = "ម", 
    ["ย"] = "យ", ["ร"] = "រ", ["ล"] = "ល", ["ว"] = "វ", ["ศ"] = "ឝ", ["ษ"] = "ឞ", ["ส"] = "ស", 
    ["ห"] = "ហ", ["ฬ"] = "ឡ", ["อ"] = "អ", ["ฮ"] = "អ្ហ", 
    -- vowels
    ["ะ"] = "ៈ", ["ั"] = "័", ["า"] = "ា", ["ำ"] = "ាំ", ["ิ"] = "ិ", ["ี"] = "ី", ["ึ"] = "ឹ", ["ื"] = "ឺ", ["ุ"] = "ុ", ["ู"] = "ូ", ["ฤ"] = "ឫ", ["ฦ"] = "ឭ", ["ๅ"] = "ា",
    -- tones and diacritics
    ["็"] = "៏", ["่"] = "់", ["้"] = "៉", ["๊"] = "៊", ["๋"] = "៎", ["์"] = "៍", ["ํ"] = "ំ", ["ฺ"] = "្", ["๎"] = "្",
    -- punctuations
    ["ฯ"] = "។", ["ๆ"] = "ៗ", ["๏"] = "៙", ["๛"] = "៚", ["ฯลฯ"] = "៘", ["๚"] = "៕",
    -- 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, "([เแไใโ])([กขคดตบปพ])(ร)", "%2%1%3")
    text = gsub(text, "([เแไใโ])([กขคบปพ])(ล)([ก-ฮ])", "%2%1%3%4")
    text = gsub(text, "([เแไใโ])([กขค])(ว)([ก-ฮ])", "%2%1%3%4")
    
    text = gsub(text, "อ([ะ-ฺ])", "អ%1")
    text = gsub(text, "([ก-ฮ])อ", "%1្ច")
    text = gsub(text, "([ก-ฮ])([็-๋])อ", "%1្ច%2")
    text = gsub(text, "([ก-ฮ])([ิ])([็-๋])อ", "%1្ច%2%3")
    text = gsub(text, "([ก-ฮ])([ิ])อ", "%1្ច%2")
    text = gsub(text, "([ก-ฮ])ีย", "%1ី្យ")
    text = gsub(text, "([ก-ฮ])ี([็-๋])ย", "%1ី%2្យ")

    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, "ฏ", "ฎ")
		text = gsub(text, u(0x0303), "")
	end

	return text

end

return export