Content deleted Content added
sync from sandbox; |
sync from sandbox; |
||
Line 1:
--[=[
Lua support for the {{lang}}, {{langx}}, {{lang-
]=]
Line 104:
The return value nil causes the calling lang, lang_xx, or transl function to set args.italic according to the template's
defined default ('inherit' for {{lang}}, 'inherit' or 'italic' for {{lang-
the individual template's requirements, 'italic' for {{transliteration}}) or to the value appropriate to |script=, if set ({{lang}}
and {{lang-
Accepted values and the values that this function returns are are:
Line 138:
--[=[--------------------------< V A L I D A T E _ C A T _ A R G S >----------------------------------------------------------
Default behavior of the {{lang}} and {{lang-
This default functionality may be suppressed by setting |nocat=yes or |cat=no. This function selects one of these two parameters
to control categorization.
Line 245:
the synonymous three-character codes in the lang= attribute.
For {{lang-
because those parameters are superfluous to the IETF subtags in |code=)
Line 714:
local close_tag;
if is_set (code) then -- when a language code is provided (always with {{lang-
code = code:match ('^(%a%a%a?)'); -- strip all subtags leaving only the language subtag
Line 1,083:
--[[--------------------------< _ L A N G _ X X >
For the {{lang-
other parameters can, usually should, be written in the template call. For {{lang-
that can have multiple writing systems, it may be appropriate to set |script= as well.
For each {{lang-
styling that should be applied to text.
Line 1,114:
any other text replaces language-name label - automatic wikilinking disabled
for those {{lang-
|translit = text that is a transliteration of text
|translit-std = the standard that applies to the transliteration
|translit-script = ISO 15924 script name; falls back to code
For {{lang-
{{{1}}} text
{{{2}}} transliterated text
Line 1,127:
]]
local function _lang_xx (args, base_template) -- base_template will be either of 'Langx' or 'Lang-xx'
local out = {};
local language_name; -- used to make display text, article links
Line 1,139:
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
maint_msgs = {};
local text_idx = ('Langx' == base_template) and 2 or 1; -- for {{langx}} 'text' positional parameter is '2'
if args[1] and args.text then▼
local translit_idx = ('Langx' == base_template) and 3 or 2;
return make_error_msg ('conflicting: {{{1}}} and |text=', args, template);▼
local xlate_idx = ('Langx' == base_template) and 4 or 3;
else
args.text = args[
end
msg = validate_text (template, args); -- ensure that |text= is set, does not contain italic markup and is protected from improper bolding
if is_set (msg) then
Line 1,157 ⟶ 1,161:
args.text, tag = html_tag_select (args.text); -- inspects text; returns appropriate html tag with text trimmed accordingly
if args[
return make_error_msg ('conflicting: {{{
else
args.translit = args[
end
args.engvar = lang_data.engvar_sel_t[args.engvar] or 'us_t'; -- either 'gb_t' or 'us_t' when |engvar= valid; 'us_t' else
if args[
return make_error_msg ('conflicting: {{{
elseif args.translation and args.lit then
return make_error_msg ('conflicting: |lit= and |translation=', args, template);
else
args.translation = args[
end
Line 1,188 ⟶ 1,192:
return make_error_msg (msg, args, template);
end
args.italic, msg = validate_italic (args);
if msg then
return make_error_msg (msg, args, template);
end
-- TODO: any way to make this more lang()-like? so we can dispense with Module:Lang/langx
if nil == args.italic then -- args.italic controls
if is_set (subtags.script) then
Line 1,299 ⟶ 1,303:
returns table of args
text positional parameters are not trimmed here but are selectively trimmed at html_tag_select()
]]
local function lang_xx_args_get (frame, base_template)
local
{
parentFirst= true, -- parameters in the template override parameters set in the {{#invoke:}}
valueFunc = function (key, value)
if (('Langx' == base_template) and 2 or 1) == key then
return value; -- return untrimmed 'text' positional parameter
elseif value then -- all other values: if the value is not nil
value = mw.text.trim (value); -- trim whitespace
Line 1,319 ⟶ 1,325:
});
return
end
Line 1,325 ⟶ 1,331:
--[[--------------------------< L A N G _ X X _ I T A L I C >--------------------------------------------------
Entry point for those {{lang-
]]
local function lang_xx_italic (frame)
local args = lang_xx_args_get (frame, 'lang-xx');
initial_style_state = 'italic';
return _lang_xx (args, 'Lang-xx');
end
Line 1,339 ⟶ 1,345:
--[[--------------------------< _ L A N G _ X X _ I T A L I C >------------------------------------------------
Entry point
]]
Line 1,345 ⟶ 1,351:
local function _lang_xx_italic (args)
initial_style_state = 'italic';
return _lang_xx (args, 'Lang-xx');
end
Line 1,351 ⟶ 1,357:
--[[--------------------------< L A N G _ X X _ I N H E R I T >------------------------------------------------
Entry point for those {{lang-
]]
local function lang_xx_inherit (frame)
local args = lang_xx_args_get (frame, 'lang-xx');
initial_style_state = 'inherit';
return _lang_xx (args, 'Lang-xx');
end
Line 1,371 ⟶ 1,377:
local function _lang_xx_inherit (args)
initial_style_state = 'inherit';
return _lang_xx (args, 'Lang-xx');
end
--[[--------------------------< _ L A N G X >------------------------------------------------------------------
Entry point from another module.
]]
local function _langx (args_t)
local langx_data = mw.loadData ('Module:Lang/langx'); -- get necessary data
local inherit_t = langx_data.inherit_t; -- get list of language tags extracted from {{lang-??}} template names for languages that are rendered in upright font
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>
args_t.code = args_t[1] or args_t.code; -- get the language tag; must be {{{1}}} or |code=
args_t.rtl = args_t.rtl or (rtl_t[args_t.code] and 'yes'); -- prefer |rtl= in template call, use rtl_t else
args_t.script = args_t.script or script_t[args_t.code]; -- prefer |script= in template call, use script_t else
args_t.link = args_t.link or link_t[args_t.code]; -- prefer |link= in template call, use link_t felse
args_t.size = args_t.size or size_t[args_t.code]; -- prefer |size= in template call, use size_t else
args_t[1] = nil; -- unset to mimic {{lang-??}} templates which set |code=xx
initial_style_state = inherit_t[args_t.code] and 'inherit' or 'italic'; -- if listed in inherit_t, set as 'inherit'; 'italic' else
return _lang_xx (args_t, 'Langx');
end
--[[--------------------------< L A N G X >--------------------------------------------------------------------
Entry point for {{langx}}.
this function calls _lang_xx() to render non-English text. The {{lang-??}} templates have three positional paramters
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' as the default renderer.
{{langx}} can't do that so, intead, relies on the list of tags scraped from the {{lang-??}} templates that call
lang_xx_inherit().
]]
local function langx (frame)
local args_t = lang_xx_args_get (frame, 'Langx'); -- get the arguments; 'Langx' is the <base_template> used to decide which positional param is 'text', 'translit', 'lit'
return _langx (args_t);
-- local inherit_t = mw.loadData ('Module:Lang/langx').inherit_t; -- get list of language tags extracted from the {{lang-??}} template names for languages that are rendered in upright font
-- args_t.code = args_t[1] or args_t.code; -- get the language tag; must be {{{1}}} or |code=
-- args_t[1] = nil; -- unset to mimic {{lang-??}} which set |code=xx
-- initial_style_state = inherit_t[args_t.code] and 'inherit' or 'italic'; -- if listed in inherit_t set as 'inherit'; 'italic' else
-- return _lang_xx (args_t, 'Langx'); -- and go do it
end
Line 1,379 ⟶ 1,447:
Returns true when a language name associated with IETF language tag exists; nil else. IETF language tag must be valid.
All code combinations supported by {{lang}} and the {{lang-
Module entry point from another module
Line 1,421 ⟶ 1,489:
Returns language name associated with IETF language tag if valid; error message else.
All code combinations supported by {{lang}} and the {{lang-
Set invoke's |link= parameter to yes to get wikilinked version of the language name.
Line 1,627 ⟶ 1,695:
Returns category name associated with IETF language tag if valid; error message else
All code combinations supported by {{lang}} and the {{lang-
Module entry point from another module
Line 1,677 ⟶ 1,745:
category_from_tag = category_from_tag,
lang = lang, -- entry point for {{lang}}
langx = langx, -- entry point for {{langx}}
lang_xx_inherit = lang_xx_inherit, -- entry points for {{lang-??}}
lang_xx_italic = lang_xx_italic,
Line 1,688 ⟶ 1,757:
_category_from_tag = _category_from_tag, -- entry points when this module is require()d into other modules
_lang = _lang,
_langx = _langx,
_lang_xx_inherit = _lang_xx_inherit,
_lang_xx_italic = _lang_xx_italic,
|