Module:Lang: Засвар хоорондын ялгаа

Content deleted Content added
No edit summary
No edit summary
Tag: Reverted
Мөр 1:
--[=[
 
Lua support for the {{lang}}, {{langx}}, {{lang-xx??}}, and {{transliteration}} templates and replacement of various supporting templates.
 
]=]
Мөр 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-xx??}} depending on
the individual template's requirements, 'italic' for {{transliteration}}) or to the value appropriate to |script=, if set ({{lang}}
and {{lang-xx??}} only).
 
Accepted values and the values that this function returns are are:
Мөр 138:
--[=[--------------------------< V A L I D A T E _ C A T _ A R G S >----------------------------------------------------------
 
Default behavior of the {{lang}} and {{lang-xx??}} templates is to add categorization when the templates are used in mainspace.
This default functionality may be suppressed by setting |nocat=yes or |cat=no. This function selects one of these two parameters
to control categorization.
Мөр 245:
the synonymous three-character codes in the lang= attribute.
 
For {{lang-xx??}} templates, the parameters |script=, |region=, and |variant= are supported (not supported in {{lang}}
because those parameters are superfluous to the IETF subtags in |code=)
 
Мөр 401:
end
return code, script, region, variant, private, nil; -- return the good bits; make sure that msg is nil
end
 
 
--[[--------------------------< S U B S T I T U T E >----------------------------------------------------------
 
substitutes $1, $2, etc in <message> with data from <data_t>. Returns plain-text substituted string when
<data_t> not nil; returns <message> else
 
]]
 
local function substitute (message, data_t)
return data_t and mw.message.newRawMessage (message, data_t):plain() or message;
end
 
Line 410 ⟶ 422:
]]
 
local function make_error_msg (msg, argsargs_t, template)
local out = {};
local category;
Line 420 ⟶ 431:
end
local category_link = ((0 == namespace or 10 == namespace) and not args_t.nocat) and table.concat ({'[[Category:', category, ' template errors]]'}) or '';
table.insert (out, table.concat ({'[', args.text or 'undefined', '] '})); -- for error messages output args.text if available
table.insertreturn (out, table.concatsubstitute ({'[$1] <span style=\"color:#d33\">Error: {{', template, '$2}}: $3 ([[:Category:$4 template errors|help]])</span>$5'}));,
{
table.insert (out, msg);
args_t.text or 'undefined',
table.insert (out, table.concat ({' ([[:Category:', category, ' template errors|help]])'}));
template,
table.insert (out, '</span>');
msg,
category,
if (0 == namespace or 10 == namespace) and not args.nocat then -- categorize in article space (and template space to take care of broken usages)
category_link
table.insert (out, table.concat ({'[[Category:', category, ' template errors]]'}));
})
end
 
return table.concat (out);
end
Line 646 ⟶ 655:
]]
 
local function make_translit (code, language_name, translit, std, tscript, style, engvar)
local title;
local out_t = {};
Line 659 ⟶ 668:
title_text = title_text .. '-language'; -- skip this text (individual and macro languages only)
end
title_text = title_textsubstitute ..('$1 $2', romanization{title_text, lang_data.engvar_t[engvar]['romanisz_lc']}); -- finish the tool tip; use romanization when neither script nor standard supplied
 
elseif is_set (std) and is_set (tscript) then -- when both are specified
Line 705 ⟶ 714:
 
local close_tag;
if is_set (code) then -- when a language code is provided (always with {{lang-xx??}} templates, not always with {{transliteration}})
code = code:match ('^(%a%a%a?)'); -- strip all subtags leaving only the language subtag
 
