Module:Sandbox/trappist the monk/hyphenated language names: Difference between revisions
imported>Legoktm Replace Module:No globals with require( "strict" ) |
(No difference)
|
Latest revision as of 21:01, 23 October 2022
Documentation for this module may be created at Module:Sandbox/trappist the monk/hyphenated language names/doc
require('strict');
local data_m = mw.loadData ('Module:Language/data/iana languages');
local redirect_m = require('Module:Redirect')
local function get_redirect (name)
if redirect_m.luaIsRedirect (name) then
local target = redirect_m.getTarget (name); -- get the redirect's target
if target:find ('–', 1, true) then
return table.concat ({' → [[', target, ']]'}); -- make and return a wikilink
end
end
return ''; -- return empty string for concatenation
end
local function list()
local list_t = {}
for _, v in ipairs ({'active', 'deprecated'}) do -- there are two lists in the data module, do them both
for tag, name_t in pairs (data_m[v]) do -- for each tag/language-name pair
if name_t[1]:find ('-', 1, true) then -- look for a hyphen in the language name
local redirect = '';
if not (name_t[1]:find ('%d%-') or name_t[1]:find ('%-%d')) then -- skip hyphenated names where the hyphen is associated with digits
if name_t[1]:find ('[Ll]anguages?') then -- for collective language names and language names that contain 'language'
redirect = get_redirect (name_t[1]);
table.insert (list_t, table.concat ({'#[[', name_t[1], ']]', redirect})); -- make wikilink
else
redirect = get_redirect (name_t[1]);
table.insert (list_t, table.concat ({'#[[', name_t[1], ' language]]', redirect})); -- make nornal language wikilink
end
end
end
end
end
table.sort (list_t); -- sort the list to make it all pretty-like
return table.concat (list_t, '\n'); -- make a big string and done
end
return {list = list}