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

มอดูล:Beng-translit

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

This module will transliterate text in the อักษรเบงกอล. It is used to transliterate อัสสัม, เบงกอล, จักมา, เบงกอลกลาง, เบงกอลเก่า, Kumarbhag Paharia, Sawriya Paharia, Mising, บาลี, สันสกฤต, Surjapuri, and Panchpargania. 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:Beng-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
	['ক'] = 'ก', ['খ'] = 'ข', ['গ'] = 'ค', ['ঘ'] = 'ฆ', ['ঙ'] = 'ง',
	['চ'] = 'จ', ['ছ'] = 'ฉ', ['জ'] = 'ช', ['ঝ'] = 'ฌ', ['ঞ'] = 'ญ',
	['ট'] = 'ฏ', ['ঠ'] = 'ฐ', ['ড'] = 'ฑ', ['ঢ'] = 'ฒ', ['ণ'] = 'ณ',
	['ত'] = 'ต', ['ৎ'] = 'ตฺ', ['থ'] = 'ถ', ['দ'] = 'ท', ['ধ'] = 'ธ', ['ন'] = 'น',
	['প'] = 'ป', ['ফ'] = 'ฝ', ['ব'] = 'พ', ['ভ'] = 'ภ', ['ম'] = 'ม',
	['য'] = 'ย', ['র'] = 'ร', ['ৰ'] = 'ร', ['ল'] = 'ล', ['ৱ'] = 'ว',
	['শ'] = 'ศ', ['ষ'] = 'ษ', ['স'] = 'ส', ['হ'] = 'ห',
	[u(0x09DC)] = 'ฬ', [u(0x09DD)] = 'ฬ̱', [u(0x09DF)] = 'ย̱',
	-- 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',
	['৴'] = '¹⁄₁₆', ['৵'] = '⅛', ['৶'] = '³⁄₁₆', ['৷'] = '¼', ['৸'] = '¾', ['৹'] = '16',
	-- zero-width space (display it if it hides in a word)
	[u(0x200B)] = "‼",
	-- zero-width non-joiner and joiner (display it if it hides in a word)
	[u(0x200C)] = "₋",
	[u(0x200D)] = "₊",
}

local adjust0 = {
	-- for convenience
	['ড'..'়'] = u(0x09DC), ['ঢ'..'়'] = u(0x09DD), ['য'..'়'] = u(0x09DF),
	['ে'..'া'] = 'ো', ['ে'..'ৗ'] = 'ৌ',
}

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

	if lang == "pi" or lang == "sa" then
		text = gsub(text, "ৰ", "ৱ") -- Pali and Sanskrit use ৰ for va
	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