Module:Lang: Difference between revisions

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/Configurationconfiguration' .. (mw.getCurrentFrame():getTitle():match ('/sandbox') or '')); -- for internationalization
 
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 maker_error_spanmake_error_span (template, msg)
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 >----------------------------------------------------------
 
substitutesSubstitutes $1, $2, etc in <message> with data from <data_t>. Returns plain-text substituted string when
<data_t> not nil; returns <message> else.
 
]]
Line 60 ⟶ 63:
--[[--------------------------< M A K E _ E R R O R _ M S G >--------------------------------------------------
 
assemblesAssembles an error message from template name, message text, help link, and error category.
 
]]
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: {&#x7B;{$3}}: $4 ([[:Category:$5|$6]])</span>$7', -- &#x7B; prevents template name from being treated as a template call in certain situations
{
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 htmlHTML numeric entity equivalent so that the new italic markup doesn't become
bold markup inadvertently.
 
Line 186 ⟶ 190:
--[[--------------------------< V A L I D A T E _ I T A L I C >------------------------------------------------
 
validatesValidates |italic= or |italics= assigned values.
 
When |italic= is set and has an acceptibleacceptable assigned value, return the matching cssCSS font-style property value or,
for the special case 'default', return nil.
 
When |italic= is not set, or has an unacceptibleunacceptable assigned value, return nil and a nil error message.
 
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 translxlit function to set args.italic according to the template's
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 mainspacemain space.
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 >------------------------------------------------
 
prettifyPrettify ietfIETF tags to use recommended subtag formats:
code: lower case
script: sentence case
Line 317 ⟶ 321:
--[[--------------------------< G E T _ I E T F _ P A R T S >--------------------------------------------------
 
extractsExtracts and returns IETF language tag parts:
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=).
 
returnsReturns six values; all lower case. Valid parts are returned as themselves; omitted parts are returned as empty strings, invalid
parts are returned as nil; the sixth returned item is an error message (if an error detected) or nil.
 
seeSee http://www.rfc-editor.org/rfc/bcp/bcp47.txt section 2.1.
]]
 
local function get_ietf_parts (source, args_script, args_region, args_variant)
local code, script, region, variant, private; -- ietfIETF tag parts
 
if not is_set (source) then
Line 354 ⟶ 358:
end
 
local pattern = { -- table of tables holding acceptibeacceptable ietfIETF tag patterns and short names of the ietfIETF part captured by the pattern
{'^(%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 ietfIETF tag parts and named variables
 
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 ietfIETF parts to empty string for concatenation
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 okOK, invalid script, don't know about the others (don't care?)
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 okOK, script is suppressed for this code
end
end
Line 519 ⟶ 523:
--[[--------------------------< D I V _ M A R K U P _ A D D >--------------------------------------------------
 
addsAdds <i> and </i> tags to list-item text or to implied <p>..</p> text. mixedMixed not supported.
 
]]
 
local function div_markup_add (text, style)
local implied_p = {};
 
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 mediawikiMediaWiki
 
if 'italic' == style then
text = text:gsub('[^\n]+', '<p><i>%1</i></p>'); -- insert p and italic markup tags at each impledimplied p (two or more consecutive '\n\n' sequences)
else
text = text:gsub ('[^\n]+', '<p>%1</p>'); -- insert p markup at each impledimplied p
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 >------------------------------------------
 
makesMakes 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
htmlHTML markup. This because the lang= attibuteattribute applies to the content of its enclosing tag.
 
<tag> holds a string 'div' or 'span' used to choose the correct wrapping tag.
 
<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 htmlHTML markup to text according to the type of content that it is: <span> or <i> tags for inline content or
<div> tags for block content
 
Line 597 ⟶ 600:
end
 
if 'span' == tag then -- default htmlHTML tag for inline content
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> htmlHTML tag
code = code:gsub ('%-x%-.*', ''); -- strip private use subtag from code tag because meaningless outside of wikipediaWikipedia
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 htmlHTML tag
table.insert (html_t, text); -- insert the text
 
table.insert (html_t, table.concat ({'</', tag, '>'})); -- close the 'text' <i>, <span>, or <div> htmlHTML tag
 
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]]
 
forFor English:
[[Category:Articles containing explicitly cited English-language text]]
forFor ISO 639-2 collective languages (and for 639-1 bh):
[[Category:Articles with text in <language> languages]]
 
Line 665 ⟶ 668:
 
local function make_category (code, language_name, nocat, name_get)
local cat = {};
local retval;
 
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 >----------------------------------------------------
 
returnReturn translit <i lang=xx-Latn>...</i> where xx is the language code; else return empty string.
 
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 translxlit()
lang_xx() always provides code, language_name, and translit; may provide tscript; never provides style
translxlit() always provides language_name, translit, and one of code or tscript, never both; always provides style
 
For {{transliteration}}, style only applies when a language code is provided.
 
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;
local out_t = {};
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, lang_datamw.ustring.lower (cfg.engvar_t[engvar]['romanisz_lc'])}); -- finish the tool tip; use romanization when neither script nor standard supplied
 
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 (translxlit may not provide a language code)
title_text = substitute ('$1$2 ($3 $4) $5', { -- add the appropriate text to the tool tip
title_text,
Line 796 ⟶ 795:
end
 
local close_tag;tag
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
table.inserttag (out_t,= "'<i lang=\"%s-Latn"); -- so use >%s</i> tag'
close_tag = '</i>'; -- tag to be used when closing
else
table.inserttag (out_t, table.concat= ({'<span style=\"font-style: ', style, '\%s" lang=\"%s-Latn">%s</span>'})); -- non-standard style, construct a span tag for it
tag = string.format(tag, style, "%s", "%s")
close_tag = '</span>'; -- tag to be used when closing
end
table.inserttag = string.format(out_ttag, code, "%s");
table.insert (out_t, "-Latn\">"); -- transliterations are always Latin script
else
table.inserttag (out_t,= "'<span>");%s</span>' -- when no language code: no lang= attribute, not italic ({{transliteration}} only)
close_tag = '</span>';
end
 
table.inserttag = string.format(out_ttag, translit); -- add the translit text
table.insert (out_t, close_tag); -- and add the appropriate </i> or </span>
 
if '' == title_text then -- when there is no need for a tool-tip
return table.concat (out_t)tag; -- make a string and done
else
title_text = 'gb_t'cfg.engvar_sel_t.gb == engvar and title_text:gsub ('([Rr]omani)z', '%1s') or title_text; -- gb eng when engvar specifies gb eng; us eng else
return title_wrapper_make (title_text, table.concat (out_t)tag, 'span'); -- wrap with a tool-tip span and done
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. The tests are for empty or missing text and for improper or disallowed use of apostrophe markup.
 
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 ('no text'cfg.validate_text_t.no_text, args, template);
end
 
Line 857 ⟶ 850:
--[[--------------------------< R E N D E R _ M A I N T >------------------------------------------------------
 
renderRender mainenance messages and categories.
 
]]
Line 884 ⟶ 877:
--[[--------------------------< P R O T O _ P R E F I X >------------------------------------------------------
 
forFor proto languages, text is prefixed with a splat. We do that here as a flag for make_text_html() so that a splat
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.
 
]]
Line 906 ⟶ 899:
--[[--------------------------< H A S _ P O E M _ T A G >------------------------------------------------------
 
looksLooks for a poem strip marker in text; returns true when found; false else.
 
autoAuto-italic detection disabled when text has poem stripmarker because it is not possible for this code to know
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 htmlHTML tag for text.
 
If text contains:
Line 963 ⟶ 956:
--[[--------------------------< V A L I D A T E _ P R O T O >--------------------------------------------------
 
validatesValidates 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 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 >--------------------------------------------
 
commonCommon function to return language name from the data set according to IETF tag.
 
returnsReturns language name if found in data tables; nil else.
 
]]
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 ianaIANA active tag/name table
name = lang_table[code];
elseif lang_dep_table[code] then -- try the ianaIANA deprecated tag/name table
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
returns an error message when mismatch detected; nil else
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)
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 ('Latn' ~= script and 'latn' ~=not scripts_t[script)] then -- but a non-Latn script is specified
return cfg.text_script_match_test_t.latn_txt_mismatch; -- emit an error message
end
else -- when text is not wholly Latn script
if ('Latn' == script or 'latn' == scripts_t[script)] then -- but a Latn script is specified
return substitute (cfg.text_script_match_test_t.latn_scr_mismatch, {pos, char}); -- emit an error message with position of first offending character
end
end
Line 1,040 ⟶ 1,039:
 
 
--[[--------------------------< B I SN A R Y _ LS E A TR IC NH >--------------------------------------------------------------
 
conducts a binary search of <ranges_t> for a sub-range that holds <target>.
created because unicode does not have Latin theta 'θ' character. The Greek 'θ' is, apparently, commonly used
 
in certain romanizations. This function attempts to discover if <text> script is Latn with Greek 'θ' or some
returns boolean true if a sub-range holding <target> is found; boolean false else.
other script with Greek 'θ'.
 
when <text> is or has Greek 'θ':
for {{lang}}, {{langx}}, and {{lang-??}}, returns boolean true when <text>:
has theta and all other characters are Latn
has theta as the only character, <script> is Latn
for {{transliteration}}, returns boolean true when <text>:
has theta and all other characters are Latn
has theta as the only character
]]
 
local function is_latinbinary_search (texttarget, script, translranges_t)
local idx_bot = 1; -- initialize to index of first key
if mw.ustring.find (text, 'θ', 1, true) then -- does <text> contain 'θ'?
text local idx_top = text:gsub ('θ', '')sizeof_ranges_t; -- removeinitialize thetato fromindex <text>of last key (number of keys)
 
if 0 == text:len() then -- will be zero if theta was the only character in <text>
if (target < ranges_t[idx_bot][1]) or (target > ranges_t[idx_top][2]) then -- invalid; target out of range
if transl then -- not nil for {{transliteration}}; assume Latin theta because this is 'transliteration' template
return; -- abandon
return true;
end
 
return (script and ('latn' == script:lower())) or false; -- {{lang}}, {{langx}}, and {{lang-??}}; true when script is Latn; false else
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
return unicode.is_Latin (text); -- return true when all characters in modified <text> are Latn script; false else
end
end
 
 
return unicode.is_Latin (text); -- return true when all characters in <text> are Latn script; false else
--[[--------------------------< 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 >--------------------------------------------------------------------
 
entryEntry point for {{lang}}.
 
thereThere should be no reason to set parameters in the {{lang}} {{#invoke:}}
<includeonly>{{#invoke:lang|lang}}</includeonly>
 
parametersParameters are received from the template's frame (parent frame).
 
]]
Line 1,100 ⟶ 1,146:
 
if args[1] and args.code then
return make_error_msg (substitute (cfg.lang_t.conflict_n_param, {'1', 'cfg.lang_t.conflict_n_param_types.code'}), args, template);
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', 'cfg.lang_t.conflict_n_param_types.text'}), args, template);
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 htmlHTML tag with text trimmed accordingly
 
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_latin (args.textpos, subtags.script)char; -- make a boolean
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 ietfIETF tag first, then code w/o variant then code w/ variant
 
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 >----------------------------------------------------------------------
 
entryEntry point for {{lang}}.
 
thereThere should be no reason to set parameters in the {{lang}} {{#invoke:}}
<includeonly>{{#invoke:lang|lang}}</includeonly>
 
parametersParameters are received from the template's frame (parent frame).
 
]]
Line 1,216 ⟶ 1,263:
--[[--------------------------< T R A N S L A T I O N _ M A K E >----------------------------------------------
 
standStand-alone function to create literal translation of main text.
 
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> htmlHTML tag
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, "&thinsp;</small>"); -- close the <small> htmlHTML tag
end
table.insert (translation_t, table.concat ({'&#39;', args_t.translation, '&#39;'})); -- use htmlHTML entities to avoid wiki markup confusion
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 'Langxlangx' or 'Langlang-xx'
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, 'cfg.lang_t.conflict_n_param_types.text'}), args, template);
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 htmlHTML tag with text trimmed accordingly
 
if args[translit_idx] and args.translit then
return make_error_msg (substitute (cfg.lang_t.conflict_n_param, {translit_idx, 'cfg.lang_t.conflict_n_param_types.translit'}), args, template);
 
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.translit then
local latn, pos = is_latin (args.translit, nil, true);
if not latn then
return make_error_msg (substitute (cfg.lang_xx_t.translit_nonlatn, {pos}), args, template);
end
end
 
args.engvar = lang_data.engvar_sel_t[args.engvar] or 'us_t'; -- either 'gb_t' or 'us_t' when |engvar= valid; 'us_t' 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, '&#124;lit= or &#124;translation='}), args, template);
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 is_latn_text = is_latin (args.text, subtags.script); -- make a boolean
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 (table.concatsubstitute ({'invalid &#124;proto=: 'cfg.lang_t.invalid_proto, {args.proto}), args, template);
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 ietfIETF tag first, then code w/o variant then code w/ variant
 
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 ietfIETF tag in article name over ride?
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', {lang_datacfg.engvar_t[args.engvar]['romanisz_pt']})) .. ':'); -- make a wikilink if there is an article to link to; engvar the display text
 
else
table.insert (out, substitute ('$1:', {lang_datacfg.engvar_t[args.engvar]['romanisz_pt']})); -- else plain text per engvar
 
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
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 >----------------------------------------------
 
commonCommon function to get args table from {{lang-??}} templates.
 
returnsReturns table of args.
 
textText positional parameters are not trimmed here but are selectively trimmed at html_tag_select().
 
]]
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(). Sets the initial style state to italic.
 
]]
Line 1,534 ⟶ 1,586:
--[[--------------------------< _ L A N G _ X X _ I T A L I C >------------------------------------------------
 
Entry point from another module. Sets the initial style state to italic.
 
]]
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(). Sets the initial style state to inherit.
 
]]
Line 1,566 ⟶ 1,618:
--[[--------------------------< _ 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.
 
]]
Line 1,613 ⟶ 1,665:
Entry point for {{langx}}.
 
