Module:ne-translit

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

This module will transliterate Nepali language text per WT:NE TR. It is also used to transliterate Doteli. 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:ne-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.

-- Transliteration for Nepali
local export = {}

local m_str_utils = require("Module:string utilities")

local gmatch = m_str_utils.gmatch
local gsub = m_str_utils.gsub
local match = m_str_utils.match
local reverse = m_str_utils.reverse
local toNFC = mw.ustring.toNFC

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',  = 'w',
	 = 'ś',  = 'ṣ',  = 's',  = 'h',

	 = 'q',  = 'x',  = 'ġ',  = 'ḻ',
	 = 'ḷ',  = 'z',  = 'ž',  = 'ž',
	 = 'ṛ',  = 'ṛh',  = 'f',  = 'θ',
	 = 'ð',  = 'ṉ',  = 'ṟ',  = "'",
	 = 'V',  = 'ž',
	-- vowel diacritics
	 = 'i',  = 'u',  = 'e',  = 'o',  = 'ā',  = 'ī',  = 'ū',  = 'r̥',
	 = 'r̥̄',  = 'l̥',  = 'l̥̄',  = 'ai',  = 'au',  = 'ŏ',  = 'ĕ',
	-- vowel signs
	 = 'a',  = 'i',  = 'u',  = 'e',  = 'o',  = 'ā',  = 'ī',  = 'ū',
	 = 'r̥',  = 'r̥̄',  = 'l̥',  = 'l̥̄',  = 'ai',  = 'au',  = 'ŏ',
	 = 'ĕ',  = 'ĕ',
	-- chandrabindu
	 = '̃',
	-- anusvara
	 = '̃',
	-- visarga
	 = 'ḥ',
	-- virama
	 = '',
	-- om
	 = 'om̐',
	-- zero-width non joiner
	 = '',
	-- zero-width joiner
	 = 'a',
	-- numerals
	 = '0',  = '1',  = '2',  = '3',  = '4',  = '5',  = '6',  = '7',
	 = '8',  = '9',
	-- punctuation
	 = '.', -- danda
	 = '.', -- double danda
	 = '', -- compound separator

	-- abbreviation sign
	 = '.',
}

local nasal_assim = {
	 = 'ङ',  = 'ङ',  = 'ङ',  = 'ङ',
	 = 'ञ',  = 'ञ',  = 'ञ',  = 'ञ',
	 = 'ण',  = 'ण',  = 'ण',  = 'ण',
	 = 'म',  = 'म',  = 'म',  = 'म',  = 'म',
	 = 'न',  = 'न',  = 'न',  = 'न',  = 'न',  = 'न',  = 'ङ',
	 = 'न',
	 = 'म',  = 'म',  = 'ँ',  = 'म',  = 'ङ',
}
local perm_cl = {
	 = true,  = true,  = true,  = true,  = true,
	 = true,  = true
}

local all_cons, special_cons = 'कखगघङचछजझञटठडढणतथदधनपफबभमयरलवसशषह'
	, 'कखगघचछजझटठडढणतथदधनपफबभमयरलवशषसह'
local vowel, vowel_sign = 'aिुृेोाीूैौॉॅॆॊॄॢॣ', 'अइउएओआईऊऋॠॡऌऐऔऑऍ'
local syncope_pattern = '(़?[' ..
	all_cons ..
	'])(?[' ..
	vowel ..
	vowel_sign ..
	'])(़?[' ..
	all_cons ..
	'])(?[' ..
	vowel ..
	vowel_sign ..
	'])(़?[' ..
	all_cons ..
	'])a(़?[' ..
	all_cons .. '])(?)(़?[' ..
	all_cons .. '])(?)'

local nor_cons, sp_cons = 'कखगघङचछजझञटठडढतथदधपफबभशषसयरलवणनमयरलवनम'
	, 'कलम'
local vowel, vowel_sign = 'aिुृेोाीूैौॉॅॆॊॄॢॣ', 'अइउएओआईऊऋॠॡऌऐऔऑऍ'
local koka_sign = 'ोीाैे'
local koka_pattern = '([' ..
	koka_sign .. '])(़?)a(़?[' ..
	gsub(nor_cons, "य", "") .. '])(?)'

function export.tr(text, lang, sc)
	text = gsub(text, '(़?)(?)', function(c, d)
		return c .. (d == "" and 'a' or d)
	end)
	for word in gmatch(text, "+") do
		local orig_word = word
		word = reverse(word)
		word = gsub(word, '^a(़?)()(.)(.?)', function(opt, first, second, third)
			return (((match(first, '') and match(second, 'ं')
				or match(first, '') and match(second, '्') and not perm_cl)
				or match(first .. second, 'य') or
				match(first .. second, 'ह'))
				and 'a' or "") .. opt .. first .. second .. third
		end)

		while match(word, syncope_pattern) do
			word = gsub(word, syncope_pattern, '%1%2%3%4%5%6%7%8%9')
		end
		while match(word, koka_pattern) do

			word = gsub(word, koka_pattern, '%1%2%3%4')
		end
		word = gsub(word, '(.?)ं(.)', function(succ, prev)
			return succ .. (succ .. prev == "a" and "्म" or
				(succ == "" and match(prev, '') and "̃" or nasal_assim or "ṃ")) .. prev
		end)
		
		text = gsub(text, orig_word, reverse(word))
		text = gsub(text, 'ँ?%f', '%0a')
		text = gsub(text, 'बाट%f', 'bāṭa')
		text = gsub(text, 'ज्ञ', 'gy')
	end
	text = gsub(text, '.़?', conv)
	text = gsub(text, 'a()̃', 'a͠%1')
	text = gsub(text, "", "")
	text = gsub(text, "ॱ", "")

	text = gsub(text, 'dach%f', 'dacha')
	text = gsub(text, 'ain%f', 'aina')
	text = gsub(text, 'nach%f', 'nacha')
	text = gsub(text, 'wai', 'vai')
	text = gsub(text, 'w%f', 'v')
	text = gsub(text, '(r)w', '%1v')
	text = gsub(text, 'w()', 'v%1')
	text = gsub(text, 'w(̥̄?)', 'v%1')
	text = gsub(text, 'w(a)', 'v%1')
	text = gsub(text, 'w(ā)', 'v%1')
	text = gsub(text, 'w(ār)', 'v%1')
	text = gsub(text, 'w(ālm)', 'v%1')
	text = gsub(text, 'w(a)', 'v%1')
	text = gsub(text, 'rh̥', 'hr̥')
	---text = gsub(text, 'kṣ', 'ch̥')
	text = gsub(text, 'a(har)', '%1')
	text = gsub(text, 'abāṭa', 'bāṭa')

	text = gsub(text, 'kan%f', 'kana')
	text = gsub(text, '()(har)', '%1a%2')
	text = gsub(text, '()bāṭa', '%1abāṭa')
	text = gsub(text, '()()', '%1a%2')
	text = gsub(text, 'ñz', 'nz')
	text = gsub(text, 'ñgy', 'ṅgy')
	text = gsub(text, 'ãla', 'amla') -- assim case l
	text = gsub(text, '()mm', '%1ṃm') -- assim case m
	text = gsub(text, 'a()mm', 'a͠%1m') -- assim case m2
	text = gsub(text, '()n()', '%1ṃ%2') -- assim case s
	text = gsub(text, 'a()n()', 'a͠%1%2') -- assim case s2
	text = gsub(text, 'a()ṅ()', 'a͠%1%2') -- assim case kh
	text = gsub(text, '()ṅ()', '%1ṃ%2') -- assim case kh2
	return toNFC(text)
end

return export