Content deleted Content added
No edit summary |
No edit summary |
||
(7 intermediate revisions by 3 users not shown) | |||
Line 83:
local category_link = ((0 == namespace or 10 == namespace) and not args_t.nocat) and substitute ('[[Category:$1]]', {category}) or '';
return substitute ('[$1] <span style="color:#d33">$2:
{
text or cfg.make_error_msg_t.undefined,
Line 146:
This function attempts to invert the italic markup a args.text by adding/removing leading/trailing italic markup
in args.text. Like |italic=unset, |italic=invert disables automatic italic markup. Individual leading/trailing
apostrophes are converted to their
bold markup inadvertently.
Line 192:
Validates |italic= or |italics= assigned values.
When |italic= is set and has an
for the special case 'default', return nil.
When |italic= is not set, or has an
When both |italic= and |italics= are set, returns nil and a 'conflicting' error message.
The return value nil causes the calling lang, lang_xx, or
defined default ('inherit' for {{lang}}, 'inherit' or 'italic' for {{lang-??}} depending on
the individual template's requirements, 'italic' for {{transliteration}}) or to the value appropriate to |script=, if set ({{lang}}
Line 234:
--[=[--------------------------< V A L I D A T E _ C A T _ A R G S >----------------------------------------------------------
Default behavior of the {{lang}} and {{lang-??}} templates is to add categorization when the templates are used in
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 285:
--[[--------------------------< F O R M A T _ I E T F _ T A G >------------------------------------------------
Prettify
code: lower case
script: sentence case
Line 352:
local function get_ietf_parts (source, args_script, args_region, args_variant)
local code, script, region, variant, private; --
if not is_set (source) then
Line 358:
end
local pattern = { -- table of tables holding
{'^(%a%a%a?)%-(%a%a%a%a)%-(%a%a)%-(%d%d%d%d)$', 's', 'r', 'v'}, -- 1 - ll-Ssss-RR-variant (where variant is 4 digits)
{'^(%a%a%a?)%-(%a%a%a%a)%-(%d%d%d)%-(%d%d%d%d)$', 's', 'r', 'v'}, -- 2 - ll-Ssss-DDD-variant (where region is 3 digits; variant is 4 digits)
Line 388:
}
local t = {}; -- table of captures; serves as a translator between captured
for i, v in ipairs (pattern) do -- spin through the pattern table looking for a match
Line 402:
};
script = t.s or ''; -- translate table contents to named variables;
region = t.r or ''; -- absent table entries are nil so set named
variant= t.v or '';
private = t.p or '';
Line 436:
script = script:lower(); -- ensure that we use and return lower case version of this
if not script_table[script] then
return code, nil, nil, nil, nil, substitute (cfg.get_ietf_parts_t.unrecog_scr_code, {script, code}); -- language code
end
end
if suppressed_table[script] then -- ensure that code-script does not use a suppressed script
if in_array (code, suppressed_table[script]) then
return code, nil, nil, nil, nil, substitute (cfg.get_ietf_parts_t.script_code, {script, code}); -- language code
end
end
Line 537:
if text:find ('\n+') then -- look for any number of \n characters in text
text = text:gsub ('([^\n])\n([^\n])', '%1 %2'); -- replace single newline characters with a space character which mimics
if 'italic' == style then
text = text:gsub('[^\n]+', '<p><i>%1</i></p>'); -- insert p and italic markup tags at each
else
text = text:gsub ('[^\n]+', '<p>%1</p>'); -- insert p markup at each
text = text:gsub ('\n', ''); -- strip newline characters
end
Line 555:
Makes a <span title="<title text>"><content_text></span> or <div title="<title text>"><content_text></div> where
<title text> is in the tool-tip in the wiki's local language and <content_text> is non-local-language text in
<tag> holds a string 'div' or 'span' used to choose the correct wrapping tag.
Line 577:
--[[--------------------------< M A K E _ T E X T _ H T M L >--------------------------------------------------
Add the
<div> tags for block content
Line 600:
end
if 'span' == tag then -- default
if 'italic' == style then -- but if italic
tag = 'i'; -- change to <i> tags
Line 608:
end
table.insert (html_t, table.concat ({'<', tag})); -- open the <i>, <span>, or <div>
code = code:gsub ('%-x%-.*', ''); -- strip private use subtag from code tag because meaningless outside of
table.insert (html_t, table.concat ({' lang="', code, '\"'})); -- add language attribute
Line 632:
end
table.insert (html_t, table.concat ({style_added, '>'})); -- close the opening
table.insert (html_t, text); -- insert the text
table.insert (html_t, table.concat ({'</', tag, '>'})); -- close the 'text' <i>, <span>, or <div>
if is_set (language) then -- create a <title_text> string for the title= attribute in a wrapper span or div
Line 704:
to be |translit-script= (in this function, tscript).
This function is used by both lang_xx() and
lang_xx() always provides code, language_name, and translit; may provide tscript; never provides style
For {{transliteration}}, style only applies when a language code is provided.
Line 749:
if not title_t[std] then return ''; end -- invalid standard, setup for error message
if title_t[std][code] then -- if language code is in the table (
title_text = substitute ('$1$2 ($3 $4) $5', { -- add the appropriate text to the tool tip
title_text,
Line 913:
--[[--------------------------< H T M L _ T A G _ S E L E C T >------------------------------------------------
Inspects content of and selectively trims text. Returns text and the name of an appropriate
If text contains:
Line 992:
elseif override_table[code] then -- not there so try basic language tag
name = override_table[code];
elseif lang_table[code] then -- shift to
name = lang_table[code];
elseif lang_dep_table[code] then -- try the
name = lang_dep_table[code];
end
Line 1,093:
TODO: when text has accept-as-written markup, return a non-boolean value to indicate that <text> is not wholly
latn script? Use that return value to create non-Latn
latn so lang=und (undetermined)? or instead, omit the -Latn subtag? (without -
]]
Line 1,162:
end
args.text, tag = html_tag_select (args.text); -- inspects text; returns appropriate
args.rtl = args.rtl == cfg.keywords_t.affirmative; -- convert to boolean: 'yes' -> true, other values -> false
Line 1,178:
local is_latn_text, pos, char;
is_latn_text, args.text, pos, char= is_latin (args.text,
msg = text_script_match_test (subtags.script, is_latn_text, pos, char)
Line 1,208:
args.code = format_ietf_tag (code, subtags.script, subtags.region, subtags.variant, subtags.private); -- format to recommended subtag styles
language_name = language_name_get (args.code, code, true); -- get language name; try
if cfg.keywords_t.invert == args.italic and 'span' == tag then -- invert only supported for in-line content
Line 1,273:
if 'none' ~= args_t.label then -- if we want a label
table.insert (translation_t, '<small>'); -- open the <small>
if cfg.keywords_t.negative == args_t.link then
table.insert (translation_t, substitute ('<abbr title="$1">$2</abbr>', {cfg.translation_make_t.lit_xlation, cfg.translation_make_t.lit_abbr})); -- unlinked form
Line 1,279:
table.insert (translation_t, make_wikilink (cfg.translation_make_t.lit_xlation, cfg.translation_make_t.lit_abbr)); -- linked form
end
table.insert (translation_t, " </small>"); -- close the <small>
end
table.insert (translation_t, table.concat ({''', args_t.translation, '''})); -- use
return table.concat (translation_t); -- make a big string and done
end
Line 1,330:
]]
local function _lang_xx (args, base_template) -- base_template will be either of '
local out = {};
local language_name; -- used to make display text, article links
Line 1,361:
end
args.text, tag = html_tag_select (args.text); -- inspects text; returns appropriate
if args[translit_idx] and args.translit then
Line 1,368:
else
args.translit = args[translit_idx] or args.translit -- prefer positional 'translit' parameter
end▼
if args.translit then▼
local latn, pos, char;▼
latn, args.translit, pos, char = is_latin (args.translit, args[1] or args.code);▼
if not latn then▼
return make_error_msg (substitute (cfg.lang_xx_t.translit_nonlatn, {pos, char}), args, template);▼
end▼
end
Line 1,404 ⟶ 1,396:
end
▲ if args.translit then
▲ local latn, pos, char;
▲ latn, args.translit, pos, char = is_latin (args.translit,
▲ if not latn then
▲ return make_error_msg (substitute (cfg.lang_xx_t.translit_nonlatn, {pos, char}), args, template);
▲ end
▲ end
local is_latn_text, text, pos, char = is_latin (args.text, code); -- make a boolean
args.text = text; -- may have been modified (accept-as-written markup removed)
Line 1,455:
args.code = format_ietf_tag (code, subtags.script, subtags.region, subtags.variant, subtags.private); -- format to recommended subtag styles
language_name = language_name_get (args.code, code, true); -- get language name; try
category_name = language_name; -- category names retain IANA parenthetical diambiguators (if any)
Line 1,470:
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
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
Line 1,669:
| 1 | 2 | 3 | 4
{{lang-xx |<text> |<
{{langx |<tag> |<text> |<
The calls to lang_xx_args_get() and _lang_xx() use '
positional parameters.
Line 1,678:
{{langx}} can't do that. The initial version of {{langx}} relied on a list of language tags (inherit_t in ~/langx)
scraped from those {{lang-??}} templates that call lang_xx_inherit() to render text in upright font.
uses auto-italics code adapted from {{lang}} (doesn't support poem tags).
Line 1,684:
local function langx (frame)
local args_t = lang_xx_args_get (frame, cfg.templates_t.langx); -- get the arguments; '
return _langx (args_t);
Line 1,715:
local function is_ietf_tag (frame)
return _is_ietf_tag (getArgs (frame)[1]); -- args[1] is the
end
Line 1,728:
local function is_ietf_tag_frame (frame)
return _is_ietf_tag (getArgs (frame, {frameOnly = true,})[1]); -- args[1] is the
end
Line 1,760:
raw_code = format_ietf_tag (code, subtags.script, subtags.region, subtags.variant, subtags.private); -- format to recommended subtag styles; private omitted because private
language_name = language_name_get (raw_code, code); -- get language name; try
if 'yes' ~= args.raw then
Line 1,769:
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[raw_code:lower()] then -- is
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?
Line 1,788:
]]
local function name_from_tag (frame) -- entry point from an {{#invoke:
return _name_from_tag (getArgs(frame)) -- pass-on the args table, nothing else; getArgs() so we also get parent frame
end
Line 1,795:
--[[--------------------------< _ T A G _ F R O M _ N A M E >--------------------------------------------------
Returns the
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).
Line 1,835:
]]
local function tag_from_name (frame) -- entry point from an {{#invoke:
local result, _ = _tag_from_name (getArgs(frame)) -- pass-on the args table, nothing else; getArgs() so we also get parent frame; supress second return used by is_lang_name()
return result;
Line 1,853:
--[[--------------------------< _
Module entry point from another module.
Line 1,859:
]]
local function
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,891:
end
if is_set (args[1]) then -- IANA language code used for
if args[1]:match ('^%a%a%a?%a?$') or args[1]:match ('^%a%a%a?%-x%-') then -- args[1] has correct form?
args.code = args[1]:lower(); -- use the language/script code; only (2, 3, or 4 alpha characters) or private-use; lower case because table indexes are lower case
Line 1,938:
--[[--------------------------<
Module entry point from an {{#invoke:}}.
Line 1,944:
]]
local function
return
end
Line 1,975:
raw_code = format_ietf_tag (code, subtags.script, subtags.region, subtags.variant, subtags.private); -- format to recommended subtag styles; private omitted because private
category_name = language_name_get (raw_code, code); -- get language name; try
category_name = make_category (code, category_name, nil, true):gsub ('[%[%]]', '');
Line 1,992:
]]
local function category_from_tag (frame) -- entry point from an {{#invoke:
return _category_from_tag (getArgs (frame)); -- pass-on the args table, nothing else; getArgs() so we also get parent frame
end
Line 2,001:
return {
category_from_tag = category_from_tag, -- frame entry points when this module is #invoke:ed into templates/wikitext
lang = lang, -- entry point for {{lang}}
langx = langx, -- entry point for {{langx}}
Line 2,009:
is_ietf_tag_frame = is_ietf_tag_frame,
is_lang_name = is_lang_name,
tag_from_name = tag_from_name, -- returns
name_from_tag = name_from_tag, -- used for template documentation; possible use in ISO 639 name from code templates
_category_from_tag = _category_from_tag, -- API entry points when this module is require()d into other modules
_lang = _lang,
_langx = _langx,
Line 2,022:
_tag_from_name = _tag_from_name,
_name_from_tag = _name_from_tag,
_translation_make = translation_make,
};
|