Mô đun:Deva-Knda-translit

Từ điển mở Wiktionary
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 Knda = require("Module:scripts").getByCode("Knda")
	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) == Knda:countCharacters(reducedText) and not mw.ustring.find(text, "಼಼")) or override then
		return text
	else
		return nil
	end
end

return export