Line 728 ⟶ 737:
return table.concat (out_t); -- make a string and done
else
title_text = 'gb_t' == engvar and title_text:gsub ('([Rr]omani)z', '%1s') or title_text; -- gb eng when engvar specifies gb eng; us eng else
return title_wrapper_make (title_text, table.concat (out_t), 'span'); -- wrap with a tool-tip span and don
return title_wrapper_make (title_text, table.concat (out_t), 'span'); -- wrap with a tool-tip span and done
end
end
Line 1,073 ⟶ 1,083:
 
 
--[[--------------------------< _ L A N G _ X X >----------------------------------------------------------------
 
For the {{lang-xx??}} templates, the only parameter required to be set in the template is the language code. All
other parameters can, usually should, be written in the template call. For {{lang-xx??}} templates for languages
that can have multiple writing systems, it may be appropriate to set |script= as well.
 
For each {{lang-xx??}} template choose the appropriate entry-point function so that this function knows the default
styling that should be applied to text.
 
Line 1,104 ⟶ 1,114:
any other text replaces language-name label - automatic wikilinking disabled
for those {{lang-xx??}} templates that support transliteration (those templates where |text= is not entirely latn script):
|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-xx??}}, the positional parameters are:
{{{1}}} text
{{{2}}} transliterated text
Line 1,117 ⟶ 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,129 ⟶ 1,139:
local msg; -- for error messages
local tag = 'span'; -- initial value for make_text_html()
local template = args.template or 'Lang-xx'base_template;
 
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;
 
if args[text_idx] and args.text then
return make_error_msg ('conflicting: {{{' .. text_idx .. '}}} and |text=', args, template);
else
args.text = args[1text_idx] or args.text; -- prefer args.positional 'text' parameter
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,147 ⟶ 1,161:
args.text, tag = html_tag_select (args.text); -- inspects text; returns appropriate html tag with text trimmed accordingly
 
if args[2translit_idx] and args.translit then
return make_error_msg ('conflicting: {{{2'.. translit_idx .. '}}} and |translit=', args, template);
else
args.translit = args[2translit_idx] or args.translit -- prefer args.positional 'translit' parameter
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[3] and (args.translation or args.lit) then
 
return make_error_msg ('conflicting: {{{3}}} and |lit= or |translation=', args, template);
if args[xlate_idx] and (args.translation or args.lit) then
return make_error_msg ('conflicting: {{{'.. xlate_idx ..'}}} and |lit= or |translation=', args, template);
elseif args.translation and args.lit then
return make_error_msg ('conflicting: |lit= and |translation=', args, template);
else
args.translation = args[3xlate_idx] or args.translation or args.lit; -- prefer args.positional 'translation' parameter
end
 
Line 1,176 ⟶ 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: this appears to work so we might in future dispense inherit_t in Module:Lang/langx
-- retain existing system until {{langx}} has replaced {{lang-??}}
-- if nil == args.italic then -- nil when |italic= absent or not set or |italic=default; args.italic controls
-- if ('latn' == subtags.script) or -- script is latn
-- (this_wiki_lang_tag ~= code and not is_set (subtags.script) and unicode.is_Latin (args.text)) then -- text is not this wiki's language, no script specified and is wholly latn script (auto-italics)
-- args.italic = 'italic'; -- set font-style:italic
-- else
-- args.italic = 'inherit'; -- italic not set; script not latn; inherit current style
-- end
-- end
 
-- TODO: retain this system until {{langx}} has replaced {{lang-??}}
if nil == args.italic then -- args.italic controls
if is_set (subtags.script) then
Line 1,221 ⟶ 1,248:
table.insert (out, language_name); -- language name without wikilink
else
if mw.ustring.find (language_name, 'хэлlanguages', 1, true) then
table.insert (out, make_wikilink (language_name)); -- collective language name uses simple wikilink
elseif lang_data.article_name[args.code:lower()] then -- is ietf tag in article name over ride?
table.insert (out, make_wikilink (lang_data.article_name[args.code:lower()], language_name)); -- language name with wikilink from override data
elseif lang_data.article_name[code] then -- is language tag in article override
table.insert (out, make_wikilink (lang_data.article_name[code], language_name)); -- language name with wikilink from override data
else
table.insert (out, make_wikilink (language_name .. ' хэлlanguage', language_name)); -- language name with wikilink
end
end
Line 1,249 ⟶ 1,278:
translit_script_name = language_name; -- fall back on language name
end
translit_title = mw.title.makeTitle (0, table.concat ({'Romanization of ', translit_script_name})); -- make a title object; no engvar, article titles use US spelling
if translit_title.exists and ('no' ~= args.link) then
table.insert (out, make_wikilink ('Romanization of ' .. translit_script_name or language_name,
substitute ('галиглал$1', {lang_data.engvar_t[args.engvar]['romanisz_pt']})) .. ':'); -- make a wikilink if there is an article to link to; engvar the display text
 
