Module:or-translit

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

This module will transliterate Odia language text. It is also used to transliterate Sambalpuri. 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:or-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 consonants = {
	--common
	["କ"]="k", ["ଖ"]="kh", ["ଗ"]="g", ["ଘ"]="gh", ["ଙ"]="ṅ",
	["ଚ"]="c", ["ଛ"]="ch", ["ଜ"]="j", ["ଝ"]="jh", ["ଞ"]="ñ", 
	["ଟ"]="ṭ", ["ଠ"]="ṭh", ["ଡ"]="ḍ", ["ଢ"]="ḍh", ["ଣ"]="ṇ", 
	["ତ"]="t", ["ଥ"]="th", ["ଦ"]="d", ["ଧ"]="dh", ["ନ"]="n", 
	["ପ"]="p", ["ଫ"]="ph", ["ବ"]="b", ["ଭ"]="bh", ["ମ"]="m",
	["ଯ"]="j", ["ୟ"]="y", ["ର"]="r", ["ଲ"]="l", ["ଳ"]="ḷ",
	["ଵ"]="v", ["ୱ"]="w", ["ଶ"]="ś", ["ଷ"]="sh", ["ସ"]="s", ["ହ"]="h",
	--nuktas
   	["କ଼"]="k", ["ଖ଼"]="kh", ["ଗ଼"]="g", ["ଜ଼"]="j", ["ଝ଼"]="jh", ["ଫ଼"]="ph",
	["ଡ଼"]="ṛ", ["ଢ଼"]="ṛh",
}

local diacritics = {
	["ା"]="ā", ["ି"]="i", ["ୀ"]="i", ["ୁ"]="u", ["ୂ"]="u", ["ୃ"]="ru", ["ୄ"]="ru", 
	["ୢ"]="lu", ["ୣ"]="lu", ["େ"]="e", ["ୈ"]="ai", ["ୖ"]="ai", ["ୋ"]="o", ["ୌ"]="au", ["ୗ"]="au",
	["୍"]="",
}

local tt = {
	-- vowels
	["ଅ"]="a", ["ଆ"]="ā", ["ଇ"]="i", ["ଈ"]="i", ["ଉ"]="u", ["ଊ"]="u", ["ଋ"]="ru", ["ୠ"]="ru",
	["ଌ"]="lu", ["ୡ"]="lu", ["ଏ"]="e", ["ଐ"]="ai", ["ଓ"]="o", ["ଔ"]="au", 
	-- chandrabindu    
	["ଁ"]="̃", --until a better method is found
	-- anusvara    
	["ଂ"]="ṁ", --until a better method is found
	-- visarga    
	["ଃ"]="ḥ",
	-- avagraha
	["ଽ"]="’",
	--numerals
	["୦"]="0", ["୧"]="1", ["୨"]="2", ["୩"]="3", ["୪"]="4", ["୫"]="5", ["୬"]="6", ["୭"]="7", ["୮"]="8", ["୯"]="9",
	["୲"]="¼", ["୳"]="½", ["୴"]="¾", ["୵"]="¹⁄₁₆", ["୶"]="⅛", ["୷"]="³⁄₁₆",
	--punctuation        
	["।"]=".", --danda
}

function export.tr(text, lang, sc)
	text = mw.ustring.gsub(
		text,
		"([କଖଗଘଙଚଛଜଝଞଟଠଡଢଣତଥଦଧନପଫବଵଭମଯୟରଲଳୱଶଷସହ]଼?)"..
		"([ାିୀୁୂୃୄେୈୖୋୌୗ୍ୢୣ]?)",
		function(c, d)
			if not consonants[c] then
				return c
			end
			if d == "" then
				return consonants[c] .. "a"
			else
				return consonants[c] .. diacritics[d]
			end
		end)

	text = mw.ustring.gsub(text, ".", tt)
	
	-- anusvara
	text = mw.ustring.gsub(text, 'ṁ([kqxgġṅ])', 'ṅ%1')
	text = mw.ustring.gsub(text, 'ṁ([cjźñ])', 'ñ%1')
	text = mw.ustring.gsub(text, 'ṁ([ṭḍṇ])', 'ṇ%1')
	text = mw.ustring.gsub(text, 'ṁ([tdnz])', 'n%1')
	text = mw.ustring.gsub(text, 'ṁ([pfbm])', 'm%1')
	
	return text
end
 
return export