Module:Infobox/utilities: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
 
(9 intermediate revisions by 5 users not shown)
Line 1:
require('Module:No globalsstrict');
local getArgs = require ('Module:Arguments').getArgs;
 
--[=[--------------------------< I N T E R L A N G _ W I K I S O U R C E _ L I N K _ M A K E >------------------
 
created as a test function to figure out why the wikitext for |data36= in [[Special:Permalink/1236589613|this version]]
of the template doesn't work in [[Salammbô]] when |title_orig= exists but does not have a value. When that
happened, the infobox returned plain wikitext [[s:fr:Salammbô|]] which should have been a functioning link.
Placing that wikilink in the article body and previewing produced a working inter-language/inter-project link.
 
{{#invoke:Infobox/utilities|interlang_wikisource_link_make|{{{orig_lang_code|}}}|{{{native_wikisource|}}}|{{{title_orig|}}}|{{{name|}}} }}
 
]=]
 
local function interlang_wikisource_link_make (frame)
local lang_mod = require ('Module:Lang'); -- used to wrap non-English wikisource links in proper html markup
 
local args_t = getArgs (frame); -- parameter values that are emptyspace or only white space are converted to nil
local orig_lang_code = args_t[1]; -- 'all of them sensible everyday names'
local native_wikisource = args_t[2];
local title_orig = args_t[3];
local name = args_t[4];
 
local orig_lang_name = mw.language.fetchLanguageName (orig_lang_code, 'en'); -- get the English name associated with <orig_lang_code>; only language tags known to MediaWiki allowed
if '' == orig_lang_name then -- empty string when <orig_lang_code> invalid
return '<span style="color:#d33">invalid language tag: <span style="font-family:monospace">' .. orig_lang_code .. '</span></span>';
end
 
local out_t = {}; -- output goes here
table.insert (out_t, '[[s:'); -- open inter-language/inter-project wikilink
table.insert (out_t, orig_lang_code); -- the language tag
table.insert (out_t, ':'); -- add the required separator
 
table.insert (out_t, native_wikisource); -- insert wikisource title
table.insert (out_t, '|'); -- done with link; start label
table.insert (out_t, title_orig or name or mw.title.getCurrentTitle().baseText); -- insert the label
table.insert (out_t, ']]'); -- close inter-language/inter-project wikilink
out_t = {lang_mod._lang ({orig_lang_code, table.concat (out_t)})}; -- replace content of out_t with a big string of its contents wrapped in {{lang}}
 
table.insert (out_t, ' at '); -- begin other language wikisource wikilinklink
table.insert (out_t, orig_lang_name); -- add the MediaWiki-known language name associated with |orig_lang_code=
table.insert (out_t, ' [[Wikisource]]'); -- insert wikisource link static text
return table.concat (out_t); -- make a big string of all and done
end
 
 
Line 42 ⟶ 86:
local is_latn = require ("Module:Unicode data").is_Latin;
code = code:gsub ('^(%a+).*', '%1'); -- strip subtags from IETF tag to leave just the language subtag
if is_cjk_code (code) and not is_latn (text) then -- is_latn() is in Module:Unicode data
return 'no'; -- only case for 'no'
Line 124 ⟶ 169:
local result = { -- initialize; table will be sorted according to values in result[n][1]
{args[1], '% [[White peopleAmericans|whiteWhite]]'},
{args[2], '% [[BlackAfrican peopleAmericans|blackBlack]]'},
{args[3], '% [[Asian Americans|Asian]]'},
{args[4], '% [[Hispanic and Latino Americans|Hispanic]]'},
{args[5], '% [[Native Americans in the United States|Native American]]'},
{args[6], '% [[Pacific IslandsIslander Americans]]'},
{args[7], '% [[Multiracial Americans|Two or more races]]'},
{args[8], '% other'}, -- TODO: make other always last?
};
Line 167 ⟶ 212:
set_italics = set_italics, -- {{Infobox book}}
interlang_wikisource_link_make = interlang_wikisource_link_make,
}