模組:Deva-as-Beng-translit


This module will transliterate text in the 天城文. 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-as-Beng-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.
-- If noKhandaTa is set, then "ৎ" will not be contextually substituted for "ত্", which is suitable (e.g.) for Sanskrit transliteration.
function export.tr(text, lang, sc, override, noKhandaTa)
	local UTF8_char = "[%z\1-\127\194-\244][\128-\191]*"
	local asBeng = require("Module:scripts").getByCode("as-Beng")
	text = mw.ustring.toNFD(text)
	
	text = string.gsub(text, UTF8_char, char)
	text = require("Module:Deva-Beng-translit").tr(text, lang, sc, true, noKhandaTa)
	
	-- Khanda Ta is not used in Sanskrit.
	if not noKhandaTa and lang ~= "sa" then
		text = mw.ustring.gsub(text, "ৎ(ৰ)", "ত্%1")
	end
	
	local reducedText = mw.ustring.gsub(mw.ustring.gsub(text, "<.->", ""), "[%s%p\n]+", "")
	if (mw.ustring.len(reducedText) == asBeng:countCharacters(reducedText) and not mw.ustring.find(text, "়়")) or override then
		return text
	else
		return nil
	end
end

return export