47,726
edits
![]() | We're back! Sorry, bad combo of sickness, funeral and a month-long trip abroad. The site is back now. ![]() |
Chrysophylax (talk | contribs) (Created page with "local export = {} function export.exists(frame) local args = frame.args local lang = args[1] or error("Language code has not been specified. Please pass parameter 1 to the...") |
No edit summary |
||
Line 19: | Line 19: | ||
-- * [[WT:NEC]] | -- * [[WT:NEC]] | ||
function export.getByCode(frame) | function export.getByCode(frame) | ||
local | local iparams = { | ||
[1] = {required = true}, | |||
[2] = {required = true}, | |||
[3] = {}, | |||
[4] = {}, | |||
[5] = {}, | |||
} | |||
local | local iargs = require("Module:parameters").process(frame.args, iparams) | ||
local langcode = iargs[1] | |||
local lang = require("Module:languages").getByCode(langcode, true) | |||
return require("Module:language-like").templateGetByCode(lang, iargs, | |||
function(itemname) | |||
local list | |||
if itemname == "getWikimediaLanguages" then | |||
list = lang:getWikimediaLanguages() | |||
elseif itemname == "getScripts" then | |||
list = lang:getScriptCodes() | |||
elseif itemname == "getAncestors" then | |||
list = lang:getAncestors() | |||
end | |||
if list then | |||
local index = iargs[3] | |||
index = tonumber(index) or error("Please specify the numeric index of the desired item.") | |||
local retval = list[index] | |||
if retval then | |||
if type(retval) == "string" then | |||
return retval | |||
else | |||
return retval:getCode() | |||
end | |||
else | |||
return "" | |||
end | |||
end | |||
if itemname == "transliterate" then | |||
local text = iargs[3] | |||
local sc = iargs[4] | |||
local module_override = iargs[5] | |||
sc = require("Module:scripts").getByCode(sc, 4) | |||
return lang:transliterate(text, sc, module_override) or "" | |||
elseif itemname == "makeEntryName" then | |||
local text = iargs[3] | |||
return lang:makeEntryName(text) or "" | |||
elseif itemname == "makeSortKey" then | |||
local text = iargs[3] | |||
return lang:makeSortKey(text) or "" | |||
elseif itemname == "countCharacters" then | |||
local text = args[3] or "" | |||
local sc = require("Module:scripts").getByCode(iargs[4], 4, "disallow nil") | |||
return sc:countCharacters(text) | |||
end | |||
end | end | ||
) | |||
end | end | ||