Content deleted Content added
No edit summary |
No edit summary |
||
(10 intermediate revisions by 3 users not shown) | |||
Line 1:
require('
local getArgs = require ('Module:Arguments').getArgs;
Line 6:
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
local err_texts = { -- because wrapper templates have Latn/non-Latn text ordered according to the wrapper template's name
['lang-sh-cyrl-latn'] = true, -- this template has |1=cyrl script |2=latn script
}
Line 11 ⟶ 15:
assembles an error message from template name, message text, help link, and error category.
<span style="font-family: monospace, monospace;">{{', template, '}}</span>
]]
local function error_msg_make (msg, template,
local out = {};
local category = 'Lang and lang-xx';
table.insert (out, table.concat ({'<span style=\"color:#d33\">Error: <span style="font-family: monospace, monospace;">{{', template, '}}</span>: '}));
table.insert (out, msg);
table.insert (out, table.concat ({' ([[Template:
table.insert (out, '</span>');
if (0 == namespace or 10 == namespace) and not
table.insert (out, table.concat ({'[[Category:Lang and lang-xx template errors]]'}));
end
Line 85 ⟶ 89:
]]
local function ietf_tag_make (args_t,
local ietf_tag_t = {
local enum = swap and '1' or '2'; -- when <swap> is true latin <text1> is rendered second by _lang()
Line 99 ⟶ 103:
--[[--------------------------< _ L A N G _ X 2 >--------------------------------------------------------------
mimics {{lang|<
Latin-script form). Intended for languages where two scripts are 'official' or 'native and equal in status' (sh
is and sr may be
{{lang_x2|<
<
<text1> - (required) Latin-script text (always)
<text2> - (required) non-Latin-script text (always)
Line 121 ⟶ 125:
enumerated parameters:
|script1= - ISO 15924 script tag for <text1> -- when <text1> renders first, these are passed to _lang_xx_...() individually
|region1= - ISO 3166 region tag for <text1> -- when <text1> renders second, these are combined with <
|variant1= - IETF tag for <text1>
|script2= - ISO 15924 script tag for <text2> -- when <text2> renders first, these are passed to _lang_xx_...() individually
|region2= - ISO 3166 region tag for <text2> -- when <text2> renders second, these are combined with <
|variant2= - IETF tag for <text2>
Line 145 ⟶ 149:
local function _lang_x2 (args_t)
local text1 = args_t.text1 or args_t[2];▼
return error_msg_make ('missing a required argument', 'lang-x2', args_t);▼
local text2 = args_t.text2 or args_t[3];▼
local translation = args_t.translation or args_t[4];
local template_name = args_t.template_name or 'lang-x2';
local nocat = ('yes' == args_t.nocat) or ('no' == args_t.cat); -- boolean
if not (tag and text1 and text2) then
end
if
return error_msg_make ('invalid language
end
if not is_latn then
return error_msg_make ('<span style="font-family: monospace, monospace;"><' .. ((err_texts[template_name:lower()] and 'text2') or 'text1') .. '></span> is not Latin script (pos ' .. pos .. ')', template_name, nocat);
end
if is_latn then
return error_msg_make ('<span style="font-family: monospace, monospace;"><' .. ((err_texts[template_name:lower()] and 'text1') or 'text2') .. '></span> is Latin script (pos ' .. pos .. ')', template_name, nocat);
end
local swap = 'yes' == args_t.swap; -- boolean
local out = {};
▲ local text1 = args_t[2];
▲ local text2 = args_t[3];
local ietf_tags = ietf_tag_make (args_t,
-- create base-form arguments tables
local lang_xx_args_t = {['code']=
local lang_args_t = {['code']=ietf_tags, ['cat']=args_t.cat, ['nocat']=args_t.nocat, ['cat']=args_t.cat}; -- for whichever <textn> renders second
param_select (args_t, lang_args_t, lang_xx_args_t, swap); -- load <lang_args_t>, <lang_xx_args_t> tables with appropriate enumerated parameters from <args_t> table according to <swap>
Line 184 ⟶ 194:
table.insert (out, lang._lang (lang_args_t)); -- and render the other of <text1> or <text2>
if translation then -- if positional parameter 4 (translation of <text1> and <text2>)
table.insert (out, lang._translation_make ({['translation'] = translation, ['label']=args_t.label, ['link']=args_t.link})); -- add translation to rendering
end
return table.concat (out)
end
|