Module:In lang: Difference between revisions

Jump to navigation Jump to search
m (1 revision imported: Templates and CSS files)
No edit summary
Line 1: Line 1:
require('strict');
require('strict');


--[[--------------------------< _ I N _ L A N G >--------------------------------------------------------------
--[[--------------------------< _ I N _ L A N G >--------------------------------------------------------------
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 42: Line 42:
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 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?
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 60: Line 61:
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 75: 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