Module:translit-redirect

Definition from Wiktionary, the free dictionary
Jump to: navigation, search

local export = {}

local data = {
	["pa"] = {
		["debug_mode"] = true,
		["Guru"] = {
			["module"] = "Guru-translit",
		},
		["Deva"] = {
			["module"] = "sa-translit",
		},
		["Arab"] = {
--			["module"] = "pa-Arab-translit",
		},
		["pa-Arab"] = {
--			["module"] = "pa-Arab-translit",
		},
		["error"] = "Invalid script for Punjabi language.",
	},
	["khb"] = {
		["Talu"] = {
			["module"] = "Talu-translit",
		},
		["Lana"] = {
--			["module"] = "Lana-translit",
		},
		["Thai"] = {
		},
		["error"] = "Invalid script for Lü language.",
	}
}

function export.tr(text, lang, sc, debug_mode)
	local translit
	
	local language_data = data[lang:getCode()]
	
	if language_data then
		script_data = language_data[script:getCode()]
		
		if script_data then
			local success, translit_module = pcall(require, "Module:" .. script_data.module)
			
			if success then
				translit = translit_module.tr(text, lang, sc, debug_mode)
			else
				error(translit_module)
			end
		else
			error(language_data.error)
		end
	end

	return translit
end

return export