Content deleted Content added
No edit summary |
sync from sandbox; |
||
Line 33:
local maint_cats = {}; -- maintenance categories go here
local maint_msgs = {}; -- and their messages go here
local templates = {
lang = 'Lang',
langx = 'Langx',
langxx = 'Lang-xx',
}
--[[--------------------------< C O M M O N _ P A R A M S >----------------------------------------------------
]]
local known_params_t = {
['common_params_all_t'] = { -- these parameters common to {{lang}}, {{langx}}, and {{lang-xx}}
['code'] = true,
['text'] = true,
['rtl'] = true,
['italic'] = true,
['italics'] = true,
['i'] = true,
['size'] = true,
['proto'] = true,
['nocat'] = true,
['cat'] = true,
['template'] = true, -- supplied by external templates to provide template name for error messaging ({{nihongo}}, etc)
},
['params_lang_t'] = { -- unique to {{lang}}
[1] = true, -- alias of |code=
[2] = true, -- alias of |text=
},
['params_x_t'] = { -- common to {{langx}} and {{lang-xx}}
['translit'] = true,
['translit-std'] = true,
['translit-script'] = true,
['translation'] = true,
['lit='] = true,
['label'] = true,
['link'] = true,
['links'] = true,
['lit'] = true,
['script'] = true, -- deprecated in {{langx}}; will become unique to {{lang-xx}}
['region'] = true, -- deprecated in {{langx}}; will become unique to {{lang-xx}}
['variant'] = true, -- deprecated in {{langx}}; will become unique to {{lang-xx}}
['engvar'] = true,
},
['params_langx_t'] = { -- unique to {{langx}}
[1] = true, -- alias of |code=
[2] = true, -- alias of |text=
[3] = true, -- alias of |translit=
[4] = true, -- alias of |translation=
},
['params_lang_xx_t'] = { -- unique to {{lang-xx}}
[1] = true, -- alias of |text=
[2] = true, -- alias of |translit=
[3] = true, -- alias of |translation=
},
}
--[[--------------------------< P A R A M E T E R _ V A L I D A T E >------------------------------------------
]]
local function parameter_validate (args_t, template)
local err_msg = 'invalid parameter: |%s=';
if templates.lang == template then -- for {{lang}}
for param, _ in pairs (args_t) do
if not known_params_t.params_lang_t[param] and -- unique {{lang}} parameters
not known_params_t.common_params_all_t[param] then -- common to all
return string.format (err_msg, param); -- <param> not found so abandon
end
end
elseif templates.langx == template then -- for {{langx}}
for param, _ in pairs (args_t) do
if not known_params_t.params_langx_t[param] and -- unique {{langx}} parameters
not known_params_t.params_x_t[param] and -- common to {{langx}} and {{lang-xx}}
not known_params_t.common_params_all_t[param] then -- common to all
return string.format (err_msg, param); -- <param> not found so abandon
end
end
elseif templates.langxx == template then -- for {{lang-xx}}
for param, _ in pairs (args_t) do
if not known_params_t.params_lang_xx_t[param] and -- unique {{lang-xx}} parameters
not known_params_t.params_x_t[param] and -- common to {{langx}} and {{lang-xx}}
not known_params_t.common_params_all_t[param] then -- common to all
return string.format (err_msg, param); -- <param> not found so abandon
end
end
end
end
Line 424 ⟶ 517:
local function make_error_msg (msg, args_t, template)
local category;
local text; -- handle the oddity that is {{langx}}
if templates.langxx == template then
text = args_t.text or args_t[1]; -- for {{lang-xx}}
else
text = args_t.text or args_t[2]; -- for {{lang}}, {{langx}}, and {{transliteration}}
end
if 'Transliteration' == template then
category = 'Transliteration';
Line 434 ⟶ 533:
return substitute ('[$1] <span style="color:#d33">Error: {{$2}}: $3 ([[:Category:$4 template errors|help]])</span>$5',
{
template,
msg,
Line 778 ⟶ 877:
]]
local function render_maint (nocat)
local maint = {};
Line 950 ⟶ 1,049:
local msg; -- for error messages
local tag = 'span'; -- initial value for make_text_html()
local template = args.template or
maint_cats = {}; -- initialize because when this module required into another module, these only declared once so only initialzed once
Line 968 ⟶ 1,067:
args.text = args[2] or args.text; -- prefer args.text
end
msg = parameter_validate (args, templates.lang);
if msg then
return make_error_msg (msg, args, templates.lang);
end
msg = validate_text (template, args); -- ensure that |text= is set
if is_set (msg) then -- msg is an already-formatted error message
Line 1,022 ⟶ 1,126:
table.insert (out, make_text_html (args.code, args.text, tag, args.rtl, args.italic, args.size, language_name));
table.insert (out, make_category (code, language_name, args.nocat));
table.insert (out, render_maint (args.nocat)); -- maintenance messages and categories
return table.concat (out); -- put it all together and done
Line 1,040 ⟶ 1,144:
local function lang (frame)
local
valueFunc = function (key, value)
if 2 == key or 'text' == key then -- the 'text' parameter; do not trim wite space
Line 1,054 ⟶ 1,158:
});
return _lang (
end
Line 1,144 ⟶ 1,248:
maint_msgs = {};
local text_idx = (
local translit_idx = (
local xlate_idx = (
if args[text_idx] and args.text then
Line 1,197 ⟶ 1,301:
return make_error_msg (msg, args, template);
end
else
args.italic =
end
end
else -- {{lang-xx}} does not do auto italics; retained for those wikis that don't support {{langx}}
if nil == args.italic then -- args.italic controls
if is_set (subtags.script) then
if 'latn' == subtags.script then
args.italic = 'italic'; -- |script=Latn; set for font-style:italic
else
args.italic = initial_style_state; -- italic not set; script is not latn; set for font-style:<initial_style_state>
end
else
args.italic = initial_style_state; -- here when |italic= and |script= not set; set for font-style:<initial_style_state>
end
end
end
Line 1,303 ⟶ 1,408:
table.insert (out, make_category (code, category_name, args.nocat));
if (templates.langx == base_template) and args.script or args.region or args.variant then
table.insert (maint_cats, 'Langx deprecated parameters');
table.insert (maint_msgs, '{{langx}} uses deprecated parameter(s)');
end
table.insert (out, render_maint(args.nocat)); -- maintenance messages and categories
Line 1,324 ⟶ 1,433:
parentFirst= true, -- parameters in the template override parameters set in the {{#invoke:}}
valueFunc = function (key, value)
if ((
return value; -- return untrimmed 'text' positional parameter
elseif value then -- all other values: if the value is not nil
Line 1,347 ⟶ 1,456:
local function lang_xx_italic (frame)
local args = lang_xx_args_get (frame,
local msg = parameter_validate (args, templates.langxx);
if msg then
return make_error_msg (msg, args, templates.langxx);
end
initial_style_state = 'italic';
return _lang_xx (args,
end
Line 1,362 ⟶ 1,476:
local function _lang_xx_italic (args)
initial_style_state = 'italic';
return _lang_xx (args,
end
Line 1,373 ⟶ 1,487:
local function lang_xx_inherit (frame)
local args = lang_xx_args_get (frame,
local msg = parameter_validate (args, templates.langxx);
if msg then
return make_error_msg (msg, args, templates.langxx);
end
initial_style_state = 'inherit';
return _lang_xx (args,
end
Line 1,388 ⟶ 1,507:
local function _lang_xx_inherit (args)
initial_style_state = 'inherit';
return _lang_xx (args,
end
Line 1,400 ⟶ 1,519:
local function _langx (args_t)
local langx_data = mw.loadData ('Module:Lang/langx'); -- get necessary data
local rtl_t = langx_data.rtl_t; -- get list of language tags for languages that are rendered right-to-left
local script_t = langx_data.script_t; -- get list of language tags for {{lang-??}} templates that set |script=<something>
local link_t = langx_data.link_t; -- get list of language tags for {{lang-??}} templates that set |link=<something>
local size_t = langx_data.size_t; -- get list of language tags for {{lang-??}} templates that set |size=<something>
local msg = parameter_validate (args_t, templates.langx);
if msg then
return make_error_msg (msg, args_t, templates.langx);
end
args_t.code = args_t[1] or args_t.code; -- get the language tag; must be {{{1}}} or |code=
if not args_t.code then
return make_error_msg ('missing language tag', args_t,
end
Line 1,419 ⟶ 1,542:
local lang_subtag = args_t.code; -- use only the base language subtag for unsupported tag test; some args_t.code are modified by |script= etc
return _lang_xx (args_t, templates.langx) .. ((langx_data.unsupported_t[lang_subtag:lower()] and '[[Category:Langx uses unsupported language tag|'.. lang_subtag .. ']]') or ''); -- temporary category for unsupported language tags
-- return _lang_xx (args_t, templates.langx);
end
Line 1,432 ⟶ 1,554:
but {{langx}} has four:
| 1 | 2 | 3 | 4
{{lang-xx |<text> |<transl> |<xlate> }}
{{langx |<tag> |<text> |<transl> |<xlate> }}
The calls to lang_xx_args_get() and _lang_xx() use 'Langx' as a flag for those functions to select the proper
positional parameters.
{{lang-??}} depends on the calling template to select 'inherit' or 'italic'
{{langx}} can't do that. The initial version of {{langx}} relied on a list of language tags (inherit_t in ~/langx)
scraped from those {{lang-??}} templates that call lang_xx_inherit() to render text in upright font. Langx now
uses auto-italics code adapted from {{lang}} (doesn't support poem tags)
]]
local function langx (frame)
local args_t = lang_xx_args_get (frame,
return _langx (args_t);
|