มอดูล:Newa-translit

จาก วิกิพจนานุกรม พจนานุกรมเสรี
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)
	['𑐵'] = 'า', ['𑐶'] = 'ิ', ['𑐷'] = 'ี', ['𑐸'] = 'ุ', ['𑐹'] = 'ู',
	['𑐺'] = 'ฺฤ', ['𑐻'] = 'ฺฤๅ', ['𑐼'] = 'ฺฦ', ['𑐽'] = 'ฺฦๅ',
	['𑑄'] = 'ํ', ['𑑈'] = 'ํ', ['𑑟'] = 'ํ', ['𑑅'] = 'ห์', ['𑑂'] = 'ฺ',
	['𑑆'] = u(0x0331), -- macron below
	['𑑃'] = 'ม̐', -- candrabindu
	-- 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 adjust1 = {
	-- dependent vowels (front type)
	['𑐾'] = 'เ%1', ['𑐿'] = 'ไ%1', ['𑑀'] = 'โ%1', ['𑑁'] = 'เ%1า',
}

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)

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

	text = gsub(text, '([เแไโ])อฺ', 'อฺ%1')
	
	-- ย้ายสัญลักษณ์ขึ้นบน เมื่อมีสระล่าง (ยกเว้นตัวที่ไม่มี)
	text = gsub(text, u(0x0331)..'([ุ-ฺ])', u(0x0304)..'%1') -- macron below > macron above
		
	return text

end

return export