Module:Sandbox/Mr. Stradivarius/Check ISO 639-1
Appearance
![]() | This module is rated as pre-alpha. It is unfinished, and may or may not be in active development. It should not be used from article namespace pages. Modules remain pre-alpha until the original editor (or someone who takes one over if it is abandoned for some time) is satisfied with the basic structure. |
This module checks whether the code passed to the first positional parameter is a valid ISO 639-1 language code.
--[[
-- This module detects whether the first positional parameter is a valid ISO 639-1 language code.
-- If it is, it returns the code. If not, it returns an error and a tracking category. For blank
-- or non-string input, the returns a blank string. The tracking category is sorted by the language
-- code, rather than by the page name.
--]]
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local p = {}
function p.main(frame)
local args = getArgs(frame)
return p._main(args)
end
function p._main(args)
local code = args[1]
if type(code) ~= 'string' then
return '' -- code is either not a string or is a blank string that was removed by getArgs.
end
local ret = mw.ustring.lower(code)
if not mw.language.isKnownLanguageTag(ret) then
ret = '<strong class="error">Error: "' .. code .. '" is not a valid [[List of ISO 639-1 codes|ISO 639-1 code]]</strong>'
if not yesno(args.nocat) then
ret = ret .. '[[Category:Pages with invalid ISO 639-1 language codes|' .. code .. ']]'
end
end
return ret
end
return p