else
table.insert (out, substitute ('галиглал$1:', {lang_data.engvar_t[args.engvar]['romanisz_pt']})); -- else plain text per engvar
 
end
table.insert (out, '&nbsp;</small>'); -- close the small tag
end
translit = make_translit (args.code, language_name, args.translit, args['translit-std'], args['translit-script'], nil, args.engvar)
if is_set (translit) then
table.insert (out, translit);
Line 1,282 ⟶ 1,314:
 
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 argsargs_t = getArgs(frame,
{
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 -- the 'text' positional parameter; 1 for {{lang-??}}, 2 for {{langx}}; do not trim wite space
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,302 ⟶ 1,336:
});
 
return argsargs_t;
end
 
Line 1,308 ⟶ 1,342:
--[[--------------------------< L A N G _ X X _ I T A L I C >--------------------------------------------------
 
Entry point for those {{lang-xx??}} templates that call lang_xx_italic(). Sets the initial style state to italic.
 
]]
 
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') .. '[[Category:Pages using Lang-xx templates]]'; -- temporary category
end
 
Line 1,322 ⟶ 1,356:
--[[--------------------------< _ L A N G _ X X _ I T A L I C >------------------------------------------------
 
Entry point ffromfrom another module. Sets the initial style state to italic.
 
]]
Line 1,328 ⟶ 1,362:
local function _lang_xx_italic (args)
initial_style_state = 'italic';
return _lang_xx (args, 'Lang-xx');
end
 
Line 1,334 ⟶ 1,368:
--[[--------------------------< L A N G _ X X _ I N H E R I T >------------------------------------------------
 
Entry point for those {{lang-xx??}} templates that call lang_xx_inherit(). Sets the initial style state to inherit.
 
]]
 
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') .. '[[Category:Pages using Lang-xx templates]]'; -- temporary category
end
 
Line 1,354 ⟶ 1,388:
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=
if not args_t.code then
return make_error_msg ('missing language tag', args_t, 'Langx');
end
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
 
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
initial_style_state = inherit_t[args_t.code:lower()] and 'inherit' or 'italic'; -- if listed in inherit_t, set as 'inherit'; 'italic' else
return _lang_xx (args_t, '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, '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);
end
 
Line 1,362 ⟶ 1,456:
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-xx??}} templates are supported by this function.
 
Module entry point from another module
Line 1,404 ⟶ 1,498:
Returns language name associated with IETF language tag if valid; error message else.
 
All code combinations supported by {{lang}} and the {{lang-xx??}} templates are supported by this function.
 
Set invoke's |link= parameter to yes to get wikilinked version of the language name.
Line 1,433 ⟶ 1,527:
 
if link then -- when |link=yes, wikilink the language name
if mw.ustring.find (language_name, 'хэлlanguages', 1, true) then
language_name = make_wikilink (language_name, label); -- collective language name uses simple wikilink
elseif lang_data.article_name[coderaw_code:lower()] then -- is ietf tag in article name override?
language_name = make_wikilink (lang_data.article_name[raw_code:lower()], label or language_name); -- language name with wikilink from override data
elseif lang_data.article_name[code] then -- is language tag in article name override?
language_name = make_wikilink (lang_data.article_name[code], label or language_name); -- language name with wikilink from override data
else
language_name = make_wikilink (language_name .. ' хэлlanguage', label or language_name); -- language name with wikilink
end
end
Line 1,571 ⟶ 1,667:
args.italic = nil; -- set to nil;
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 override_table[args.code] then -- is code a language code defined in the override table?
Line 1,587 ⟶ 1,685:
end
-- here only when all parameters passed to make_translit() are valid
return make_translit (args.code, language_name, args.text, args.translit_std, script, args.italic, args.engvar);
end
 
Line 1,606 ⟶ 1,704:
Returns category name associated with IETF language tag if valid; error message else
 
All code combinations supported by {{lang}} and the {{lang-xx??}} templates are supported by this function.
 
Module entry point from another module
Line 1,624 ⟶ 1,722:
if msg then
local template = (args_t.template and table.concat ({'{{', args_t.template, '}}: '})) or ''; -- make template name (if provided by the template)
return table.concat ({'<span style=\"color:#d33\">Error: ', template, msg, '</span>'});
end
 
Line 1,656 ⟶ 1,754:
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,667 ⟶ 1,766:
_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,