Module:mr-Modi-translit

Hello, you have come here looking for the meaning of the word Module:mr-Modi-translit. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:mr-Modi-translit, but we will also tell you about its etymology, its characteristics and you will know how to say Module:mr-Modi-translit in singular and plural. Everything you need to know about the word Module:mr-Modi-translit you have here. The definition of the word Module:mr-Modi-translit will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:mr-Modi-translit, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module will transliterate Marathi language text per WT:MR TR. It is also used to transliterate Varhadi. 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:mr-Modi-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 u = require("Module:string/char")
local gsub = mw.ustring.gsub
local find = mw.ustring.find

local ZWJ = u(0x200D)

local conv = {
	-- 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',
	 = 'r',
	--  = 'dny',

	-- vowel diacritics
	----  only in script charts:  = 'i',  ='ū',
	 = 'u',  = 'e',  = 'o', 
	 = 'ā',  = 'ī',
	 = 'ru',
	 = 'ai',  = 'au',
	--  = 'ŏ',
	 = 'ĕ',

	-- vowel signs
	----  only in script charts:  = 'i',  ='ū',
	 = 'a',  = 'u',  = 'e',  = 'o',
	 = 'ā',  = 'ī',
	 = 'ŕ', 
	 = 'ai',  = 'au', 
	 = 'ŏ',
	 = 'ĕ',  = 'ĕ',
	
	 = 'om',
	
	-- chandrabindu
	---  = '̃',
	
	-- anusvara
	 = 'ṁ',
	
	-- visarga
	 = 'ḥ',
	
	-- virama
	 = '',
	
	-- numerals
	 = '0',  = '1',  = '2',  = '3',  = '4',
	 = '5',  = '6',  = '7',  = '8',  = '9',
	
	-- punctuation
	 = '.', -- danda
	 = '.', -- double danda
	 = '', -- compound separator
	
	-- abbreviation sign
	 = '.',
}

local nasal_assim = {
	 = '𑘒',  = '𑘒',  = '𑘒',  = '𑘒', 
	 = '𑘗',  = '𑘗',  = '𑘗',  = '𑘗',  
	 = '𑘜',  = '𑘜',  = '𑘜',  = '𑘜',
	 = '𑘦',  = '𑘦',  = '𑘦',  = '𑘦',  = '𑘦',
	 = 'i',  = '𑘄',  = '𑘩',  = '𑘄',
	 = '𑘄',  = '𑘄',  = '𑘄',  = '𑘄',
}

local perm_cl = {
	 = true,  = true,  = true,
	
}

local all_cons, special_cons = '𑘎𑘏𑘐𑘑𑘒𑘓𑘔𑘕𑘖𑘗𑘘𑘙𑘚𑘛𑘝𑘞𑘟𑘠𑘢𑘣𑘤𑘥𑘫𑘬𑘭𑘧𑘨𑘩𑘪𑘮𑘜𑘡𑘦𑘯', '𑘟𑘝𑘧𑘨𑘩𑘪𑘮𑘡𑘦'
local vowel, vowel_sign = '%*a𑘱𑘳𑘵𑘹𑘻𑘰𑘲𑘴𑘺𑘼𑙀', '𑘀𑘂𑘄𑘊𑘌𑘁𑘃𑘅𑘆𑘋𑘍𑘀𑙀'
local syncope_pattern = '()()a()(?)'

local function rev_string(text)
	local char_array, i = {}, 1
	for char in string.gmatch(text, "*") do -- UTF-8 character pattern
		char_array = char
		i = i + 1
	end
	return table.concat(require("Module:table").reverse(char_array))
end

function export.tr(text, lang, sc)
	-- text = gsub(text, 'ाँ', 'ॉ' .. 'ं')
	-- text = gsub(text, 'ँ', 'ॅ' .. 'ं')
	text = gsub(text, '()𑘽 ', '%1𑘀 ')
	text = gsub(text, '()𑘽$', '%1𑘀')
	text = gsub(text, '()(?)', function(c, d)
		return c .. (d == "" and 'a' or d) end)
	for word in mw.ustring.gmatch(text, "+") do
		local orig_word = word
		word = rev_string(word)
		word = gsub(word, '^a()', '%1')
		while find(word, syncope_pattern) do
			word = gsub(word, syncope_pattern, '%1%2%3%4')
		end
		word = gsub(word, '(.?)𑘽(.)', function(succ, prev)
			return succ .. (succ..prev == "a" and "𑘿𑘦" or 
				(succ == "" and find(prev, '') and "̃" or nasal_assim or "n")) .. prev end)
		text = gsub(text, orig_word, rev_string(word))
	end
	text = gsub(text, '.', conv)
	text = gsub(text, 'a()̃', 'a͠%1')
	text = gsub(text, 'aa', 'a')
    text = gsub(text, 'ñjñ', 'ndny')
    text = gsub(text, 'jñ', 'dny')
	return mw.ustring.toNFC(text)
end

return export