Module:User:Erutuon/tools

Hello, you have come here looking for the meaning of the word Module:User:Erutuon/tools. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:User:Erutuon/tools, but we will also tell you about its etymology, its characteristics and you will know how to say Module:User:Erutuon/tools in singular and plural. Everything you need to know about the word Module:User:Erutuon/tools you have here. The definition of the word Module:User:Erutuon/tools will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:User:Erutuon/tools, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

The functions script and translit output parameters that can be used in {{t-simple}}.

Testcases

  • {{#invoke:User:Erutuon/tools|script|sh|Hrvatoslav}}
    Lua error at line 29: attempt to call upvalue 'getScript' (a nil value)
  • {{#invoke:User:Erutuon/tools|script|sh|Хрватослав}}
    Lua error at line 29: attempt to call upvalue 'getScript' (a nil value)
  • {{#invoke:User:Erutuon/tools|translit|grc|Περικλῆς}}
    Lua error at line 48: attempt to call upvalue 'getScript' (a nil value)

local export = {}

local getScript = require("Module:scripts").findBestScript

local function getArgs(frame)
	local params = {
		 = { required = true },
		 = { required = true },
	}
	
	local args = require("Module:parameters").process(frame.args, params)
	
	local langCode = args
	local text = args
	
	return langCode, text
end

local function getLang(langCode)
	return require("Module:languages").getByCode(langCode) or require("Module:languages").err(langCode, 1)
end

function export.script(frame)
	local langCode, text = getArgs(frame)
	
	local lang = getLang(langCode)
	local sc
	if lang then
		sc = getScript(text, lang)
	end
	
	local dontReturn = {
		None = true,
		Latn = true,
	}
	
	if sc and not dontReturn then
		return "|sc=" .. sc:getCode()
	end
end

function export.translit(frame)
	local langCode, text = getArgs(frame)
	
	local lang = getLang(langCode)
	local translit
	if lang then
		local sc = getScript(text, lang)
		translit = lang:transliterate(text, sc)
	end
	
	if translit then
		return "|tr=" .. translit
	end
end

return export