|
|
| Line 19: |
Line 19: |
| -- * [[WT:NEC]] | | -- * [[WT:NEC]] |
| function export.getByCode(frame) | | function export.getByCode(frame) |
| local args = frame.args | | local iparams = { |
| local langcode = args[1] or error("Language code has not been specified. Please pass parameter 1 to the module invocation.")
| | [1] = {required = true}, |
| local itemname = args[2] or error("Type of information to look up has not been specified. Please pass parameter 2 to the module invocation.")
| | [2] = {required = true}, |
| | [3] = {}, |
| | [4] = {}, |
| | [5] = {}, |
| | } |
| | | |
| local lang = require("Module:languages").getByCode(langcode) | | local iargs = require("Module:parameters").process(frame.args, iparams) |
| | local langcode = iargs[1] |
| | | |
| if not lang then | | local lang = require("Module:languages").getByCode(langcode, true) |
| error("The language code '" .. langcode .. "' is not valid.")
| |
| end
| |
| | | |
| | | return require("Module:language-like").templateGetByCode(lang, iargs, |
| -- The item that the caller wanted to look up
| | function(itemname) |
|
| | local list |
| if itemname == "getOtherNames" then
| | if itemname == "getWikimediaLanguages" then |
| local index = args[3]; if index == "" then index = nil end
| | list = lang:getWikimediaLanguages() |
| index = tonumber(index) or error("Please specify the numeric index of the desired name.")
| | elseif itemname == "getScripts" then |
| return lang:getOtherNames()[index] or ""
| | list = lang:getScriptCodes() |
| elseif itemname == "getFamily" then
| | elseif itemname == "getAncestors" then |
| return lang:getFamily():getCode()
| | list = lang:getAncestors() |
| elseif itemname == "getWikimediaLanguages" then
| | end |
| local index = args[3]; if index == "" then index = nil end
| | if list then |
| index = tonumber(index) or error("Please specify the numeric index of the desired language.")
| | local index = iargs[3] |
| local langs = lang:getWikimediaLanguages()
| | index = tonumber(index) or error("Please specify the numeric index of the desired item.") |
|
| | local retval = list[index] |
| if langs[index] then
| | if retval then |
| return langs[index]:getCode() | | if type(retval) == "string" then |
| else
| | return retval |
| return "" | | else |
| end
| | return retval:getCode() |
| elseif itemname == "getScripts" then
| | end |
| local index = args[3]; if index == "" then index = nil end
| | else |
| index = tonumber(index) or error("Please specify the numeric index of the desired script.")
| | return "" |
| local scripts = lang:getScriptCodes()
| | end |
|
| | end |
| if scripts[index] then
| | if itemname == "transliterate" then |
| return scripts[index]
| | local text = iargs[3] |
| else
| | local sc = iargs[4] |
| return ""
| | local module_override = iargs[5] |
| end
| | sc = require("Module:scripts").getByCode(sc, 4) |
| elseif itemname == "getAncestors" then
| | return lang:transliterate(text, sc, module_override) or "" |
| local index = args[3]; if index == "" then index = nil end
| | elseif itemname == "makeEntryName" then |
| index = tonumber(index) or error("Please specify the numeric index of the desired ancestor.")
| | local text = iargs[3] |
| local ancestors = lang:getAncestors()
| | return lang:makeEntryName(text) or "" |
|
| | elseif itemname == "makeSortKey" then |
| if ancestors[index] then
| | local text = iargs[3] |
| return ancestors[index]:getCode()
| | return lang:makeSortKey(text) or "" |
| else
| | elseif itemname == "countCharacters" then |
| return ""
| | local text = args[3] or "" |
| end
| | local sc = require("Module:scripts").getByCode(iargs[4], 4, "disallow nil") |
| elseif itemname == "transliterate" then
| | return sc:countCharacters(text) |
| local text = args[3]; if text == "" then text = nil end
| | end |
| local sc = args[4]; if sc == "" then sc = nil end
| |
| local module_override = args[5]; if module_override == "" then module_override = nil end
| |
| sc = (sc and (require("Module:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")) or nil)
| |
| return lang:transliterate(text, sc, module_override) or ""
| |
| elseif itemname == "makeEntryName" then
| |
| local text = args[3]; if text == "" then text = nil end
| |
| return lang:makeEntryName(text) or ""
| |
| elseif itemname == "makeSortKey" then
| |
| local text = args[3]; if text == "" then text = nil end
| |
| return lang:makeSortKey(text) or ""
| |
| elseif lang[itemname] then
| |
| local ret = lang[itemname](lang)
| |
|
| |
| if type(ret) == "string" then
| |
| return ret
| |
| else
| |
| error("The function \"" .. itemname .. "\" did not return a string value.")
| |
| end | | end |
| else | | ) |
| error("Requested invalid item name \"" .. itemname .. "\".")
| |
| end
| |
| end | | end |
|
| |
|