Jump to content

Module:languages/error/documentation

From Wiktionary, the free dictionary
Documentation for Module:languages/error. [edit]
This page contains usage information, categories, interwiki links and other content describing the module.
Use the second parameter of getByCode() instead of directly invoking this module.
The preferred way to generate an error message for an invalid language code is to pass the parameter name holding the language code as the parameter getByCode() rather than directly invoking this module. Code in some modules directly invokes this module, but this is generally old code that should be cleaned up.

Preferred calling convention

[edit]
local m_languages = require("Module:languages")
local lang = m_languages.getByCode(frame.args[1], 1)

Here, we call getByCode with the parameter name in the second parameter.

Old (obsolete) calling convention

[edit]

require("Module:languages/error")(lang, param, text)

Looks at a supposed language code passed through a template parameter and returns a helpful error message depending on whether the language code has a valid form (two or three lowercase basic Latin letters, two or three groups of three lowercase basic Latin letters separated by hyphens).

Add the parameter value in argument #1 and the parameter name in argument #2. For instance, if parameter 1 of the template is supposed to be a language code, this function can be called the following way:

local m_languages = require("Module:languages")
local lang = m_languages.getByCode(frame.args[1]) or require("Module:languages/error")(frame.args[1], 1)

If you would like the error message to say something other than "language code", place the phrase in argument #3.