Module:new-translit

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

This module will transliterate Newar 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:new-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 Newar

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",  = "w",  = "ḷ",
	 = "ś",  = "ṣ",  = "s",  = "h",  = "ḻ",  = "ॽ",
	-- 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",  = "ô",  = "â",  = "â",
	-- ZWNJ
	 = "",
	-- ZWJ
	 = "", -- chandrabindu
	 = "̃",
	-- anusvara
	 = "ṃ",
	-- visarga (liphuti)
	 = ":",
	-- virama
	 = "",
	-- om
	 = "oḥm",
	-- avagraha
	 = "’",
	-- 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
}

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

local function rev_string(text)

	local result, length = {}, mw.ustring.len(text)
	for i = length, 1, -1 do
		table.insert(result, mw.ustring.sub(text, i, i))
	end
	return table.concat(result)

end

function export.tr(text, lang, sc)

	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(़?)()(.)(.?)",
			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 "a") ..
					opt .. first .. second .. third
			end
		)

		word = gsub(word, "(.?)ं(.)",
			function(succ, prev)
				return succ .. (succ .. prev == "" and "्म" or
					(succ == "" and match(prev, "") and "ṃ" or nasal_assim or "ṃ")) .. prev
			end
		)

		local escaped_orig_word = gsub(orig_word, "%+", "")
		text = gsub(text, orig_word, rev_string(word))
		text = gsub(text, "आँय्", "æ̃")
		text = gsub(text, "आंय्", "æ̃")
		text = gsub(text, "आय्", "æ")
		text = gsub(text, "ाँय्", "æ̃")
		text = gsub(text, "ांय्", "æ̃")
		text = gsub(text, "ाय्", "æ")
		text = gsub(text, "अँय्", "ễ")
		text = gsub(text, "अंय्", "ễ")
		text = gsub(text, "अय्", "ê")
		text = gsub(text, "य्", "ê")
	end
	text = gsub(text, ".़?", conv)
	text = gsub(text, "a()̃", "a͠%1")

	text = gsub(text, "()()()ê", "%1%2%3ê")
	text = gsub(text, "()()()ễ", "%1%2%3ễ")
	text = gsub(text, "()()̃ê", "%1ễ")
	text = gsub(text, "()()ê", "%1ê")

	text = gsub(text, "", "")
	return mw.ustring.toNFC(text)

end

return export