Module:In lang: Difference between revisions

m 1 revision imported
Module:Lang no longer creates 'collective' categories; this module should do the same;
Line 1: Line 1:
require ('Module:No globals');
require('strict');




Line 25: Line 25:
if not args[1] then
if not args[1] then
local template = (args['template'] and table.concat ({'{{', args['template'], '}}: '})) or ''; -- make template name (if provided by the template)
local template = (args['template'] and table.concat ({'{{', args['template'], '}}: '})) or ''; -- make template name (if provided by the template)
return table.concat ({'<span style=\"font-size:100%; font-style:normal;\" class=\"error\">error: ', template, 'missing language tag</span>'});
return table.concat ({'<span style=\"color:#d33\">error: ', template, 'missing language tag</span>'});
end
end


Line 39: Line 39:
local t = {code, ['link'] = args['link'], ['template'] = args['template']}; -- build an 'args' table
local t = {code, ['link'] = args['link'], ['template'] = args['template']}; -- build an 'args' table
lang = name_from_tag (t) -- get the language name
lang = name_from_tag (t) -- get the language name
table.insert (list, lang) -- add this language or error message to the list
table.insert (list, lang) -- add this language or error message to the list


if 'ca-valencia' ~= code then -- except for valencian
if not ({['ca-valencia'] = true, ['gsw-fr'] = true, ['pt-br'] = true, ['nl-be'] = true})[code] then -- except for these exact IETF tags; TODO: a better way/place to do this?
code = code:match ('^%a%a%a?%f[^%a]'); -- strip off region, script, and variant tags so that they aren't used to make category names
code = code:match ('^%a%a%a?%f[^%a]'); -- strip off region, script, and variant tags so that they aren't used to make category names
end
end
Line 54: Line 55:
end
end


if (0 == namespace) or list_cats then -- when in article space
if (0 == namespace) or list_cats then -- when in article space
if lang:find ('error') then -- add error category (message provided by Module:Lang)
if lang:find ('[Ee]rror') then -- add error category (message provided by Module:Lang)
if not list_cats then -- don't include this cat when listin cats; TODO: right choice?
if not list_cats then -- don't include this cat when listing cats; TODO: right choice?
table.insert (cats, '[[Category:in lang template errors]]');
table.insert (cats, '[[Category:in lang template errors]]');
end
end
Line 67: Line 68:


if lang:find ('languages') then -- add appropriate language-name category
if lang:find ('languages') then -- add appropriate language-name category
table.insert (cats, table.concat ({'[[Category:Articles with ', lang, '-collective sources (', code, ')]]'}));
table.insert (cats, table.concat ({'[[Category:Articles with sources in ', lang, ' (', code, ')]]'}));
else
else
table.insert (cats, table.concat ({'[[Category:Articles with ', lang, '-language sources (', code, ')]]'}));
table.insert (cats, table.concat ({'[[Category:Articles with ', lang, '-language sources (', code, ')]]'}));