Module:Lang: Difference between revisions

remove deprecated entry points;
m (1 revision imported)
(remove deprecated entry points;)
Line 20:
 
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
 
local this_wiki_lang = mw.language.getContentLanguage().code; -- get this wiki's language
 
local maint_cats = {}; -- maintenance categories go here
Line 75 ⟶ 77:
end
 
seg[1] = invert_pattern_table[seg[1]:gsub] (".*", invert_pattern_table,or seg[1)]; -- replace leading markup according to pattern table
seg[3] = invert_pattern_table[seg[3]:gsub] (".*",or invert_pattern_table, 1)seg[3]; -- replace leading markup according to pattern table
 
return table.concat (seg); -- put it all back together and done
Line 478 ⟶ 480:
 
if text:match ('^%*') then
table.insert (html, '*'); -- move proto language text prefix outside of italic markup if any; use numeric entity because planeplain splat confuses MediaWiki
text = text:gsub ('^%*', ''); -- remove the splat from the text
end
Line 730 ⟶ 732:
will be rendered outside of italic markup (if used). If the first character in text here is already a splat, we
do nothing
 
proto_param is boolean or nil; true adds splat prefix regardless of language name; false removes and / or inhibits
regardless of language name; nil does nothing; presumes that the value in text is correct but removes extra splac
 
]]
 
local function proto_prefix (text, language_name, proto_param)
if false == proto_param then -- when forced by |proto=no
if language_name:find ('^Proto%-') and not text:find ('^*') then -- language is a proto and text does not already have leading splat
return table.concattext:gsub ({'^%**', text}''); -- return text without splat prefix protoregardless of language textname withor aexisting splat prefix in text
elseif (language_name:find ('^Proto%-') or (true == proto_param)) then -- language is a proto or forced by |proto=yes
return text:gsub ('^%**', '*'); -- prefix proto-language text with a splat; also removes duplicate prefixing splats
end
return text:gsub ('^%*+', '*'); -- return text unmolested except multiple splats reduced to one splat
return text;
end
 
Line 791 ⟶ 798:
return text, tag;
end
 
 
--[[--------------------------< V A L I D A T E _ P R O T O >--------------------------------------------------
 
validates value assigned to |proto=; permitted values are yes and no; yes returns as true, no returns as false,
empty string (or parameter omitted) returns as nil; any other value returns as nil with a second return value of
true indicating that some other value has been assigned to |proto=
 
]]
 
local function validate_proto (proto_param)
if 'yes' == proto_param then
return true;
elseif 'no' == proto_param then
return false;
elseif is_set (proto_param) then
return nil, true; -- |proto= something other than 'yes' or 'no'
else
return nil; -- missing or empty
end
end
 
Line 826 ⟶ 854:
end
msg = validate_text ('lang'template, args); -- ensure that |text= is set
if is_set (msg) then -- msg is an already-formatted error message
return msg;
Line 836 ⟶ 864:
 
args.rtl = args.rtl == 'yes'; -- convert to boolean: 'yes' -> true, other values -> false
 
args.proto, msg = validate_proto (args.proto); -- return boolean, or nil, or nil and error message flag
if msg then
return make_error_msg (table.concat ({'invalid &#124;proto=: ', args.proto}), args, template);
end
 
code, subtags.script, subtags.region, subtags.variant, subtags.private, msg = get_ietf_parts (args.code); -- |script=, |region=, |variant= not supported because they should be part of args.code ({{{1}}} in {{lang}})
Line 850 ⟶ 883:
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
('en'this_wiki_lang ~= code and not is_set (subtags.script) and not has_poem_tag (args.text) and unicode.is_Latin (args.text)) then -- text not Englishthis wiki's language, no script specified and not in poem markup but is wholly latn script (auto-italics)
args.italic = 'italic'; -- DEFAULT for {{lang}} templates is upright; but if latn script set for font-style:italic
else
Line 880 ⟶ 913:
args.text = invert_italics (args.text)
end
 