this function calls _lang_xx() to render non-English text. The {{lang-??}} templates have three positional paramters
but {{langx}} has four:
 
| 1 | 2 | 3 | 4
{{lang-xx |<text> |<translxlit> |<xlatexlat> }}
{{langx |<tag> |<text> |<translxlit> |<xlatexlat> }}
 
The calls to lang_xx_args_get() and _lang_xx() use 'Langxlangx' as a flag for those functions to select the proper
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. Langxlangx() now
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; 'Langxlangx' is the <base_template> used to decide which positional param is 'text', 'translit', 'lit'
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 ietfIETF language tag to be tested; also get parent frame
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 ietfIETF language tag to be tested; do not get parent frame
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 maker_error_spanmake_error_span (template, msg);
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 ietfIETF tag first, then code w/o variant then code w/ variant
 
if 'yes' ~= args.raw then
language_name = language_name:gsub ('%s+%b()', ''); -- remove IANA parenthetical disambiguators or qualifiers from names that have them
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 ietfIETF tag in article name override?
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:Langlang|name_from_tag|<ietfIETF tag>|link=<yes>|template=<template name>}}
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 ietfIETF 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.
 
]]
Line 1,770 ⟶ 1,824:
template = table.concat ({'{{', args['template'], '}}: '}); -- make template name (if provided by the template)
end
return substitute (maker_error_spanmake_error_span (template, msg));
 
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:Langlang|tag_from_name|<language name>|link=<yes>|template=<template name>}}
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:
 
 
--[[--------------------------< _ TX RL AI N S LT >--------------------------------------------------------------------
 
Module entry point from another module.
 
]]
 
