Content deleted Content added
No edit summary |
No edit summary |
||
Line 342:
local args = require ('Module:Arguments').getArgs (frame);
local err = false; -- boolean set true when an error is detected; one error message only
local cat_page_title = mw.title.getCurrentTitle().text;
local lang_name;
local index; -- positional parameter index
local lc_lang_name, lc_lang_name_col; -- individual and collective cat names are different
local lc_title;
for i, v in ipairs (args) do -- pairs because ipairs stops at nil value (empty positional parameter)
mw.logObject (cat_page_title, 'cat_page_title')▼
if 'number' == type (i) and args[i] then -- only positional parameters and only when they have a value
if lang_module._is_ietf_tag (v) then -- see if this thing 'v' is an ietf tag
local t = {v}; -- it is so make an args table for _name_from_tag()
lang_name = lang_module._name_from_tag (t);
else
lang_name = v; -- not a valid tag so presume it is a name
end
mw.logObject (lang_name, 'lang_name
lc_lang_name = table.concat ({ -- build a string to match category name form for individual and macro languages
if not mw.ustring.find (cat_page_title:lower(), lang_name:lower(), 1, true) then▼
'containing ',
mw.ustring.lower (lang_name); -- to lowercase for comparisons
'-language',
break; -- abandon on first error▼
});
lc_lang_name_col = table.concat ({ -- build a string to match category name form for collective languages
'the ',
mw.ustring.lower (lang_name); -- to lowercase for comparisons
' ', -- next word is languages which is included in the name retrieved from Module:lang
});
mw.logObject (lc_lang_name_col, 'lc_lang_name_col')
lc_title = mw.ustring.lower (cat_page_title);
if not mw.ustring.find (lc_title, lc_lang_name, 1, true) and -- if lang name not found in cat title
▲
err = true; -- set a flag
index = i; -- remember which positional param failed the test
end
end
end
-- create error message and done
return err and table.concat ({
'<span style=\"font-size:100%; font-style:normal;\" class=\"error\">error: language: ',
lang_name, -- the thing that we think is the language name
' from {{{',
index, -- the positional parameter index: 1 in {{{1}}}
'}}} (',
args[index], -- the content of the positional parameter
') does not match category title.</span>[[Category:Lang and lang-xx template errors]]'
}) or nil;
end
|