args.text = proto_prefix (args.text, language_name, args.proto); -- prefix proto-language text with a splat
 
table.insert (out, make_text_html (args.code, args.text, tag, args.rtl, args.italic, args.size, language_name));
Line 977 ⟶ 1,010:
local msg; -- for error messages
local tag = 'span'; -- initial value for make_text_html()
local template = args.template or 'lang-xx';
 
if args[1] and args.text then
return make_error_msg ('conflicting: {{{1}}} and &#124;text=', args, 'lang-xx'template);
else
args.text = args[1] or args.text; -- prefer args.text
end
msg = validate_text ('lang-xx'template, args); -- ensure that |text= is set, does not contain italic markup and is protected from improper bolding
if is_set (msg) then
return msg;
Line 992 ⟶ 1,026:
 
if args[2] and args.translit then
return make_error_msg ('conflicting: {{{2}}} and &#124;translit=', args, 'lang-xx'template);
else
args.translit = args[2] or args.translit -- prefer args.translit
Line 998 ⟶ 1,032:
if args[3] and (args.translation or args.lit) then
return make_error_msg ('conflicting: {{{3}}} and &#124;lit= or &#124;translation=', args, 'lang-xx'template);
elseif args.translation and args.lit then
return make_error_msg ('conflicting: &#124;lit= and &#124;translation=', args, 'lang-xx'template);
else
args.translation = args[3] or args.translation or args.lit; -- prefer args.translation
Line 1,006 ⟶ 1,040:
 
if args.links and args.link then
return make_error_msg ('conflicting: &#124;links= and &#124;link=', args, 'lang-xx'template);
else
args.link = args.link or args.links; -- prefer args.link
Line 1,018 ⟶ 1,052:
 
if msg then -- if an error detected then there is an error message
return make_error_msg (msg, args, 'lang-xx'template);
end
args.italic, msg = validate_italic (args);
if msg then
return make_error_msg (msg, args, 'lang-xx'template);
end
 
Line 1,044 ⟶ 1,078:
args.rtl = false; -- script is not an rtl script
end
end
 
args.proto, msg = validate_proto (args.proto); -- return boolean, or nil, or nil and error message flag
if msg then
return make_error_msg (table.concat ({'invalid &#124;proto=: ', args.proto}), args, template);
end
 
Line 1,092 ⟶ 1,131:
end
args.text = proto_prefix (args.text, language_name, args.proto); -- prefix proto-language text with a splat
 
table.insert (out, make_text_html (args.code, args.text, tag, args.rtl, args.italic, args.size))
Line 1,109 ⟶ 1,148:
table.insert (out, make_wikilink ('Romanization of ' .. translit_script_name or language_name, 'romanized') .. ':'); -- make a wikilink if there is an article to link to
else
-- table.insert (out, '<abbr title="transliteration">translit.</abbr>romanized:'); -- else define theplain abbreviationtext
table.insert (out, 'romanized:'); -- else define the abbreviation
end
table.insert (out, '&nbsp;</small>'); -- close the small tag
Line 1,119 ⟶ 1,157:
table.insert (out, translit);
else
return make_error_msg (table.concat ({'invalid translit-std: \'', args['translit-std'] or '[missing]'}), args, 'lang-xx'template);
end
end
Line 1,225 ⟶ 1,263:
 
 
--[[--------------------------< _ I S _ I E T F _ CT OA D EG >------------------------------------------------------
 
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.
 
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_codename_from_tag|<code>}}
 
Module entry point from another module
Line 1,238 ⟶ 1,276:
]]
 
