Module:gu-translit

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

This module will transliterate Gujarati language text per WT:GU TR. It is also used to transliterate Kachchi and Vaghri. 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:gu-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 match = mw.ustring.match

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',
	 = 't̰',  = 'z',  = 'ng',  = 'ṛ',  = 'ṛh',  = 'ṉ',  = 'f',

	--vowel diacritics
	 = 'ā',  = 'i',  = 'ī',  = 'u',  = 'ū',  = 'ŕ',  = 'ṝ', 
	 = 'e',  = 'ai',  = 'o',  = 'au',  = 'ě',  = 'ŏ',

	-- vowel mātras
	 = 'a',  = 'ā',  = 'i',  = 'ī',  = 'u',  = 'ū',  = 'ŕ',  = 'ṝ',
	 = 'e',  = 'ai',  = 'o',  = 'au',  = 'ě',  = 'ŏ',

	-- chandrabindu    
	 = 'm̐', --until a better method is found

	-- anusvara    
	 = 'ṃ', --until a better method is found

	-- visarga
	 = 'ḥ',

	-- virama
	 = '', 

	-- avagraha
	 = '’',

	--numerals
	 = '0',  = '1',  = '2',  = '3',  = '4',  = '5',  = '6',  = '7',  = '8',  = '9',

	--punctuation        
	 = '.', --danda
	 = '', -- compound separator
	
	--om
	 = 'OM',
}

local nasal_assim = {
	h?"] = "ṅ",
	h?"] = "ñ",
	h?"] = "ṇ",
	h?"] = "n",
	h?"] = "m",
	 = "n",
	 = "m",
}

function export.tr(text, lang, sc)
	local c = '(઼?)'
	local no_drop = 'ય'
	local final_no_drop = 'યરલવહનમ'
	local v = '(ઁ?)'
	local virama = '(્)'
	local n = '(ં?)'
	local nukta = '(઼)'
	
	local can_drop = gsub(c,"","")
	local final_can_drop = gsub(c,"","")
	local no_virama = gsub(v,virama,"")
	
	text = text .. " "
	
	--text = gsub(text,"(%S)"..c.."%2","%1ː%2")
	
	text = gsub(text,c,"%1a")
	text = gsub(text,"a"..v,"%1")
	text = gsub(text,no_virama..n..can_drop.."a ","%1%2%3 ") --ending
	text = gsub(text,virama..n..final_can_drop.."a ","%1%2%3 ") --ending
	local pattern = no_virama..n..can_drop.."a"..c..no_virama
	while match(text,"(.*)"..pattern) do
		text = gsub(text,"(.*)"..pattern,"%1%2%3%4%5%6")
	end
	
	text = gsub(text,nukta,conv)
	text = gsub(text,".",conv)
	
	for key,val in pairs(nasal_assim) do
		text = gsub(text,"()ṃ("..key..")", "%1"..val.."%2")
	end
	
	text = gsub(text,"()ṃ", "%1̃")
	
	text = gsub(text,"ː(.)","%1%1")
	
	text = gsub(text," $","")
	
	text = gsub(text,"ā̃tar","āntar")
	
	text = gsub(text,"OM","oṃ")
    text = gsub(text, 'a*%*a*', 'a')
	
	return mw.ustring.toNFC(text)
end

return export