Module:In lang: Difference between revisions

m
1 revision imported: templates
m (1 revision imported)
m (1 revision imported: templates)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
require ('Module:No globals');
require('strict');
 


--[[--------------------------< _ I N _ L A N G >--------------------------------------------------------------
--[[--------------------------< _ I N _ L A N G >--------------------------------------------------------------
Line 25: Line 24:
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 34: Line 33:
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
local this_wiki_lang = mw.language.getContentLanguage().code; -- get this wiki's language code
local this_wiki_lang = mw.language.getContentLanguage().code; -- get this wiki's language code
local override_t = mw.loadData ('Module:Lang/data').override; -- this table holds ietf tag/name definitions known to Module:Lang


for i, lang in ipairs (args) do
for i, lang in ipairs (args) do
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 code:find ('%-') and not override_t[code] then -- except for the IETF tags listed in <override_t>
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 subtags so that they aren't used to make category names
end
end
if synonym_table[code] then -- if 639-2/639-2T code has a 639-1 synonym
if synonym_table[code] then -- if 639-2/639-2T code has a 639-1 synonym
if (0 == namespace) and not list_cats then -- when listing cats don't include this cat; TODO: right choice?
if (0 == namespace) and not list_cats then -- when listing cats don't include this cat; TODO: right choice?
Line 54: Line 56:
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
elseif this_wiki_lang ~= code then -- categorize article only when code is not this wiki's language code
elseif this_wiki_lang ~= code:match ('^%a%a%a?') then -- categorize article only when code is not this wiki's language code or variants thereof
if lang:match ('%[%[.-|.-%]%]') then -- wikilinked individual language name
if lang:match ('%[%[.-|.-%]%]') then -- wikilinked individual language name
lang = lang:match ('%[%[.-|(.-)%]%]');
lang = lang:match ('%[%[.-|(.-)%]%]');
Line 67: Line 69:


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, ')]]'}));
Line 74: Line 76:
end
end
end
end
 
if list_cats then
if list_cats then
local cats = table.concat (cats, ', '):gsub ('[%[%]]', ''); -- make a string of categories and then strip wikilink markup
local cats = table.concat (cats, ', '):gsub ('[%[%]]', ''); -- make a string of categories and then strip wikilink markup