This module will transliterate text in the อักษรเทวนาครี. It is used to transliterate Agariya, Ahirani, Jeru, Angika, Andh, Athpare, อวัธ, Bantawa, Byangsi, Pauri Bareli, Balti, Bagheli, Mahasu Pahari, Haryanvi, Rathwi Bareli, Bauria, Bagri, Bhatri, พิหาร, Bharia, Bhili, Bhadrawahi, Bhilali, Bahing, Bhattiyali, Bhunjia, Bijori, Birhor, Kannauji, Bote-Majhi, Bundeli, Palya Bareli, พรัช, Baraamu, โบโด, Bateri, Bujhyal, Belhariya, Chambeali, Churahi, Chepang, Chantyal, Chinali, Idu, Chhintange, Chhulung, Hindi Dogri, Dhundhari, Dhimal, Dhodia, Danuwar, Dogri, Darai, Doteli, Dungra Bhil, Dumi, Eastern Meohang, Gaddi, Gamit, Garhwali, Eastern Gurung, Southern Ghale, Northern Ghale, Gojri, Rajput Garasia, Western Gurung, ฮินดี, Halbi, Chhattisgarhi, Ho, Hadothi, Apabhramsa, คุชราตกลาง, Old Awadhi, คุชราตเก่า, ฮินดีเก่า, Jaunsari, Kolami, Kinnauri, Bilaspuri, Kullu Pahari, Kumaoni, Gamale Kham, Eastern Parbate Kham, Sheshi Kham, Western Parbate Kham, Kalaktang Monpa, Kumarbhag Paharia, กงกัณ, กุรุข, แคชเมียร์, Nepali Kurux, Kayort, Kudmali, มคธ, ไมถิลี, Mandeali, Sawriya Paharia, Mal Paharia, มราฐี, Western Magar, Mising, เมวาร์, Malvi, มาร์วาร์, Miju, Na, นิโคบาร์กลาง, Nachering, เนปาล, เนวาร์, Southeastern Kolami, Nihali, Manangba, Wancho, Nimadi, เนวาร์กลาง, มราฐีเก่า, Duruwa, คานธาระ, Pangwali, บาลี, ปรากฤต, Powari, Chamling, Raute, ราชพังสี, สันสกฤต, Saurashtra, Sindhi Bhil, Sadri, Shina, Yolmo, สินธ์, Surjapuri, Saraiki, Sunwar, Kagate, Eastern Tamang, Milang, Panchpargania, Western Tamang, Eastern Gorkha Tamang, Northwestern Tamang, Tshangla, Mundari, Varhadi, Varli, Bajjika, Mewati, Kangri, เศรปา, Yakkha, and Yamphu. 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:Deva-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(0x0929)] = 'น̱',
	['प'] = 'ป', ['फ'] = 'ผ', ['ब'] = 'พ', ['भ'] = 'ภ', ['म'] = 'ม',
	['य'] = 'ย', ['र'] = 'ร', [u(0x0931)] = 'ร̱', ['ल'] = 'ล', ['ळ'] = 'ฬ', [u(0x0934)] = 'ฬ̱', ['व'] = 'ว',
	['श'] = 'ศ', ['ष'] = 'ษ', ['स'] = 'ส', ['ह'] = 'ห',
	[u(0x0958)] = 'ก̱', [u(0x0959)] = 'ฃ', [u(0x095A)] = 'ฅ',
	[u(0x095B)] = 'ซ', [u(0x095C)] = 'ฑ̱', [u(0x095D)] = 'ฒ̱',
	[u(0x095E)] = 'ฝ', [u(0x095F)] = 'ย̱', ['ॹ'] = 'ซ̱', ['ॺ'] = 'ย͇',
	['ॻ'] = 'ค͓', ['ॼ'] = 'ช͓', ['ॽ'] = 'อ', ['ॾ'] = 'ฑ͓', ['ॿ'] = 'พ͓',
	-- independent vowels
	['अ'] = 'อ', ['आ'] = 'อา', ['इ'] = 'อิ', ['ई'] = 'อี',
	['ॶ'] = 'อึ', ['ॷ'] = 'อื', ['उ'] = 'อุ', ['ऊ'] = 'อู',
	['ऋ'] = 'ฤ', ['ॠ'] = 'ฤๅ', ['ऌ'] = 'ฦ', ['ॡ'] = 'ฦๅ',
	['ऍ'] = 'แอ', ['ऎ'] = 'เอ็', ['ए'] = 'เอ', ['ऐ'] = 'ไอ',
	['ऑ'] = 'ออ̂', ['ऒ'] = 'โอ็', ['ओ'] = 'โอ', ['औ'] = 'เอา',
	['ॳ'] = 'เอ็อ̂', ['ॴ'] = 'เออ̂',
	-- dependent vowels and diacritics (excluding front type)
	['ा'] = 'า', ['ि'] = 'ิ', ['ी'] = 'ี',
	['ॖ'] = 'ึ', ['ॗ'] = 'ื', ['ु'] = 'ุ', ['ू'] = 'ู',
	['ृ'] = 'ฺฤ', ['ॄ'] = 'ฺฤๅ', ['ॢ'] = 'ฺฦ', ['ॣ'] = 'ฺฦๅ',
	['ॉ'] = 'อ̂', ['ं'] = 'ํ', ['ः'] = 'ะ', ['्'] = 'ฺ',
	['़'] = u(0x0331), -- macron below
	['ऀ'] = 'ํ์', -- fermata (inverted candrabindu)
	['ँ'] = 'ํ์', -- candrabindu
	['॑'] = u(0x030D), -- vertical line above
	['॒'] = u(0x0332), -- low line
	['॓'] = u(0x0300), -- grave accent
	['॔'] = u(0x0301), -- acute accent
	-- 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 adjust0 = {
	-- for convenience
	['न'..'़'] = u(0x0929), ['र'..'़'] = u(0x0931), ['ळ'..'़'] = u(0x0934),
	['क'..'़'] = u(0x0958), ['ख'..'़'] = u(0x0959), ['ग'..'़'] = u(0x095A),
	['ज'..'़'] = u(0x095B), ['ड'..'़'] = u(0x095C), ['ढ'..'़'] = u(0x095D),
	['फ'..'़'] = u(0x095E), ['य'..'़'] = u(0x095F),
}

