The functions script
and translit
output parameters that can be used in {{t-simple}}
.
{{#invoke:User:Erutuon/tools|script|sh|Hrvatoslav}}
{{#invoke:User:Erutuon/tools|script|sh|Хрватослав}}
{{#invoke:User:Erutuon/tools|translit|grc|Περικλῆς}}
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