Module:Tirh-Deva-translit

From Linguifex
Jump to navigation Jump to search

Documentation for this module may be created at Module:Tirh-Deva-translit/doc

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