Module:Tirh-Deva-translit

This module will transliterate text in the Tirhuta 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:Tirh-Deva-translit/testcases.

Functions

edit
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 twoChars = {
	["𑒏𑓃"] = "क़", ["𑒐𑓃"] = "ख़", ["𑒑𑓃"] = "ग़", ["𑒖𑓃"] = "ज़", ["𑒛𑓃"] = "ड़", ["𑒜𑓃"] = "ढ़", ["𑒤𑓃"] = "फ़", ["𑒨𑓃"] = "य़", ["𑒪𑓃"] = "ळ",
	["𑒁𑒺"] = "ऎ", ["𑒁𑒽"] = "ऒ"
}

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

-- 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 Deva = require("Module:scripts").getByCode("Deva")
	
	for digraph, replacement in pairs(twoChars) do
		text = string.gsub(text, digraph, replacement)
	end
	
	text = string.gsub(text, UTF8_char, oneChar)
	
	local reducedText = mw.ustring.gsub(mw.ustring.gsub(text, "<.->", ""), "[%s%p\n]+", "")
	if mw.ustring.len(reducedText) == Deva:countCharacters(reducedText) or override then
		return text
	else
		return nil
	end
end

return export