Content deleted Content added
No edit summary |
No edit summary |
||
(25 intermediate revisions by 3 users not shown) | |||
Line 23:
local synonym_table = mw.loadData ('Module:Lang/ISO 639 synonyms'); -- ISO 639-2/639-2T code translation to 639-1 code
local cfg = mw.loadData ('Module:Lang/
local is_latn_data = mw.loadData ('Module:Lang/data/is latn data');
local sizeof_ranges_t = is_latn_data.sizeof_ranges_t;
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
Line 41 ⟶ 44:
]]
local function
return table.concat ({'<span style="color:#d33">', cfg.misc_text_t.error, ': ', template, msg, '</span>'})
end
Line 48 ⟶ 51:
--[[--------------------------< S U B S T I T U T E >----------------------------------------------------------
<data_t> not nil; returns <message> else.
]]
Line 60 ⟶ 63:
--[[--------------------------< M A K E _ E R R O R _ M S G >--------------------------------------------------
]]
Line 80 ⟶ 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 94 ⟶ 97:
--[[--------------------------< P A R A M E T E R _ V A L I D A T E >------------------------------------------
]]
Line 142 ⟶ 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 186 ⟶ 190:
--[[--------------------------< V A L I D A T E _ I T A L I C >------------------------------------------------
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 230 ⟶ 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 262 ⟶ 266:
--[[--------------------------< I N _ A R R A Y >--------------------------------------------------------------
Whether needle is in haystack.
]]
Line 281 ⟶ 285:
--[[--------------------------< F O R M A T _ I E T F _ T A G >------------------------------------------------
code: lower case
script: sentence case
Line 317 ⟶ 321:
--[[--------------------------< G E T _ I E T F _ P A R T S >--------------------------------------------------
primary language subtag (required) - 2 or 3 character IANA language code
script subtag - four character IANA script code
Line 331 ⟶ 335:
lang-x-private
each of lang, script, region, variant, and private, when used, must be valid.
Languages with both two- and three-character code synonyms are promoted to the two-character synonym because
Line 338 ⟶ 342:
For {{lang-??}} templates, the parameters |script=, |region=, and |variant= are supported (not supported in {{lang}}
because those parameters are superfluous to the IETF subtags in |code=).
parts are returned as nil; the sixth returned item is an error message (if an error detected) or nil.
]]
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 354 ⟶ 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 384 ⟶ 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 398 ⟶ 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 432 ⟶ 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 519 ⟶ 523:
--[[--------------------------< D I V _ M A R K U P _ A D D >--------------------------------------------------
]]
local function div_markup_add (text, style)
if text:find ('^\n[%*:;#]') then -- look for list markup; list markup must begin at start of text
if 'italic' == style then
Line 535 ⟶ 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 551 ⟶ 553:
--[[--------------------------< T I T L E _ W R A P P E R _ M A K E >------------------------------------------
<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 574 ⟶ 577:
--[[--------------------------< M A K E _ T E X T _ H T M L >--------------------------------------------------
Add the
<div> tags for block content
Line 597 ⟶ 600:
end
if 'span' == tag then -- default
if 'italic' == style then -- but if italic
tag = 'i'; -- change to <i> tags
Line 605 ⟶ 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 629 ⟶ 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 656 ⟶ 659:
[[Category:Articles containing <language>-language text]]
[[Category:Articles containing explicitly cited English-language text]]
[[Category:Articles with text in <language> languages]]
Line 665 ⟶ 668:
local function make_category (code, language_name, nocat, name_get)
if ((0 ~= namespace) or nocat) and not name_get then -- only categorize in article space
return ''; -- return empty string for concatenation
Line 695:
--[[--------------------------< M A K E _ T R A N S L I T >----------------------------------------------------
The value |script= is not used in {{transliteration}} for this purpose; instead it uses |code. Because language scripts
Line 702:
To avoid confusion, in this module and the templates that use it, the transliteration script parameter is renamed
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.
]]
local function make_translit (code, language_name, translit, std, tscript, style, engvar)
local title_t = lang_data.translit_title_table; -- table of transliteration standards and the language codes and scripts that apply to those standards
local title_text = ''; -- tool tip text for title= attribute
Line 724 ⟶ 723:
title_text = substitute ('$1-$2', {title_text, cfg.misc_text_t.language}); -- skip this text (individual and macro languages only)
end
title_text = substitute ('$1 $2', {title_text,
elseif is_set (std) and is_set (tscript) then -- when both are specified
Line 750 ⟶ 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 796 ⟶ 795:
end
local
if is_set (code) then -- when a language code is provided (always with {{lang-??}} templates, not always with {{transliteration}})
code = code:match ('^(%a%a%a?)'); -- strip all subtags leaving only the language subtag
if not style then -- nil for the default italic style
else
tag = string.format(tag, style, "%s", "%s")
end
else
end
if '' == title_text then -- when there is no need for a tool-tip
return
else
title_text =
return title_wrapper_make (title_text,
end
end
Line 829 ⟶ 822:
This function checks the content of args.text and returns empty string if nothing is amiss else it returns an
error message.
Italic rendering is controlled by the |italic= template parameter so italic markup should never appear in args.text
Line 838 ⟶ 831:
local function validate_text (template, args)
if not is_set (args.text) then
return make_error_msg (
end
Line 857 ⟶ 850:
--[[--------------------------< R E N D E R _ M A I N T >------------------------------------------------------
]]
Line 884 ⟶ 877:
--[[--------------------------< P R O T O _ P R E F I X >------------------------------------------------------
will be rendered outside of italic markup (if used).
do nothing.
proto_param is boolean or nil; true adds splat prefix regardless of language name; false removes and
regardless of language name; nil does nothing; presumes that the value in text is correct but removes extra splac.
]]
Line 906 ⟶ 899:
--[[--------------------------< H A S _ P O E M _ T A G >------------------------------------------------------
the content that will replace the stripmarker.
Line 920 ⟶ 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 963 ⟶ 956:
--[[--------------------------< V A L I D A T E _ P R O T O >--------------------------------------------------
empty string (or parameter omitted) returns as nil; any other value returns nil with <proto_param> as second
return value for use in error message.
Line 984 ⟶ 977:
--[[--------------------------< L A N G U A G E _ N A M E _ G E T >--------------------------------------------
]]
Line 999 ⟶ 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,022 ⟶ 1,015:
Conversely, when <text> is written using the Latn script, the IETF script subtag, if present, should be Latn.
For the purposes of this test, Latf (Fraktur) and Latg (Gaelic) are considered to be equivalent to Latn because
unicode treats these two scripts as font-specific variants of Latn.
Returns an error message when mismatch detected; nil else.
]]
local function text_script_match_test (script, is_latn_text, pos, char)
local scripts_t = {['latf'] = true, ['latg'] = true, ['latn'] = true}; -- unicode 'latn' scripts; 'latf' and 'latg' are font variants so there are no Fraktur or Gaelic codepoints
if is_set (script) then -- don't bother with the rest of this if <script> is nil or empty string
script = script:lower(); -- lower case to index into <scripts_t>
if is_latn_text then -- when text is wholly Latn script
if
return cfg.text_script_match_test_t.latn_txt_mismatch;
end
else -- when text is not wholly Latn script
if
return substitute (cfg.text_script_match_test_t.latn_scr_mismatch, {pos, char});
end
end
Line 1,040 ⟶ 1,039:
--[[--------------------------< B I
conducts a binary search of <ranges_t> for a sub-range that holds <target>.
returns boolean true if a sub-range holding <target> is found; boolean false else.
]]
local function
local idx_bot = 1; -- initialize to index of first key
if (target < ranges_t[idx_bot][1]) or (target > ranges_t[idx_top][2]) then -- invalid; target out of range
return; -- abandon
local idx_mid; -- calculated index of range midway between top index and bottom index
local flag = false; -- flag to tell us when we've evaluated last (highest) range in <ranges_t>
while 1 do
idx_mid = math.ceil ((idx_bot + idx_top) / 2); -- get the mid-point in the <ranges_t> sequence
if (target >= ranges_t[idx_mid][1]) and (target <= ranges_t[idx_mid][2]) then -- indexed range low value <= target <= indexed range high value
return true; -- we found the range that holds the <target> character; return true
elseif (target > ranges_t[idx_mid][2]) then -- is <target> > indexed range high value?
idx_bot = idx_mid; -- adjust <idx_bot> up
else -- here when <target> less than indexed range low value
idx_top = idx_mid - 1; -- adjust <idx_top> down
end
if flag then
break; -- here when we just evaluated the last range and <target> not found
end
if not flag and (idx_bot == idx_top) then -- set true just before we evaluate the last (highest) range in <ranges_t>
flag = true;
end
end
end
--[[--------------------------< I S _ L A T I N >--------------------------------------------------------------
compare <text> as codepoints to lists of known codepoints accepted as Latn script
returns boolean true and modified <text> when <text> is wrapped in accept-as-written markup
returns boolean true and <text> when codepoint is known
returns boolean false, <text>, non-Latn codepoint position in <text> (left to right), and the codepoint character
when codepoint is not known
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 HTML lang= attribute because <text> isn't really
latn so lang=und (undetermined)? or instead, omit the -Latn subtag? (without -Latn need to force |italic=yes)
]]
local function is_latin (text, tag)
local count;
text, count = text:gsub ('^%(%((.+)%)%)$', '%1'); -- remove accept-as-written markup if present
if 0 ~= count then
return true, text; -- markup present so assume that <text> is Latn-script
end
local pos = 0; -- position counter for error messaging
for codepoint in mw.ustring.gcodepoint (text) do -- fetch each code point
pos = pos + 1; -- bump the position counter
if not is_latn_data.singles_t[codepoint] and -- codepoint not found in the singles list?
not binary_search (codepoint, is_latn_data.ranges_t) and -- codepoint not a member of a listed range?
not (tag and is_latn_data.specials_t[codepoint] and is_latn_data.specials_t[codepoint][tag]) then -- not a language-specific codepoint?
return false, text, pos, mw.ustring.char (codepoint); -- codepoint not known; return false with codepoint position and character representation
end
end
return true, text; -- is known; return <text>
end
Line 1,075 ⟶ 1,121:
--[[--------------------------< _ L A N G >--------------------------------------------------------------------
<includeonly>{{#invoke:lang|lang}}</includeonly>
]]
Line 1,100 ⟶ 1,146:
if args[1] and args.code then
return make_error_msg (substitute (cfg.lang_t.conflict_n_param, {'1',
else
args.code = args[1] or args.code; -- prefer args.code
Line 1,106 ⟶ 1,152:
if args[2] and args.text then
return make_error_msg (substitute (cfg.lang_t.conflict_n_param, {'2',
else
args.text = args[2] or args.text; -- prefer args.text
Line 1,116 ⟶ 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,131 ⟶ 1,177:
end
local is_latn_text,
is_latn_text, args.text, pos, char= is_latin (args.text, code); -- make a boolean
msg = text_script_match_test (subtags.script, is_latn_text, pos, char)
if msg then -- if an error detected then there is an error message
return make_error_msg (msg, args, template);
Line 1,161 ⟶ 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,179 ⟶ 1,226:
--[[--------------------------< L A N G >----------------------------------------------------------------------
<includeonly>{{#invoke:lang|lang}}</includeonly>
]]
Line 1,216 ⟶ 1,263:
--[[--------------------------< T R A N S L A T I O N _ M A K E >----------------------------------------------
Also used by {{lang-x2}}.
]]
Line 1,226 ⟶ 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,232 ⟶ 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,283 ⟶ 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,304 ⟶ 1,351:
if args[text_idx] and args.text then
return make_error_msg (substitute (cfg.lang_t.conflict_n_param, {translit_idx,
else
args.text = args[text_idx] or args.text; -- prefer positional 'text' parameter
Line 1,314 ⟶ 1,361:
end
args.text, tag = html_tag_select (args.text); -- inspects text; returns appropriate
if args[translit_idx] and args.translit then
return make_error_msg (substitute (cfg.lang_t.conflict_n_param, {translit_idx,
else
Line 1,323 ⟶ 1,370:
end
args.engvar = cfg.engvar_sel_t[args.engvar] or cfg.default_engvar; -- |engvar= when valid; cfg.default_engvar else
if args[xlate_idx] and (args.translation or args.lit) then
return make_error_msg (substitute (cfg.lang_xx_t.conflict_n_lit, {translit_idx
elseif args.translation and args.lit then
return make_error_msg (cfg.lang_xx_t.conflict_lit, args, template);
Line 1,356 ⟶ 1,396:
end
if args.translit then
local latn, pos, char;
latn, args.translit, pos, char = is_latin (args.translit, (('' ~= subtags.private) and (code .. '-x-' .. subtags.private)) or code);
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)
msg = text_script_match_test (subtags.script, is_latn_text, pos, char)
if msg then -- if an error detected then there is an error message
return make_error_msg (msg, args, template);
Line 1,402 ⟶ 1,451:
args.proto, msg = validate_proto (args.proto); -- return boolean, or nil, or nil and error message flag
if msg then
return make_error_msg (
end
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,421 ⟶ 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,453 ⟶ 1,502:
if translit_title_obj.exists and (cfg.keywords_t.negative ~= args.link) then
table.insert (out, make_wikilink (substitute ('$1 $2', {cfg.lang_xx_t.romanization, translit_script_name or language_name}),
substitute ('$1', {
else
table.insert (out, substitute ('$1:', {
end
Line 1,468 ⟶ 1,517:
return make_error_msg (substitute ('$1: $2', {cfg.lang_xx_t.invalid_xlit_std, args['translit-std'] or '[missing]'}), args, template);
end
elseif is_set (args.translit) and is_latn_text then -- when creating a transliteration of Latn script <text>
return make_error_msg (cfg.lang_xx_t.xlit_of_latn, args, template); -- emit error message and abandon
end
if is_set (args.translation) then -- translation (not supported in {{lang}})
table.insert (out, translation_make (args));
Line 1,483 ⟶ 1,535:
--[[--------------------------< L A N G _ X X _ A R G S _ G E T >----------------------------------------------
]]
Line 1,514 ⟶ 1,566:
--[[--------------------------< L A N G _ X X _ I T A L I C >--------------------------------------------------
Entry point for those {{lang-??}} templates that call lang_xx_italic().
]]
Line 1,534 ⟶ 1,586:
--[[--------------------------< _ L A N G _ X X _ I T A L I C >------------------------------------------------
Entry point from another module.
]]
Line 1,546 ⟶ 1,598:
--[[--------------------------< L A N G _ X X _ I N H E R I T >------------------------------------------------
Entry point for those {{lang-??}} templates that call lang_xx_inherit().
]]
Line 1,566 ⟶ 1,618:
--[[--------------------------< _ L A N G _ X X _ I N H E R I T >----------------------------------------------
Entry point from another module.
]]
Line 1,613 ⟶ 1,665:
Entry point for {{langx}}.
this function calls _lang_xx() to render non-English text.
but {{langx}} has four:
| 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,626 ⟶ 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).
]]
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,644 ⟶ 1,696:
All code combinations supported by {{lang}} and the {{lang-??}} templates are supported by this function.
Module entry point from another module.
]]
Line 1,658 ⟶ 1,710:
--[[--------------------------< I S _ I E T F _ T A G >--------------------------------------------------------
Module entry point from an {{#invoke:}}.
]]
local function is_ietf_tag (frame)
return _is_ietf_tag (getArgs (frame)[1]); -- args[1] is the
end
Line 1,676 ⟶ 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,688 ⟶ 1,740:
Set invoke's |link= parameter to yes to get wikilinked version of the language name.
Module entry point from another module.
]]
Line 1,704 ⟶ 1,756:
if msg then
local template = (args['template'] and table.concat ({'{{', args['template'], '}}: '})) or ''; -- make template name (if provided by the template)
return
end
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
language_name = language_name:gsub ('%s+%b()', ''); -- remove IANA parenthetical disambiguators or qualifiers from names that have them
end
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[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,730 ⟶ 1,784:
--[[--------------------------< N A M E _ F R O M _ T A G >----------------------------------------------------
Module entry point from an {{#invoke:}}.
]]
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,741 ⟶ 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).
Module entry point from another module.
]]
Line 1,770 ⟶ 1,824:
template = table.concat ({'{{', args['template'], '}}: '}); -- make template name (if provided by the template)
end
return
end
Line 1,777 ⟶ 1,831:
--[[--------------------------< 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:
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,789 ⟶ 1,843:
--[[--------------------------< I S _ L A N G _ N A M E >------------------------------------------------------
Module entry point from an {{#invoke:}}.
]]
Line 1,799 ⟶ 1,853:
--[[--------------------------< _
Module entry point from another module.
]]
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,821 ⟶ 1,875:
if not title_table[args.translit_std] then
return make_error_msg (substitute (cfg.transl_t.unrecog_xlit_std, {args.translit_std}), args, template);
end
Line 1,833 ⟶ 1,886:
else
args.text = args[1]; -- args[1] is not a code so we're missing that; assign args.text for error message
return make_error_msg (cfg.transl_t.missing_lang_scr, args, template);
end
Line 1,839 ⟶ 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
else
return make_error_msg (substitute (cfg.transl_t.unrecog_lang_scr, {args[1]}), args, template); -- invalid language / script code
end
else
return make_error_msg (cfg.transl_t.missing_lang_scr, args, template); -- missing language / script code so quit
end
local
is_latn_text, args.text, pos, char= is_latin (args.text, args.code); -- is latn text? strip accept-as-written markup
if not is_latn_text then -- when text is not latn
return make_error_msg (substitute (cfg.lang_xx_t.translit_nonlatn, {pos, char}), args, template); -- abandon with error message
end
Line 1,860 ⟶ 1,910:
args.italic, msg = validate_italic (args);
if msg then
return make_error_msg (msg, args, template);
end
Line 1,868 ⟶ 1,917:
end
args.engvar =
if override_table[args.code] then -- is code a language code defined in the override table?
Line 1,882 ⟶ 1,931:
args.code = ''; -- unset because not a language code
else
return make_error_msg (substitute (cfg.transl_t.unrecog_lang_scr, {args.code}), args, template); -- invalid language / script code
end
Line 1,890 ⟶ 1,938:
--[[--------------------------<
Module entry point from an {{#invoke:}}.
]]
local function
return
end
Line 1,903 ⟶ 1,951:
--[[--------------------------< C A T E G O R Y _ F R O M _ T A G >--------------------------------------------
Returns category name associated with IETF language tag if valid; error message else.
All code combinations supported by {{lang}} and the {{lang-??}} templates are supported by this function.
Module entry point from another module.
]]
Line 1,923 ⟶ 1,971:
if msg then
local template = (args_t.template and table.concat ({'{{', args_t.template, '}}: '})) or ''; -- make template name (if provided by the template)
return
end
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,940 ⟶ 1,988:
--[[--------------------------< C A T E G O R Y _ F R O M _ T A G >--------------------------------------------
Module entry point from an {{#invoke:}}.
]]
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 1,953 ⟶ 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 1,961 ⟶ 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 1,974 ⟶ 2,022:
_tag_from_name = _tag_from_name,
_name_from_tag = _name_from_tag,
_translation_make = translation_make,
};
|