Module:Deva-Telu-translit

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

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-Telu-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, nakaaraPollu, archaicLlla, archaicRra)
	local UTF8_char = "[%z\1-\127\194-\244][\128-\191]*"
	local Telu = require("Module:scripts").getByCode("Telu")
	text = mw.ustring.toNFD(text)
	
	text = string.gsub(text, UTF8_char, char)
	
	-- Nakaara Pollu is used in Sanskrit.
	if nakaaraPollu or lang == "sa" then
		text = mw.ustring.gsub(text, "న్([^క-హౘ-ౚౝ])", "ౝ%1")
		text = mw.ustring.gsub(text, "న్$", "ౝ")
	end
	
	if archaicLlla then
		text = mw.ustring.gsub(text, "ళ఼", "ఴ")
	end
	
	if archaicRra then
		text = mw.ustring.gsub(text, "ర఼", "ఱ")
	end
	
	text = mw.ustring.toNFC(text)
	local reducedText = mw.ustring.gsub(mw.ustring.gsub(text, "<.->", ""), "[%s%p\n]+", "")
	if (mw.ustring.len(reducedText) == Telu:countCharacters(reducedText) and not mw.ustring.find(text, "಼಼")) or override then
		return text
	else
		return nil
	end
end

return export