ข้ามไปเนื้อหา

มอดูล:Taml-translit

จาก วิกิพจนานุกรม พจนานุกรมเสรี

This module will transliterate text in the อักษรทมิฬ. It is used to transliterate พทคะ, Irula, Kota (India), Mannan, สันสกฤต, Saurashtra, ทมิฬ, โตทา, Vaagri Booli, and Betta Kurumba. The module should preferably not be called directly from templates or other modules. To use it from a template, use {{xlit}}. Within a module, use Module:languages#Language:transliterate.

For testcases, see Module:Taml-translit/testcases.

Functions

tr(text, lang, sc)
Transliterates a given piece of text written in the script specified by the code sc, and language specified by the code lang.
When the transliteration fails, returns nil.

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
	['௦'] = '0', ['௧'] = '1', ['௨'] = '2', ['௩'] = '3', ['௪'] = '4',
	['௫'] = '5', ['௬'] = '6', ['௭'] = '7', ['௮'] = '8', ['௯'] = '9',
	['௰'] = '[10]', ['௱'] = '[100]', ['௲'] = '[1000]',
	-- zero-width space (display it if it hides in a word)
	[u(0x200B)] = '‼',
}

local adjust0 = {
	-- for convenience
	['ஒ'..'ௗ'] = 'ஔ',
	['ெ'..'ா'] = 'ொ', ['ே'..'ா'] = 'ோ', ['ெ'..'ௗ'] = 'ௌ',
	['ௐ'] = 'ஓம்',
}

local adjust1 = {
	-- dependent vowels (front type)
	['ெ'] = 'เ%1็', ['ே'] = 'เ%1', ['ை'] = 'ไ%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

	for k, v in pairs(adjust0) do
		text = gsub(text, k, v)
	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