local adjust1 = {
	-- dependent vowels (front type)
	['ॅ'] = 'แ%1', ['ॆ'] = 'เ%1็', ['े'] = 'เ%1', ['ै'] = 'ไ%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

	if lang == 'ne' then -- unused marks from ne-l
		text = gsub(text, '[<>•ॱ]', '')
	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, 'ฯฯ', '๚')
	
	-- ย้ายสัญลักษณ์ขึ้นบน เมื่อมีสระล่าง (ยกเว้นตัวที่ไม่มี)
	text = gsub(text, u(0x0331)..'([ุ-ฺ])', u(0x0304)..'%1') -- macron below > macron above
	text = gsub(text, u(0x0332)..'([ุ-ฺ])', u(0x0305)..'%1') -- low line > overline
	text = gsub(text, u(0x0353)..'([ุ-ฺ])', u(0x033D)..'%1') -- x below > x above
	
	-- ย้ายสัญลักษณ์ลงล่าง เมื่อมีสระบน (ยกเว้นตัวที่ไม่มี)
	text = gsub(text, u(0x030D)..'([ัิ-ื็-๎])', u(0x0329)..'%1') -- vertical line above > vertical line below
	text = gsub(text, u(0x0300)..'([ัิ-ื็-๎])', u(0x0316)..'%1') -- grave accent > grave accent below
	text = gsub(text, u(0x0301)..'([ัิ-ื็-๎])', u(0x0317)..'%1') -- acute accent > acute accent below
	
	return text

end

return export