มอดูล:Gujr-translit

จาก วิกิพจนานุกรม พจนานุกรมเสรี
ไปยังการนำทาง ไปยังการค้นหา

มอดูลนี้ใช้ถอดอักษรข้อความในอักษรคุชราต.

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 มอดูล:Gujr-translit/testcases.

ฟังก์ชัน[แก้ไข]

tr(text, lang, sc)
Transliterates a given piece of text written in the script specified by sc, and language specified by 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)
	['ા'] = 'า', ['િ'] = 'ิ', ['ી'] = 'ี', ['ુ'] = 'ุ', ['ૂ'] = 'ู',
	['ૃ'] = 'ฺฤ', ['ૄ'] = 'ฺฤๅ', ['ૢ'] = 'ฺฦ', ['ૣ'] = 'ฺฦๅ',
	['ૉ'] = 'อ̂', ['ં'] = 'ํ', ['ઃ'] = 'ห์', ['્'] = 'ฺ',
	['઼'] = 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', ['ૌ'] = 'เ%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