Module:Lang: Difference between revisions

synch from sandbox;
(synch from sandbox;)
(synch from sandbox;)
Line 805:
]]
 
local function lang_lang (frameargs)
local args = getArgs (frame, { -- this code so that we can detect and handle wiki list markup in text
valueFunc = function (key, value)
if 2 == key or 'text' == key then -- the 'text' parameter; do not trim wite space
return value; -- return untrimmed 'text'
elseif value then -- all other values: if the value is not nil
value = mw.text.trim (value); -- trim whitespace
if '' ~= value then -- empty string when value was only whitespace
return value;
end
end
return nil; -- value was empty or contained only whitespace
end -- end of valueFunc
});
 
local out = {};
local language_name; -- used to make category names
Line 902 ⟶ 888:
 
return table.concat (out); -- put it all together and done
end
 
 
--[[--------------------------< L A N G >----------------------------------------------------------------------
 
entry point for {{lang}}
 
there should be no reason to set parameters in the {{lang}} {{#invoke:}}
<includeonly>{{#invoke:lang|lang}}</includeonly>
 
parameters are recieved from the template's frame (parent frame)
 
]]
 
local function lang (frame)
local args = getArgs (frame, { -- this code so that we can detect and handle wiki list markup in text
valueFunc = function (key, value)
if 2 == key or 'text' == key then -- the 'text' parameter; do not trim wite space
return value; -- return untrimmed 'text'
elseif value then -- all other values: if the value is not nil
value = mw.text.trim (value); -- trim whitespace
if '' ~= value then -- empty string when value was only whitespace
return value;
end
end
return nil; -- value was empty or contained only whitespace
end -- end of valueFunc
});
 
return _lang (args);
end
 
Line 949 ⟶ 965:
]]
 
local function _lang_xx (frameargs)
local args = getArgs(frame,
{
parentFirst= true, -- parameters in the template override parameters set in the {{#invoke:}}
valueFunc = function (key, value)
if 1 == key then -- the 'text' parameter; do not trim wite space
return value; -- return untrimmed 'text'
elseif value then -- all other values: if the value is not nil
value = mw.text.trim (value); -- trim whitespace
if '' ~= value then -- empty string when value was only whitespace
return value;
end
end
return nil; -- value was empty or contained only whitespace
end -- end of valueFunc
});
 
local out = {};
local language_name; -- used to make display text, article links
Line 1,140:
 
return table.concat (out); -- put it all together and done
end
 
 
--[[--------------------------< L A N G _ X X _ A R G S _ G E T >----------------------------------------------
 
common function to get args table from {{lang-??}} templates
 
returns table of args
 
]]
 
local function lang_xx_args_get (frame)
local args = getArgs(frame,
{
parentFirst= true, -- parameters in the template override parameters set in the {{#invoke:}}
valueFunc = function (key, value)
if 1 == key then -- the 'text' parameter; do not trim wite space
return value; -- return untrimmed 'text'
elseif value then -- all other values: if the value is not nil
value = mw.text.trim (value); -- trim whitespace
if '' ~= value then -- empty string when value was only whitespace
return value;
end
end
return nil; -- value was empty or contained only whitespace
end -- end of valueFunc
});
 
return args;
end
 
Line 1,150 ⟶ 1,179:
 
local function lang_xx_italic (frame)
local args = lang_xx_args_get (frame);
initial_style_state = 'italic';
return _lang_xx (frameargs);
end
 
 
--[[--------------------------< _ L A N G _ X X _ I T A L I C >------------------------------------------------
 
Entry point ffrom another module. Sets the initial style state to italic.
 
]]
 
local function _lang_xx_italic (args)
initial_style_state = 'italic';
return _lang_xx (args);
end
 
Line 1,162 ⟶ 1,205:
 
local function lang_xx_inherit (frame)
local args = lang_xx_args_get (frame);
 
initial_style_state = 'inherit';
return _lang_xx (frameargs);
end
 
 
--[[--------------------------< _ L A N G _ X X _ I N H E R I T >----------------------------------------------
 
Entry point from another module. Sets the initial style state to inherit.
 
]]
 
local function _lang_xx_inherit (args)
initial_style_state = 'inherit';
return _lang_xx (args);
end
 
Line 1,175 ⟶ 1,232:
The purpose of this function is to replace {{#ifexist:Template:ISO 639 name xx|<exists>|<does not exist>}} in
templates that are better served by using {{#invoke:lang|name_from_code|<code>}}
 
Module entry point from another module
 
]]
 
local function _is_ietf_code (code) -- entry point when this module is require()d into another
local function is_ietf_code (frame)
return get_ietf_parts (frame.args[1]code) and true;
end
 
 
--[[--------------------------< NI AS M_ I E _T F R O M _ C O D E >------------------------------------------------------
 
Module entry point from an {{#invoke:}}
 
]]
 
local function is_ietf_code (frame) -- entry point from an {{#invoke:Lang|is_ietf_code|<ietf code>}}
return _is_ietf_code (frame.args[1]);
end
 
 
--[[--------------------------< _ N A M E _ F R O M _ C O D E >------------------------------------------------
 
Returns language name associated with IETF language tag if valid; empty string else.
Line 1,190 ⟶ 1,260:
 
Set invoke's |link= parameter to yes to get wikilinked version of the language name.
 
Module entry point from another module
 
]]
 
local function name_from_code_name_from_code (frameargs)
local subtags = {}; -- IETF subtags script, region, variant, and private
local raw_code = frame.args[1]; -- save a copy of the input IETF subtag
local link = 'yes' == frame.args['link']; -- savemake a copy of the link-enable positional parameter (value can be anything)boolean
local code; -- the language code
local msg; -- gets an error message if IETF language tag is malformed or invalid
Line 1,203 ⟶ 1,275:
code, subtags.script, subtags.region, subtags.variant, subtags.private, msg = get_ietf_parts (raw_code);
if msg then
local template = (frame.args['template'] and table.concat ({'{{', frame.args['template'], '}}: '})) or ''; -- make template name (if provided by the template)
return table.concat ({'<span style=\"font-size:100%; font-style:normal;\" class=\"error\">error: ', template, msg, '</span>'});
end
Line 1,222 ⟶ 1,294:
 
language_name = language_name:gsub ('%s+%b()', ''); -- remove IANA parenthetical disambiguators or qualifiers from names that have them
 
--error(lang_data.article_name[code][1])
if link then -- when |link=yes, wikilink the language name
if language_name:find ('languages') then
Line 1,235 ⟶ 1,307:
return language_name;
 
end
 
 
--[[--------------------------< N A M E _ F R O M _ C O D E >--------------------------------------------------
 
Module entry point from an {{#invoke:}}
 
]]
 
local function name_from_code (frame) -- entry point from an {{#invoke:Lang|is_ietf_code|<ietf code>|link=<yes>|template=<template name>}}
return _name_from_code (frame.args); -- pass-on the args table, nothing else
end
 
Line 1,240 ⟶ 1,323:
--[[--------------------------< T R A N S L >------------------------------------------------------------------
 
Module entry point from another module
Entry point for {{transl}}
 
]]
 
local function transl_transl (frameargs)
local args = getArgs(frame); -- no {{#invoke:}} parameters
local title_table = lang_data.translit_title_table; -- table of transliteration standards and the language codes and scripts that apply to those standards
local language_name; -- language name that matches language code; used for tool tip
Line 1,304 ⟶ 1,386:
-- 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);
end
 
 
--[[--------------------------< T R A N S L >------------------------------------------------------------------
 
Module entry point from an {{#invoke:}}
 
]]
 
local function transl (frame)
local args = getArgs(frame); -- no {{#invoke:}} parameters
return _transl (args);
end
 
Line 1,312 ⟶ 1,406:
return {
lang = lang, -- entry point for {{lang}}
is_ietf_code = is_ietf_code,
lang_xx_inherit = lang_xx_inherit, -- entry points for {{lang-??}}
lang_xx_italic = lang_xx_italic,
is_ietf_code = is_ietf_code,
name_from_code = name_from_code, -- used for template documentation; possible use in ISO 639 name from code templates
transl = transl, -- entry point for {{transl}}
 
_lang = _lang, -- entry points when this module is require()d into other modules
_lang_xx_inherit = _lang_xx_inherit,
_lang_xx_italic = _lang_xx_italic,
_is_ietf_code = _is_ietf_code,
_name_from_code = _name_from_code,
_transl = _transl,
};
Anonymous user