Module:translit-redirect: Difference between revisions

From Linguifex
Jump to navigation Jump to search
(Created page with "local export = {} function export.tr(text, lang, sc, debug_mode) if not sc then sc = require("Module:scripts").findBestScript(text, require("Module:languages").getByCode(l...")
 
No edit summary
 
Line 24: Line 24:
end
end
else
else
require("Module:debug").track{
"translit-redirect/incorrect-script/" .. lang,
"translit-redirect/incorrect-script/" .. lang .. "/" .. sc,
}
mw.log("script code (" .. sc .. ") for language code " .. lang .. " not found in Module:translit-redirect/data; text: " .. text)
mw.log("script code (" .. sc .. ") for language code " .. lang .. " not found in Module:translit-redirect/data; text: " .. text)
end
end

Latest revision as of 19:35, 15 October 2021



local export = {}

function export.tr(text, lang, sc, debug_mode)
	if not sc then
		sc = require("Module:scripts").findBestScript(text, require("Module:languages").getByCode(lang)):getCode()
	end
	
	local language_data = mw.loadData("Module:translit-redirect/data")[lang]
	
	if language_data then
		local script_data = language_data[sc]
		
		if script_data then
			if script_data.module then
				local success, translit_module = pcall(require, "Module:" .. script_data.module)
			
				if success then
					return translit_module.tr(text, lang, sc, debug_mode)
				else
					error(translit_module)
				end
			else
				return nil
			end
		else
			mw.log("script code (" .. sc .. ") for language code " .. lang .. " not found in Module:translit-redirect/data; text: " .. text)
		end
	end
end

return export