Module:Deva-Tirh-translit

This module will transliterate text in the Devanagari script. 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:Deva-Tirh-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 char = {
	["क"] = "𑒏", ["ख"] = "𑒐", ["ग"] = "𑒑", ["घ"] = "𑒒", ["ङ"] = "𑒓", ["च"] = "𑒔", ["छ"] = "𑒕", ["ज"] = "𑒖", ["झ"] = "𑒗", ["ञ"] = "𑒘", ["ट"] = "𑒙", ["ठ"] = "𑒚", ["ड"] = "𑒛", ["ढ"] = "𑒜", ["ण"] = "𑒝", ["त"] = "𑒞", ["थ"] = "𑒟", ["द"] = "𑒠", ["ध"] = "𑒡", ["न"] = "𑒢", ["प"] = "𑒣", ["फ"] = "𑒤", ["ब"] = "𑒥", ["भ"] = "𑒦", ["म"] = "𑒧", ["य"] = "𑒨", ["र"] = "𑒩", ["ल"] = "𑒪", ["ळ"] = "𑒪𑓃", ["व"] = "𑒫", ["श"] = "𑒬", ["ष"] = "𑒭", ["स"] = "𑒮", ["ह"] = "𑒯",
	["अ"] = "𑒁", ["आ"] = "𑒂", ["इ"] = "𑒃", ["ई"] = "𑒄", ["उ"] = "𑒅", ["ऊ"] = "𑒆", ["ऋ"] = "𑒇", ["ॠ"] = "𑒈", ["ऌ"] = "𑒉", ["ॡ"] = "𑒊", ["ऎ"] = "𑒁𑒺", ["ए"] = "𑒋", ["ऐ"] = "𑒌", ["ऒ"] = "𑒁𑒽", ["ओ"] = "𑒍", ["औ"] = "𑒎",
	["ा"] = "𑒰", ["ि"] = "𑒱", ["ी"] = "𑒲", ["ु"] = "𑒳", ["ू"] = "𑒴", ["ृ"] = "𑒵", ["ॄ"] = "𑒶", ["ॢ"] = "𑒷", ["ॣ"] = "𑒸", ["ॆ"] = "𑒺", ["े"] = "𑒹", ["ै"] = "𑒻", ["ॊ"] = "𑒽", ["ो"] = "𑒼", ["ौ"] = "𑒾", ["्"] = "𑓂",
	["ं"] = "𑓀", ["ः"] = "𑓁", ["ँ"] = "𑒿", ["़"] = "𑓃", ["ऽ"] = "𑓄", ["ॐ"] = "𑓇", ["॰"] = "𑓆",
	["०"] = "𑓐", ["१"] = "𑓑", ["२"] = "𑓒", ["३"] = "𑓓", ["४"] = "𑓔", ["५"] = "𑓕", ["६"] = "𑓖", ["७"] = "𑓗", ["८"] = "𑓘", ["९"] = "𑓙"
}

-- Override returns text even if some characters cannot be transliterated.
function export.tr(text, lang, sc, override)
	local UTF8_char = "[%z\1-\127\194-\244][\128-\191]*"
	local Tirh = require("Module:scripts").getByCode("Tirh")
	
	text = string.gsub(text, UTF8_char, char)
	
	local reducedText = mw.ustring.gsub(mw.ustring.gsub(text, "<.->", ""), "[%s%p\n]+", "")
	if (mw.ustring.len(reducedText) == Tirh:countCharacters(reducedText) and not mw.ustring.find(text, "𑓃𑓃")) or override then
		return text
	else
		return nil
	end
end

return export