local function _transl_xlit (args)
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, cfg.templates_t.transliteration);
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, cfg.templates_t.transliteration);
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 htmlHTML lang= attribute; or ISO 15924 script code
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, cfg.templates_t.transliteration); -- invalid language / script code
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, cfg.templates_t.transliteration); -- missing language / script code so quit
return make_error_msg (cfg.transl_t.missing_lang_scr, args, template); -- missing language / script code so quit
end
 
local latnis_latn_text, pos = is_latin (args.text, nil, true)char;
is_latn_text, args.text, pos, char= is_latin (args.text, args.code); -- is latn text? strip accept-as-written markup
if not latn then -- text is not latn
if not is_latn_text then -- when text is not latn
-- return make_error_msg (substitute (cfg.lang_xx_t.translit_nonlatn, {pos}), args, cfg.templates_t.transliteration);
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, cfg.templates_t.transliteration);
return make_error_msg (msg, args, template);
end
Line 1,868 ⟶ 1,917:
end
 
args.engvar = lang_datacfg.engvar_sel_t[args.engvar] or 'us_t'cfg.default_engvar; -- either 'gb_t' or 'us_t' when |engvar= when valid; 'us_t'cfg.default_engvar else
 
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, cfg.templates_t.transliteration); -- invalid language / script code
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:
 
 
--[[--------------------------< TX RL AI N S LT >----------------------------------------------------------------------
 
Module entry point from an {{#invoke:}}.
 
]]
 
local function translxlit (frame)
return _transl_xlit (getArgs(frame));
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 maker_error_spanmake_error_span (template, msg);
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 ietfIETF tag first, then code w/o variant then code w/ variant
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:Langlang|category_from_tag|<ietfIETF tag>|template=<template name>}}
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 ietfIETF tag associated with language name
name_from_tag = name_from_tag, -- used for template documentation; possible use in ISO 639 name from code templates
translxlit = translxlit, -- entry point for {{transliteration}}
_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,
_transl_xlit = _transl_xlit,
_translation_make = translation_make,
};