local function _is_ietf_code_is_ietf_tag (codetag) -- entry point when this module is require()d into another
local c, s, r, v, p, err; -- code, script, region, private, error message
return get_ietf_parts (code) and true;
c, s, r, v, p, err = get_ietf_parts (tag); -- disassemble tag into constituent part and validate
return ((c and not err) and true) or nil; -- return true when code portion has a value without error message; nil else
end
 
 
--[[--------------------------< I S _ I E T F _ CT OA D EG >--------------------------------------------------------
 
Module entry point from an {{#invoke:}}
Line 1,249 ⟶ 1,290:
]]
 
local function is_ietf_codeis_ietf_tag (frame) -- entry point from an {{#invoke:Lang|is_ietf_codeis_ietf_tag|<ietf codetag>}}
return _is_ietf_code_is_ietf_tag (frame.args[1]); -- frame.args[1] is the ietf language tag
end
 
Line 1,266 ⟶ 1,307:
]]
 
local function _name_from_code_name_from_tag (args)
local subtags = {}; -- IETF subtags script, region, variant, and private
local raw_code = args[1]; -- save a copy of the input IETF subtag
Line 1,317 ⟶ 1,358:
]]
 
local function name_from_codename_from_tag (frame) -- entry point from an {{#invoke:Lang|is_ietf_codename_from_tag|<ietf codetag>|link=<yes>|template=<template name>}}
return _name_from_code_name_from_tag (frame.args); -- pass-on the args table, nothing else
end
 
 
--[[--------------------------< _ T A G _ F R AO M _ N SA M LE >------------------------------------------------------------------
 
Returns the ietf language tag associated with the language name. Spelling of language name must be correct
according to the spelling in the source tables. When a standard language name has a parenthetical disambiguator,
that disambiguator must be omitted (they are not present in the data name-to-tag tables).
 
Module entry point from another module
 
]]
 
local function _tag_from_name (args) -- entry point from another module
local msg;
 
if args[1] and '' ~= args[1] then
local data = mw.loadData ('Module:Lang/name to tag'); -- get the reversed data tables
local lang = args[1]:lower(); -- allow any-case for the language name (speeling must till be correct)
local tag = data.rev_lang_data[lang] or data.rev_lang_name_table[lang];-- get the code; look first in the override then in the standard
 
if tag then
return tag; -- language name found so return tag and done
else
msg = 'language: ' .. args[1] .. ' not found' -- language name not found, error message
end
else
msg = 'missing language name' -- language name not provided, error message
end
 
local template = '';
if args.template and '' ~= args.template then
template = table.concat ({'{{', args['template'], '}}: '}); -- make template name (if provided by the template)
end
return table.concat ({'<span style=\"font-size:100%; font-style:normal;\" class=\"error\">error: ', template, msg, '</span>'});
end
 
 
--[[--------------------------< T A G _ F R O M _ N A M E >----------------------------------------------------
 
Module entry point from an {{#invoke:}}
 
]]
 
local function tag_from_name (frame) -- entry point from an {{#invoke:Lang|tag_from_name|<language name>|link=<yes>|template=<template name>}}
return _tag_from_name (frame.args); -- pass-on the args table, nothing else
end
 
 
--[[--------------------------< _ T R A N S L >----------------------------------------------------------------
 
Module entry point from another module
Line 1,409 ⟶ 1,496:
lang_xx_inherit = lang_xx_inherit, -- entry points for {{lang-??}}
lang_xx_italic = lang_xx_italic,
is_ietf_tag = is_ietf_tag,
is_ietf_code = is_ietf_code,
name_from_codetag_from_name = name_from_codetag_from_name, -- usedreturns forietf templatetag documentation;associated possiblewith use in ISO 639language name from code templates
name_from_tag = name_from_tag, -- used for template documentation; possible use in ISO 639 name from code templates
transl = transl, -- entry point for {{transl}}
 
Line 1,416 ⟶ 1,504:
_lang_xx_inherit = _lang_xx_inherit,
_lang_xx_italic = _lang_xx_italic,
_is_ietf_tag = _is_ietf_tag,
_is_ietf_code = _is_ietf_code,
_tag_from_name = _tag_from_name,
_name_from_code = _name_from_code,
_name_from_tag = _name_from_tag,
_transl = _transl,
};