Anonymous user
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]
seg[3] = invert_pattern_table[seg[3]
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
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
return
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
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 (
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 |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
(
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);
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 |text=', args,
else
args.text = args[1] or args.text; -- prefer args.text
end
msg = validate_text (
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 |translit=', args,
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 |lit= or |translation=', args,
elseif args.translation and args.lit then
return make_error_msg ('conflicting: |lit= and |translation=', args,
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: |links= and |link=', args,
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,
end
args.italic, msg = validate_italic (args);
if msg then
return make_error_msg (msg, args,
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 |proto=: ', args.proto}), args, template);
end
Line 1,092 ⟶ 1,131:
end
args.text = proto_prefix (args.text, language_name, args.proto);
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
end
table.insert (out, ' </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,
end
end
Line 1,225 ⟶ 1,263:
--[[--------------------------< _ I S _ I E T F _
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|
Module entry point from another module
Line 1,238 ⟶ 1,276:
]]
local function
local c, s, r, v, p, err; -- code, script, region, private, error message
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 _
Module entry point from an {{#invoke:}}
Line 1,249 ⟶ 1,290:
]]
local function
return
end
Line 1,266 ⟶ 1,307:
]]
local function
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
return
end
--[[--------------------------< _ T A G _ F R
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,
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,
_tag_from_name = _tag_from_name,
_name_from_tag = _name_from_tag,
_transl = _transl,
};
|