Module:gon-Gonm-translit

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Masaram Gondi transliteration module.

This module will transliterate Gondi language text. 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:gon-Gonm-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.

Testcases

[edit]

Module:gon-Gonm-translit/testcases:

All tests passed. (refresh)

TextExpectedActualComments
test_translit_gondi:
Passed𑴦𑴶independent <r̥> represented by independent <r> + dependent <r̥>
Passed𑴨𑴘𑵂𑴳vaṛīvaṛī<ṛ> represented as 𑴘𑵂
Passed𑴀𑴎𑵅𑴎aggaaggavirama
Passed𑴌𑴱𑴖𑵄kāṭkāṭword-final halanta
Passed𑴌𑴵𑴥𑵄𑴫𑴱kūysākūysāword-medial halanta
Passed𑴀𑵆𑴝𑴽ardoardorepha
Passed𑴑𑴱𑴠𑵇𑴱cāprācāprāra-kāra
Passed𑴆𑵃ĕĕ<ऍ> ĕ independent
Passed𑴁𑵃ŏŏ<ऑ> ŏ independent
Passed𑴌𑵃<ऍ> ĕ dependent
Passed𑴌𑴱𑵃<ऑ> ŏ dependent

local export = {}
local gsub = mw.ustring.gsub
 
local consonants = {
	['𑴌'] = 'k', ['𑴍'] = 'kh', ['𑴎'] = 'g', ['𑴏'] = 'gh', ['𑴐'] = 'ṅ', 
	['𑴑'] = 'c', ['𑴒'] = 'ch', ['𑴓'] = 'j', ['𑴔'] = 'jh', ['𑴕'] = 'ñ', 
	['𑴖'] = 'ṭ', ['𑴗'] = 'ṭh', ['𑴘'] = 'ḍ', ['𑴙'] = 'ḍh', ['𑴚'] = 'ṇ', 
	['𑴛'] = 't',  ['𑴜'] = 'th', ['𑴝'] = 'd', ['𑴞'] = 'dh', ['𑴟'] = 'n',
	['𑴠'] = 'p', ['𑴡'] = 'ph', ['𑴢'] = 'b', ['𑴣'] = 'bh', ['𑴤'] = 'm', 
	['𑴥'] = 'y', ['𑴦'] = 'r', ['𑴧'] = 'l', ['𑴨'] = 'v', ['𑴭'] = 'ḷ',
	['𑴩'] = 'ś', ['𑴪'] = 'ṣ', ['𑴫'] = 's', ['𑴬'] = 'h', 
	['𑴮'] = 'kṣ', ['𑴯'] = 'jñ', ['𑴰'] = 'tr',
	['𑴘𑵂'] = 'ṛ',
}

local diacritics = {
	['𑴱'] = 'ā', ['𑴲'] = 'i', ['𑴳'] = 'ī', ['𑴴'] = 'u', ['𑴵'] ='ū', ['𑴶'] = 'r̥',
	['𑴺'] = 'e', ['𑴼'] = 'ai', ['𑴽'] ='o', ['𑴿'] = 'au', ['𑵄'] = '', ['𑵅'] = '',
}
local tt = {
	-- vowels
	['𑴀'] = 'a' , ['𑴁'] = 'ā' , ['𑴂'] = 'i' , ['𑴃'] = 'ī' , ['𑴄']='u' , ['𑴅'] = 'ū',
	['𑴆'] = 'e', ['𑴈'] = 'ai' , ['𑴉'] = 'o', ['𑴋'] = 'au',
	-- other symbols
	['𑵀'] = 'ṁ', -- anusvara
	['𑵁'] = 'ḥ', -- visarga
	['𑵃'] = '̃',  -- chandra

-- digits
	['𑵐'] = '0', ['𑵑'] = '1', ['𑵒'] = '2', ['𑵓'] = '3', ['𑵔'] = '4',
	['𑵕'] = '5', ['𑵖'] = '6', ['𑵗'] = '7', ['𑵘'] = '8', ['𑵙'] = '9',
}

-- translit any words or phrases
function export.tr(text, lang, sc)
	text = gsub(text, '𑵇', '𑵄𑴦') -- ra-kāra
	text = gsub(
		text,
		'([𑴌-𑴰]𑵂?)'..
		'([[𑴱𑴲𑴳𑴴𑴵𑴶𑴺𑴼𑴽𑴿𑵀𑵁𑵄𑵅]?)',
		function(c, d)
			if d == "" then        
				return consonants[c] .. 'a'
			else
				return consonants[c] .. diacritics[d]
			end
		end)
	
	text = gsub(text, '.', tt)
	
	-- anusvara
	text = gsub(text, 'ṁ([kgṅ])', 'ṅ%1')
	text = gsub(text, 'ṁ([cjñ])', 'ñ%1')
	text = gsub(text, 'ṁ([ṭḍṇ])', 'ṇ%1')
	text = gsub(text, 'ṁ([tdn])', 'n%1')
	text = gsub(text, 'ṁ([pbm])', 'm%1')

	text = gsub(text, 'rr̥', 'r̥') -- 𑴦𑴶 is independent r̥
	text = gsub(text, '𑵆', 'r') -- repha

	text = gsub(text, '[ea]̃', 'ĕ') -- <ऍ> ĕ independent and dependent
	text = gsub(text, 'ā̃', 'ŏ') -- <ऑ> ŏ independent and dependent
	
	return text
end
 
return export