Module:Lang: Difference between revisions
Appearance
m 1 revision imported |
Template>Trappist the monk No edit summary |
||
| Line 8: | Line 8: | ||
local getArgs = require ('Module:Arguments').getArgs; | local getArgs = require ('Module:Arguments').getArgs; | ||
local unicode = require ("Module:Unicode data"); -- for | local unicode = require ("Module:Unicode data"); -- for is_Latin() and is_rtl() | ||
local yesno = require ('Module:Yesno'); | local yesno = require ('Module:Yesno'); | ||
| Line 23: | Line 23: | ||
local synonym_table = mw.loadData ('Module:Lang/ISO 639 synonyms'); -- ISO 639-2/639-2T code translation to 639-1 code | 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 cfg = mw.loadData ('Module:Lang/configuration' .. (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 | local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization | ||
| Line 36: | Line 39: | ||
local maint_msgs = {}; -- and their messages go here | local maint_msgs = {}; -- and their messages go here | ||
local | |||
--[[--------------------------< M A K E _ E R R O R _ S P A N >-------------------------------------------------- | |||
]] | |||
local function make_error_span (template, msg) | |||
return table.concat ({'<span style="color:#d33">', cfg.misc_text_t.error, ': ', template, msg, '</span>'}) | |||
end | |||
--[[--------------------------< S U B S T I T U T E >---------------------------------------------------------- | --[[--------------------------< S U B S T I T U T E >---------------------------------------------------------- | ||
Substitutes $1, $2, etc in <message> with data from <data_t>. Returns plain-text substituted string when | |||
<data_t> not nil; returns <message> else | <data_t> not nil; returns <message> else. | ||
]] | ]] | ||
| Line 57: | Line 63: | ||
--[[--------------------------< M A K E _ E R R O R _ M S G >-------------------------------------------------- | --[[--------------------------< M A K E _ E R R O R _ M S G >-------------------------------------------------- | ||
Assembles an error message from template name, message text, help link, and error category. | |||
]] | ]] | ||
| Line 64: | Line 70: | ||
local category; | local category; | ||
local text; -- handle the oddity that is {{langx}} | local text; -- handle the oddity that is {{langx}} | ||
if | if cfg.templates_t.langxx == template then | ||
text = args_t.text or args_t[1]; -- for {{lang-xx}} | text = args_t.text or args_t[1]; -- for {{lang-xx}} | ||
else | else | ||
| Line 70: | Line 76: | ||
end | end | ||
if | if cfg.templates_t.transliteration == template then | ||
category = cfg.make_error_msg_t.xlit_err_cat; | category = cfg.make_error_msg_t.xlit_err_cat; | ||
else | else | ||
| Line 76: | Line 82: | ||
end | end | ||
local category_link = ((0 == namespace or 10 == namespace) and not args_t.nocat) and substitute ('[[Category:$1 | 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: {{$3}}: $4 ([[:Category:$5 | return substitute ('[$1] <span style="color:#d33">$2: {{$3}}: $4 ([[:Category:$5|$6]])</span>$7', | ||
{ | { | ||
text or cfg.make_error_msg_t.undefined, | text or cfg.make_error_msg_t.undefined, | ||
| Line 84: | Line 90: | ||
msg, | msg, | ||
category, | category, | ||
cfg.misc_text_t.help, | |||
category_link | category_link | ||
}) | }) | ||
| Line 90: | Line 97: | ||
--[[--------------------------< P A R A M E T E R _ V A L I D A T E >------------------------------------------ | --[[--------------------------< P A R A M E T E R _ V A L I D A T E >------------------------------------------ | ||
]] | ]] | ||
| Line 95: | Line 103: | ||
local err_msg = cfg.parameter_validate_t.invalid_param; | local err_msg = cfg.parameter_validate_t.invalid_param; | ||
if | if cfg.templates_t.lang == template then -- for {{lang}} | ||
for param, _ in pairs (args_t) do | for param, _ in pairs (args_t) do | ||
if not cfg.known_params_t.params_lang_t[param] and -- unique {{lang}} parameters | if not cfg.known_params_t.params_lang_t[param] and -- unique {{lang}} parameters | ||
| Line 102: | Line 110: | ||
end | end | ||
end | end | ||
elseif | elseif cfg.templates_t.langx == template then -- for {{langx}} | ||
for param, _ in pairs (args_t) do | for param, _ in pairs (args_t) do | ||
if not cfg.known_params_t.params_langx_t[param] and -- unique {{langx}} parameters | if not cfg.known_params_t.params_langx_t[param] and -- unique {{langx}} parameters | ||
| Line 110: | Line 118: | ||
end | end | ||
end | end | ||
elseif | elseif cfg.templates_t.langxx == template then -- for {{lang-xx}} | ||
for param, _ in pairs (args_t) do | for param, _ in pairs (args_t) do | ||
if not cfg.known_params_t.params_lang_xx_t[param] and -- unique {{lang-xx}} parameters | if not cfg.known_params_t.params_lang_xx_t[param] and -- unique {{lang-xx}} parameters | ||
| Line 129: | Line 137: | ||
]] | ]] | ||
local function is_set( var ) | local function is_set (var) | ||
return not (var == nil or var == ''); | return not (var == nil or var == ''); | ||
end | end | ||
| Line 182: | Line 190: | ||
--[[--------------------------< V A L I D A T E _ I T A L I C >------------------------------------------------ | --[[--------------------------< V A L I D A T E _ I T A L I C >------------------------------------------------ | ||
Validates |italic= or |italics= assigned values. | |||
When |italic= is set and has an acceptible assigned value, return the matching css font-style property value or, | When |italic= is set and has an acceptible assigned value, return the matching css font-style property value or, | ||
| Line 207: | Line 215: | ||
local function validate_italic (args) | local function validate_italic (args) | ||
local properties = {[cfg.keywords_t.affirmative] = 'italic', [cfg.keywords_t.negative] = 'normal', [ | local properties = {[cfg.keywords_t.affirmative] = 'italic', [cfg.keywords_t.negative] = 'normal', [cfg.keywords_t.unset] = 'inherit', [cfg.keywords_t.invert] = 'invert', [cfg.keywords_t.default] = nil}; | ||
local count = 0 | local count = 0 | ||
| Line 258: | Line 266: | ||
--[[--------------------------< I N _ A R R A Y >-------------------------------------------------------------- | --[[--------------------------< I N _ A R R A Y >-------------------------------------------------------------- | ||
Whether needle is in haystack | Whether needle is in haystack. | ||
]] | ]] | ||
local function in_array ( needle, haystack ) | local function in_array (needle, haystack) | ||
if needle == nil then | if needle == nil then | ||
return false; | return false; | ||
end | end | ||
for n,v in ipairs( haystack ) do | for n,v in ipairs (haystack) do | ||
if v == needle then | if v == needle then | ||
return n; | return n; | ||
| Line 277: | Line 285: | ||
--[[--------------------------< F O R M A T _ I E T F _ T A G >------------------------------------------------ | --[[--------------------------< F O R M A T _ I E T F _ T A G >------------------------------------------------ | ||
Prettify ietf tags to use recommended subtag formats: | |||
code: lower case | code: lower case | ||
script: sentence case | script: sentence case | ||
| Line 313: | Line 321: | ||
--[[--------------------------< G E T _ I E T F _ P A R T S >-------------------------------------------------- | --[[--------------------------< G E T _ I E T F _ P A R T S >-------------------------------------------------- | ||
Extracts and returns IETF language tag parts: | |||
primary language subtag (required) - 2 or 3 character IANA language code | primary language subtag (required) - 2 or 3 character IANA language code | ||
script subtag - four character IANA script code | script subtag - four character IANA script code | ||
| Line 327: | Line 335: | ||
lang-x-private | lang-x-private | ||
each of lang, script, region, variant, and private, when used, must be valid | 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 | Languages with both two- and three-character code synonyms are promoted to the two-character synonym because | ||
| Line 334: | Line 342: | ||
For {{lang-??}} templates, the parameters |script=, |region=, and |variant= are supported (not supported in {{lang}} | 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=) | because those parameters are superfluous to the IETF subtags in |code=). | ||
Returns 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. | parts are returned as nil; the sixth returned item is an error message (if an error detected) or nil. | ||
See http://www.rfc-editor.org/rfc/bcp/bcp47.txt section 2.1. | |||
]] | ]] | ||
| Line 515: | Line 523: | ||
--[[--------------------------< D I V _ M A R K U P _ A D D >-------------------------------------------------- | --[[--------------------------< D I V _ M A R K U P _ A D D >-------------------------------------------------- | ||
Adds <i> and </i> tags to list-item text or to implied <p>..</p> text. Mixed not supported. | |||
]] | ]] | ||
local function div_markup_add (text, style) | 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 text:find ('^\n[%*:;#]') then -- look for list markup; list markup must begin at start of text | ||
if 'italic' == style then | if 'italic' == style then | ||
| Line 547: | Line 553: | ||
--[[--------------------------< T I T L E _ W R A P P E R _ M A K E >------------------------------------------ | --[[--------------------------< T I T L E _ W R A P P E R _ M A K E >------------------------------------------ | ||
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 | <title text> is in the tool-tip in the wiki's local language and <content_text> is non-local-language text in | ||
html markup. This because the lang= attibute applies to the content of its enclosing tag. | html markup. This because the lang= attibute 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 652: | Line 659: | ||
[[Category:Articles containing <language>-language text]] | [[Category:Articles containing <language>-language text]] | ||
For English: | |||
[[Category:Articles containing explicitly cited English-language text]] | [[Category:Articles containing explicitly cited English-language text]] | ||
For ISO 639-2 collective languages (and for 639-1 bh): | |||
[[Category:Articles with text in <language> languages]] | [[Category:Articles with text in <language> languages]] | ||
| Line 661: | Line 668: | ||
local function make_category (code, language_name, nocat, name_get) | 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 | if ((0 ~= namespace) or nocat) and not name_get then -- only categorize in article space | ||
return ''; -- return empty string for concatenation | return ''; -- return empty string for concatenation | ||
| Line 691: | Line 695: | ||
--[[--------------------------< M A K E _ T R A N S L I T >---------------------------------------------------- | --[[--------------------------< M A K E _ T R A N S L I T >---------------------------------------------------- | ||
Return 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 | The value |script= is not used in {{transliteration}} for this purpose; instead it uses |code. Because language scripts | ||
| Line 698: | Line 702: | ||
To avoid confusion, in this module and the templates that use it, the transliteration script parameter is renamed | 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) | to be |translit-script= (in this function, tscript). | ||
This function is used by both lang_xx() and transl() | This function is used by both lang_xx() and transl() | ||
| Line 704: | Line 708: | ||
transl() always provides language_name, translit, and one of code or tscript, never both; always provides style | transl() 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 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_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 | local title_text = ''; -- tool tip text for title= attribute | ||
| Line 720: | Line 723: | ||
title_text = substitute ('$1-$2', {title_text, cfg.misc_text_t.language}); -- skip this text (individual and macro languages only) | title_text = substitute ('$1-$2', {title_text, cfg.misc_text_t.language}); -- skip this text (individual and macro languages only) | ||
end | end | ||
title_text = substitute ('$1 $2', {title_text, | title_text = substitute ('$1 $2', {title_text, mw.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 | elseif is_set (std) and is_set (tscript) then -- when both are specified | ||
| Line 747: | Line 750: | ||
if title_t[std][code] then -- if language code is in the table (transl may not provide a language code) | if title_t[std][code] then -- if language code is in the table (transl may not provide a language code) | ||
title_text = substitute ('$1$2 ($3 $4) $5', { | title_text = substitute ('$1$2 ($3 $4) $5', { -- add the appropriate text to the tool tip | ||
title_text, | title_text, | ||
title_t[std][code:lower()], | title_t[std][code:lower()], | ||
| Line 792: | Line 795: | ||
end | end | ||
local | local tag | ||
if is_set (code) then -- when a language code is provided (always with {{lang-??}} templates, not always with {{transliteration}}) | 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 | code = code:match ('^(%a%a%a?)'); -- strip all subtags leaving only the language subtag | ||
if not style then -- nil for the default italic style | if not style then -- nil for the default italic style | ||
tag = '<i lang="%s-Latn">%s</i>' | |||
else | else | ||
tag = '<span style="font-style: %s" lang="%s-Latn">%s</span>' -- non-standard style, construct a span tag for it | |||
tag = string.format(tag, style, "%s", "%s") | |||
end | end | ||
tag = string.format(tag, code, "%s") | |||
else | else | ||
tag = '<span>%s</span>' -- when no language code: no lang= attribute, not italic ({{transliteration}} only) | |||
end | end | ||
tag = string.format(tag, translit) -- add the translit text | |||
if '' == title_text then -- when there is no need for a tool-tip | if '' == title_text then -- when there is no need for a tool-tip | ||
return | return tag; -- done | ||
else | else | ||
title_text = | title_text = 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, | return title_wrapper_make (title_text, tag, 'span'); -- wrap with a tool-tip span and done | ||
end | end | ||
end | end | ||
| Line 825: | Line 822: | ||
This function checks the content of args.text and returns empty string if nothing is amiss else it returns an | This function checks the content of args.text and returns empty string if nothing is amiss else it returns an | ||
error message. | 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 | Italic rendering is controlled by the |italic= template parameter so italic markup should never appear in args.text | ||
| Line 834: | Line 831: | ||
local function validate_text (template, args) | local function validate_text (template, args) | ||
if not is_set (args.text) then | if not is_set (args.text) then | ||
return make_error_msg ( | return make_error_msg (cfg.validate_text_t.no_text, args, template); | ||
end | end | ||
| Line 853: | Line 850: | ||
--[[--------------------------< R E N D E R _ M A I N T >------------------------------------------------------ | --[[--------------------------< R E N D E R _ M A I N T >------------------------------------------------------ | ||
Render mainenance messages and categories. | |||
]] | ]] | ||
| Line 880: | Line 877: | ||
--[[--------------------------< P R O T O _ P R E F I X >------------------------------------------------------ | --[[--------------------------< P R O T O _ P R E F I X >------------------------------------------------------ | ||
For 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). | will be rendered outside of italic markup (if used). If the first character in text here is already a splat, we | ||
do nothing | do nothing. | ||
proto_param is boolean or nil; true adds splat prefix regardless of language name; false removes and | proto_param is boolean or nil; true adds splat prefix regardless of language name; false removes and inhibits | ||
regardless of language name; nil does nothing; presumes that the value in text is correct but removes extra splac | regardless of language name; nil does nothing; presumes that the value in text is correct but removes extra splac. | ||
]] | ]] | ||
| Line 902: | Line 899: | ||
--[[--------------------------< H A S _ P O E M _ T A G >------------------------------------------------------ | --[[--------------------------< H A S _ P O E M _ T A G >------------------------------------------------------ | ||
Looks for a poem strip marker in text; returns true when found; false else. | |||
Auto-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. | the content that will replace the stripmarker. | ||
| Line 959: | Line 956: | ||
--[[--------------------------< V A L I D A T E _ P R O T O >-------------------------------------------------- | --[[--------------------------< 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 nil with <proto_param> as second | 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. | return value for use in error message. | ||
| Line 980: | Line 977: | ||
--[[--------------------------< L A N G U A G E _ N A M E _ G E T >-------------------------------------------- | --[[--------------------------< L A N G U A G E _ N A M E _ G E T >-------------------------------------------- | ||
Common function to return language name from the data set according to IETF tag. | |||
Returns language name if found in data tables; nil else. | |||
]] | ]] | ||
| Line 1,018: | Line 1,015: | ||
Conversely, when <text> is written using the Latn script, the IETF script subtag, if present, should be Latn. | 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) | |||
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 | 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 is_latn_text then -- when text is wholly Latn script | ||
if | if not scripts_t[script] then -- but a non-Latn script is specified | ||
return cfg.text_script_match_test_t.latn_txt_mismatch; | return cfg.text_script_match_test_t.latn_txt_mismatch; -- emit an error message | ||
end | end | ||
else -- when text is not wholly Latn script | else -- when text is not wholly Latn script | ||
if | if scripts_t[script] then -- but a Latn script is specified | ||
return cfg.text_script_match_test_t.latn_scr_mismatch; | 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 | ||
end | end | ||
| Line 1,036: | Line 1,039: | ||
--[[--------------------------< _ | --[[--------------------------< B I N A R Y _ S E A R C H >--------------------------------------------------- | ||
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 function binary_search (target, ranges_t) | ||
local | local idx_bot = 1; -- initialize to index of first key | ||
local idx_top = sizeof_ranges_t; -- initialize to index of last key (number of keys) | |||
local | |||
if (target < ranges_t[idx_bot][1]) or (target > ranges_t[idx_top][2]) then -- invalid; target out of range | |||
return; -- abandon | |||
end | end | ||
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 | ||
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}}) | |||
--[[--------------------------< I S _ L A T I N >-------------------------------------------------------------- | |||
if msg then | |||
return make_error_msg ( msg, args, template); | compare <text> as codepoints to lists of known codepoints accepted as Latn script | ||
end | |||
returns boolean true and modified <text> when <text> is wrapped in accept-as-written markup | |||
local is_latn_text = | |||
returns boolean true and <text> when codepoint is known | |||
msg = text_script_match_test (subtags.script, is_latn_text) | |||
if msg then -- if an error detected then there is an error message | returns boolean false, <text>, non-Latn codepoint position in <text> (left to right), and the codepoint character | ||
return make_error_msg (msg, args, template); | when codepoint is not known | ||
end | |||
TODO: when text has accept-as-written markup, return a non-boolean value to indicate that <text> is not wholly | |||
args.italic, msg = validate_italic (args); | latn script? Use that return value to create non-Latn html lang= attribute because <text> isn't really | ||
if msg then | latn so lang=und (undetermined)? or instead, omit the -Latn subtag? (without -latn need to force |italic=yes) | ||
return make_error_msg (msg, args, template); | |||
end | ]] | ||
if nil == args.italic then -- nil when |italic= absent or not set or |italic=default; args.italic controls | local function is_latin (text, tag) | ||
if ('latn' == subtags.script) or -- script is latn | local count; | ||
(this_wiki_lang_tag ~= code and not is_set (subtags.script) and not has_poem_tag (args.text) and is_latn_text) then -- text not this wiki's language, no script specified and not in poem markup but is wholly latn script (auto-italics) | text, count = text:gsub ('^%(%((.+)%)%)$', '%1'); -- remove accept-as-written markup if present | ||
args.italic = 'italic'; -- DEFAULT for {{lang}} templates is upright; but if latn script set for font-style:italic | if 0 ~= count then | ||
else | return true, text; -- markup present so assume that <text> is Latn-script | ||
args.italic = 'inherit'; -- italic not set; script not latn; inherit current style | end | ||
end | |||
end | local pos = 0; -- position counter for error messaging | ||
for codepoint in mw.ustring.gcodepoint (text) do -- fetch each code point | |||
if is_set (subtags.script) then -- if script set, override rtl setting | pos = pos + 1; -- bump the position counter | ||
if in_array (subtags.script, lang_data.rtl_scripts) then | |||
args.rtl = true; -- script is an rtl script | if not is_latn_data.singles_t[codepoint] and -- codepoint not found in the singles list? | ||
else | not binary_search (codepoint, is_latn_data.ranges_t) and -- codepoint not a member of a listed range? | ||
args.rtl = false; -- script is not an rtl script | not (tag and is_latn_data.specials_t[codepoint] and is_latn_data.specials_t[codepoint][tag]) then -- not a language-specific codepoint? | ||
end | return false, text, pos, mw.ustring.char (codepoint); -- codepoint not known; return false with codepoint position and character representation | ||
end | end | ||
end | |||
args.code = format_ietf_tag (code, subtags.script, subtags.region, subtags.variant, subtags.private); -- format to recommended subtag styles | return true, text; -- is known; return <text> | ||
language_name = language_name_get (args.code, code, true); -- get language name; try ietf tag first, then code w/o variant then code w/ variant | end | ||
if cfg.keywords_t.invert == args.italic and 'span' == tag then | |||
args.text = invert_italics (args.text) | --[[--------------------------< _ L A N G >-------------------------------------------------------------------- | ||
end | |||
Entry point for {{lang}}. | |||
There should be no reason to set parameters in the {{lang}} {{#invoke:}} | |||
<includeonly>{{#invoke:lang|lang}}</includeonly> | |||
Parameters are received from the template's frame (parent frame). | |||
]] | |||
local function _lang (args) | |||
local out = {}; | |||
local language_name; -- used to make category names | |||
local category_name; -- same as language_name except that it retains any parenthetical disambiguators (if any) from the data set | |||
local subtags = {}; -- IETF subtags script, region, variant, and private | |||
local code; -- the language code | |||
local msg; -- for error messages | |||
local tag = 'span'; -- initial value for make_text_html() | |||
local template = args.template or cfg.templates_t.lang; | |||
maint_cats = {}; -- initialize because when this module required into another module, these only declared once so only initialzed once | |||
maint_msgs = {}; | |||
validate_cat_args (args); -- determine if categorization should be suppressed | |||
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 | |||
end | |||
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 | |||
end | |||
msg = validate_text (template, args); -- ensure that |text= is set | |||
if is_set (msg) then -- msg is an already-formatted error message | |||
return msg; | |||
end | |||
args.text, tag = html_tag_select (args.text); -- inspects text; returns appropriate html tag with text trimmed accordingly | |||
args.rtl = args.rtl == cfg.keywords_t.affirmative; -- 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 (substitute (cfg.lang_t.invalid_proto, {msg}), 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}}) | |||
if msg then | |||
return make_error_msg (msg, args, template); | |||
end | |||
local is_latn_text, pos, char; | |||
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); | |||
end | |||
args.italic, msg = validate_italic (args); | |||
if msg then | |||
return make_error_msg (msg, args, template); | |||
end | |||
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 | |||
(this_wiki_lang_tag ~= code and not is_set (subtags.script) and not has_poem_tag (args.text) and is_latn_text) then -- text not this wiki's language, no script specified and not in poem markup but is wholly latn script (auto-italics) | |||
args.italic = 'italic'; -- DEFAULT for {{lang}} templates is upright; but if latn script set for font-style:italic | |||
else | |||
args.italic = 'inherit'; -- italic not set; script not latn; inherit current style | |||
end | |||
end | |||
if is_set (subtags.script) then -- if script set, override rtl setting | |||
if in_array (subtags.script, lang_data.rtl_scripts) then | |||
args.rtl = true; -- script is an rtl script | |||
else | |||
args.rtl = false; -- script is not an rtl script | |||
end | |||
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 ietf 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 | |||
args.text = invert_italics (args.text) | |||
end | |||
args.text = proto_prefix (args.text, language_name, args.proto); -- prefix proto-language text with a splat | args.text = proto_prefix (args.text, language_name, args.proto); -- prefix proto-language text with a splat | ||
| Line 1,142: | Line 1,226: | ||
--[[--------------------------< L A N G >---------------------------------------------------------------------- | --[[--------------------------< L A N G >---------------------------------------------------------------------- | ||
Entry point for {{lang}}. | |||
There should be no reason to set parameters in the {{lang}} {{#invoke:}} | |||
<includeonly>{{#invoke:lang|lang}}</includeonly> | <includeonly>{{#invoke:lang|lang}}</includeonly> | ||
Parameters are received from the template's frame (parent frame). | |||
]] | ]] | ||
local function lang (frame) | local function lang (frame) | ||
local args_t = getArgs (frame, { | local args_t = getArgs (frame, { -- this code so that we can detect and handle wiki list markup in text | ||
valueFunc = function (key, value) | valueFunc = function (key, value) | ||
if 2 == key or 'text' == key then -- the 'text' parameter; do not trim wite space | if 2 == key or 'text' == key then -- the 'text' parameter; do not trim wite space | ||
| Line 1,168: | Line 1,252: | ||
args_t.fn = nil; -- unset because not supported but this function might have been called by {{lang|fn=lang|...}} | args_t.fn = nil; -- unset because not supported but this function might have been called by {{lang|fn=lang|...}} | ||
local msg = parameter_validate (args_t, | local msg = parameter_validate (args_t, cfg.templates_t.lang); -- verify that all supplied parameters are supported by {{lang-??}} | ||
if msg then | if msg then | ||
return make_error_msg (msg, args_t, | return make_error_msg (msg, args_t, cfg.templates_t.lang); -- when template has unsupported params, abandon with error message | ||
end | end | ||
| Line 1,179: | Line 1,263: | ||
--[[--------------------------< T R A N S L A T I O N _ M A K E >---------------------------------------------- | --[[--------------------------< T R A N S L A T I O N _ M A K E >---------------------------------------------- | ||
Stand-alone function to create literal translation of main text. | |||
Also used by {{lang-x2}} | Also used by {{lang-x2}}. | ||
]] | ]] | ||
| Line 1,262: | Line 1,346: | ||
maint_msgs = {}; | maint_msgs = {}; | ||
local text_idx = ( | local text_idx = (cfg.templates_t.langx == base_template) and 2 or 1; -- for {{langx}} 'text' positional parameter is '2' | ||
local translit_idx = ( | local translit_idx = (cfg.templates_t.langx == base_template) and 3 or 2; | ||
local xlate_idx = ( | local xlate_idx = (cfg.templates_t.langx == base_template) and 4 or 3; | ||
if args[text_idx] and args.text then | if args[text_idx] and args.text then | ||
return make_error_msg (substitute (cfg. | return make_error_msg (substitute (cfg.lang_t.conflict_n_param, {translit_idx, cfg.lang_t.conflict_n_param_types.text}), args, template); | ||
else | else | ||
args.text = args[text_idx] or args.text; -- prefer positional 'text' parameter | args.text = args[text_idx] or args.text; -- prefer positional 'text' parameter | ||
| Line 1,280: | Line 1,364: | ||
if args[translit_idx] and args.translit then | if args[translit_idx] and args.translit then | ||
return make_error_msg (substitute (cfg. | return make_error_msg (substitute (cfg.lang_t.conflict_n_param, {translit_idx, cfg.lang_t.conflict_n_param_types.translit}), args, template); | ||
else | else | ||
| Line 1,286: | Line 1,370: | ||
end | end | ||
args.engvar = | 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 | |||
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 | 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 | return make_error_msg (substitute (cfg.lang_xx_t.conflict_n_lit, {translit_idx}), args, template); | ||
elseif args.translation and args.lit then | elseif args.translation and args.lit then | ||
return make_error_msg (cfg.lang_xx_t.conflict_lit, args, template); | return make_error_msg (cfg.lang_xx_t.conflict_lit, args, template); | ||
| Line 1,304: | Line 1,396: | ||
validate_cat_args (args); -- determine if categorization should be suppressed | validate_cat_args (args); -- determine if categorization should be suppressed | ||
args.rtl = args.rtl == cfg.keywords_t.affirmative; | args.rtl = args.rtl == cfg.keywords_t.affirmative; -- convert to boolean: 'yes' -> true, other values -> false | ||
code, subtags.script, subtags.region, subtags.variant, subtags.private, msg = get_ietf_parts (args.code, args.script, args.region, args.variant); -- private omitted because private | code, subtags.script, subtags.region, subtags.variant, subtags.private, msg = get_ietf_parts (args.code, args.script, args.region, args.variant); -- private omitted because private | ||
| Line 1,312: | Line 1,404: | ||
end | end | ||
local is_latn_text = | 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) | 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 | if msg then -- if an error detected then there is an error message | ||
return make_error_msg (msg, args, template); | return make_error_msg (msg, args, template); | ||
| Line 1,324: | Line 1,417: | ||
end | end | ||
if | if cfg.templates_t.langx == base_template then -- auto-italics for {{langx}} templates; adapted from {{lang}} (no support for poem tag) | ||
if nil == args.italic then -- nil when |italic= absent or not set or |italic=default; args.italic controls | 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 | if ('latn' == subtags.script) or -- script is latn | ||
| Line 1,358: | Line 1,451: | ||
args.proto, msg = validate_proto (args.proto); -- return boolean, or nil, or nil and error message flag | args.proto, msg = validate_proto (args.proto); -- return boolean, or nil, or nil and error message flag | ||
if msg then | if msg then | ||
return make_error_msg ( | return make_error_msg (substitute (cfg.lang_t.invalid_proto, {args.proto}), args, template); | ||
end | end | ||
| Line 1,409: | Line 1,502: | ||
if translit_title_obj.exists and (cfg.keywords_t.negative ~= args.link) then | 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}), | table.insert (out, make_wikilink (substitute ('$1 $2', {cfg.lang_xx_t.romanization, translit_script_name or language_name}), | ||
substitute ('$1', { | substitute ('$1', {cfg.engvar_t[args.engvar]['romanisz_pt']})) .. ':'); -- make a wikilink if there is an article to link to; engvar the display text | ||
else | else | ||
table.insert (out, substitute ('$1:', { | table.insert (out, substitute ('$1:', {cfg.engvar_t[args.engvar]['romanisz_pt']})); -- else plain text per engvar | ||
end | end | ||
| Line 1,424: | Line 1,517: | ||
return make_error_msg (substitute ('$1: $2', {cfg.lang_xx_t.invalid_xlit_std, args['translit-std'] or '[missing]'}), args, template); | 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 | end | ||
if is_set (args.translation) then -- translation (not supported in {{lang}}) | if is_set (args.translation) then -- translation (not supported in {{lang}}) | ||
table.insert (out, translation_make (args)); | table.insert (out, translation_make (args)); | ||
| Line 1,439: | Line 1,535: | ||
--[[--------------------------< L A N G _ X X _ A R G S _ G E T >---------------------------------------------- | --[[--------------------------< L A N G _ X X _ A R G S _ G E T >---------------------------------------------- | ||
Common function to get args table from {{lang-??}} templates. | |||
Returns table of args. | |||
Text positional parameters are not trimmed here but are selectively trimmed at html_tag_select(). | |||
]] | ]] | ||
| Line 1,452: | Line 1,548: | ||
parentFirst= true, -- parameters in the template override parameters set in the {{#invoke:}} | parentFirst= true, -- parameters in the template override parameters set in the {{#invoke:}} | ||
valueFunc = function (key, value) | valueFunc = function (key, value) | ||
if (( | if ((cfg.templates_t.langx == base_template) and 2 or 1) == key then -- the 'text' positional parameter; 1 for {{lang-??}}, 2 for {{langx}}; do not trim wite space | ||
return value; -- return untrimmed 'text' positional parameter | return value; -- return untrimmed 'text' positional parameter | ||
elseif value then -- all other values: if the value is not nil | elseif value then -- all other values: if the value is not nil | ||
| Line 1,470: | Line 1,566: | ||
--[[--------------------------< L A N G _ X X _ I T A L I C >-------------------------------------------------- | --[[--------------------------< L A N G _ X X _ I T A L I C >-------------------------------------------------- | ||
Entry point for those {{lang-??}} templates that call lang_xx_italic(). | Entry point for those {{lang-??}} templates that call lang_xx_italic(). Sets the initial style state to italic. | ||
]] | ]] | ||
local function lang_xx_italic (frame) | local function lang_xx_italic (frame) | ||
local args = lang_xx_args_get (frame, | local args = lang_xx_args_get (frame, cfg.templates_t.langxx); | ||
args.fn = nil; -- unset because not supported but this function might have been called by {{lang|fn=lang_xx_italic|...}} | args.fn = nil; -- unset because not supported but this function might have been called by {{lang|fn=lang_xx_italic|...}} | ||
local msg = parameter_validate (args, | local msg = parameter_validate (args, cfg.templates_t.langxx); -- verify that all supplied parameters are supported by {{lang-??}} | ||
if msg then | if msg then | ||
return make_error_msg (msg, args, | return make_error_msg (msg, args, cfg.templates_t.langxx); -- when template has unsupported params, abandon with error message | ||
end | end | ||
initial_style_state = 'italic'; | initial_style_state = 'italic'; | ||
return _lang_xx (args, | return _lang_xx (args, cfg.templates_t.langxx) .. '[[Category:Pages using Lang-xx templates]]'; -- temporary category | ||
end | end | ||
| Line 1,490: | Line 1,586: | ||
--[[--------------------------< _ L A N G _ X X _ I T A L I C >------------------------------------------------ | --[[--------------------------< _ L A N G _ X X _ I T A L I C >------------------------------------------------ | ||
Entry point from another module. | Entry point from another module. Sets the initial style state to italic. | ||
]] | ]] | ||
| Line 1,496: | Line 1,592: | ||
local function _lang_xx_italic (args) | local function _lang_xx_italic (args) | ||
initial_style_state = 'italic'; | initial_style_state = 'italic'; | ||
return _lang_xx (args, | return _lang_xx (args, cfg.templates_t.langxx); | ||
end | end | ||
| Line 1,502: | Line 1,598: | ||
--[[--------------------------< L A N G _ X X _ I N H E R I T >------------------------------------------------ | --[[--------------------------< L A N G _ X X _ I N H E R I T >------------------------------------------------ | ||
Entry point for those {{lang-??}} templates that call lang_xx_inherit(). | Entry point for those {{lang-??}} templates that call lang_xx_inherit(). Sets the initial style state to inherit. | ||
]] | ]] | ||
local function lang_xx_inherit (frame) | local function lang_xx_inherit (frame) | ||
local args = lang_xx_args_get (frame, | local args = lang_xx_args_get (frame, cfg.templates_t.langxx); | ||
args.fn = nil; -- unset because not supported but this function might have been called by {{lang|fn=lang_xx_inherit|...}} | args.fn = nil; -- unset because not supported but this function might have been called by {{lang|fn=lang_xx_inherit|...}} | ||
local msg = parameter_validate (args, | local msg = parameter_validate (args, cfg.templates_t.langxx); -- verify that all supplied parameters are supported by {{lang-??}} | ||
if msg then | if msg then | ||
return make_error_msg (msg, args, | return make_error_msg (msg, args, cfg.templates_t.langxx); -- when template has unsupported params, abandon with error message | ||
end | end | ||
initial_style_state = 'inherit'; | initial_style_state = 'inherit'; | ||
return _lang_xx (args, | return _lang_xx (args, cfg.templates_t.langxx) .. '[[Category:Pages using Lang-xx templates]]'; -- temporary category | ||
end | end | ||
| Line 1,522: | Line 1,618: | ||
--[[--------------------------< _ L A N G _ X X _ I N H E R I T >---------------------------------------------- | --[[--------------------------< _ L A N G _ X X _ I N H E R I T >---------------------------------------------- | ||
Entry point from another module. | Entry point from another module. Sets the initial style state to inherit. | ||
]] | ]] | ||
| Line 1,528: | Line 1,624: | ||
local function _lang_xx_inherit (args) | local function _lang_xx_inherit (args) | ||
initial_style_state = 'inherit'; | initial_style_state = 'inherit'; | ||
return _lang_xx (args, | return _lang_xx (args, cfg.templates_t.langxx); | ||
end | end | ||
| Line 1,544: | Line 1,640: | ||
local size_t = langx_data.size_t; -- get list of language tags for {{lang-??}} templates that set |size=<something> | local size_t = langx_data.size_t; -- get list of language tags for {{lang-??}} templates that set |size=<something> | ||
local msg = parameter_validate (args_t, | local msg = parameter_validate (args_t, cfg.templates_t.langx); | ||
if msg then | if msg then | ||
return make_error_msg (msg, args_t, | return make_error_msg (msg, args_t, cfg.templates_t.langx); | ||
end | end | ||
args_t.code = args_t[1] or args_t.code; -- get the language tag; must be {{{1}}} or |code= | args_t.code = args_t[1] or args_t.code; -- get the language tag; must be {{{1}}} or |code= | ||
if not args_t.code then | if not args_t.code then | ||
return make_error_msg (cfg.get_ietf_parts_t.missing_lang_tag, args_t, | return make_error_msg (cfg.get_ietf_parts_t.missing_lang_tag, args_t, cfg.templates_t.langx); | ||
end | end | ||
| Line 1,561: | Line 1,657: | ||
local lang_subtag = args_t.code; -- use only the base language subtag for unsupported tag test; some args_t.code are modified by |script= etc | local lang_subtag = args_t.code; -- use only the base language subtag for unsupported tag test; some args_t.code are modified by |script= etc | ||
return _lang_xx (args_t, | return _lang_xx (args_t, cfg.templates_t.langx); | ||
end | end | ||
| Line 1,569: | Line 1,665: | ||
Entry point for {{langx}}. | Entry point for {{langx}}. | ||
this function calls _lang_xx() to render non-English text. | this function calls _lang_xx() to render non-English text. The {{lang-??}} templates have three positional paramters | ||
but {{langx}} has four: | but {{langx}} has four: | ||
| Line 1,582: | Line 1,678: | ||
{{langx}} can't do that. The initial version of {{langx}} relied on a list of language tags (inherit_t in ~/langx) | {{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. | scraped from those {{lang-??}} templates that call lang_xx_inherit() to render text in upright font. Langx now | ||
uses auto-italics code adapted from {{lang}} (doesn't support poem tags) | uses auto-italics code adapted from {{lang}} (doesn't support poem tags). | ||
]] | ]] | ||
local function langx (frame) | local function langx (frame) | ||
local args_t = lang_xx_args_get (frame, | local args_t = lang_xx_args_get (frame, cfg.templates_t.langx); -- get the arguments; 'Langx' is the <base_template> used to decide which positional param is 'text', 'translit', 'lit' | ||
return _langx (args_t); | return _langx (args_t); | ||
| Line 1,600: | Line 1,696: | ||
All code combinations supported by {{lang}} and the {{lang-??}} templates are supported by this function. | All code combinations supported by {{lang}} and the {{lang-??}} templates are supported by this function. | ||
Module entry point from another module | Module entry point from another module. | ||
]] | ]] | ||
| Line 1,614: | Line 1,710: | ||
--[[--------------------------< I S _ I E T F _ T A G >-------------------------------------------------------- | --[[--------------------------< I S _ I E T F _ T A G >-------------------------------------------------------- | ||
Module entry point from an {{#invoke:}} | Module entry point from an {{#invoke:}}. | ||
]] | ]] | ||
| Line 1,644: | Line 1,740: | ||
Set invoke's |link= parameter to yes to get wikilinked version of the language name. | Set invoke's |link= parameter to yes to get wikilinked version of the language name. | ||
Module entry point from another module | Module entry point from another module. | ||
]] | ]] | ||
| Line 1,651: | Line 1,747: | ||
local subtags = {}; -- IETF subtags script, region, variant, and private | local subtags = {}; -- IETF subtags script, region, variant, and private | ||
local raw_code = args[1]; -- save a copy of the input IETF subtag | local raw_code = args[1]; -- save a copy of the input IETF subtag | ||
local link = cfg.keywords_t.affirmative == args['link']; | local link = cfg.keywords_t.affirmative == args['link']; -- make a boolean | ||
local label = args.label; | local label = args.label; | ||
local code; -- the language code | local code; -- the language code | ||
| Line 1,660: | Line 1,756: | ||
if msg then | if msg then | ||
local template = (args['template'] and table.concat ({'{{', args['template'], '}}: '})) or ''; -- make template name (if provided by the template) | local template = (args['template'] and table.concat ({'{{', args['template'], '}}: '})) or ''; -- make template name (if provided by the template) | ||
return | return make_error_span (template, msg); | ||
end | end | ||
| Line 1,666: | Line 1,762: | ||
language_name = language_name_get (raw_code, code); -- get language name; try ietf tag first, then code w/o variant then code w/ variant | language_name = language_name_get (raw_code, code); -- get language name; try ietf tag first, then code w/o variant then code w/ variant | ||
language_name = language_name:gsub ('%s+%b()', ''); | 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 link then -- when |link=yes, wikilink the language name | ||
| Line 1,686: | Line 1,784: | ||
--[[--------------------------< N A M E _ F R O M _ T A G >---------------------------------------------------- | --[[--------------------------< N A M E _ F R O M _ T A G >---------------------------------------------------- | ||
Module entry point from an {{#invoke:}} | Module entry point from an {{#invoke:}}. | ||
]] | ]] | ||
| Line 1,701: | Line 1,799: | ||
that disambiguator must be omitted (they are not present in the data name-to-tag tables). | that disambiguator must be omitted (they are not present in the data name-to-tag tables). | ||
Module entry point from another module | Module entry point from another module. | ||
]] | ]] | ||
| Line 1,726: | Line 1,824: | ||
template = table.concat ({'{{', args['template'], '}}: '}); -- make template name (if provided by the template) | template = table.concat ({'{{', args['template'], '}}: '}); -- make template name (if provided by the template) | ||
end | end | ||
return | return make_error_span (template, msg); | ||
end | end | ||
| Line 1,733: | Line 1,831: | ||
--[[--------------------------< T A G _ F R O M _ N A M E >---------------------------------------------------- | --[[--------------------------< T A G _ F R O M _ N A M E >---------------------------------------------------- | ||
Module entry point from an {{#invoke:}} | Module entry point from an {{#invoke:}}. | ||
]] | ]] | ||
| Line 1,745: | Line 1,843: | ||
--[[--------------------------< I S _ L A N G _ N A M E >------------------------------------------------------ | --[[--------------------------< I S _ L A N G _ N A M E >------------------------------------------------------ | ||
Module entry point from an {{#invoke:}} | Module entry point from an {{#invoke:}}. | ||
]] | ]] | ||
| Line 1,757: | Line 1,855: | ||
--[[--------------------------< _ T R A N S L >---------------------------------------------------------------- | --[[--------------------------< _ T R A N S L >---------------------------------------------------------------- | ||
Module entry point from another module | Module entry point from another module. | ||
]] | ]] | ||
| Line 1,767: | Line 1,865: | ||
local script; -- IANA script | local script; -- IANA script | ||
local msg; -- for when called functions return an error message | local msg; -- for when called functions return an error message | ||
local template = args.template or cfg.templates_t.transliteration; | |||
maint_cats = {}; -- initialize because when this module required into another module, these only declared once so only initialzed once | maint_cats = {}; -- initialize because when this module required into another module, these only declared once so only initialzed once | ||
| Line 1,776: | Line 1,875: | ||
if not title_table[args.translit_std] then | if not title_table[args.translit_std] then | ||
return make_error_msg (substitute (cfg.transl_t.unrecog_xlit_std, {args.translit_std}), args, | return make_error_msg (substitute (cfg.transl_t.unrecog_xlit_std, {args.translit_std}), args, template); | ||
end | end | ||
else | else | ||
| Line 1,784: | Line 1,883: | ||
if args[1] and (args[1]:match ('^%a%a%a?%a?$') or -- args[2] missing; is args[1] a language or script tag or is it the transliterated text? | if args[1] and (args[1]:match ('^%a%a%a?%a?$') or -- args[2] missing; is args[1] a language or script tag or is it the transliterated text? | ||
args[1]:match ('^%a%a%a?%-x%-')) then -- or is args[1] a private-use tag | args[1]:match ('^%a%a%a?%-x%-')) then -- or is args[1] a private-use tag | ||
return make_error_msg (cfg.transl_t.no_text, args, | return make_error_msg (cfg.transl_t.no_text, args, template); -- args[1] is a code so we're missing text | ||
else | else | ||
args.text = args[1]; -- args[1] is not a code so we're missing that; assign args.text for error message | 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, | return make_error_msg (cfg.transl_t.missing_lang_scr, args, template); | ||
end | end | ||
end | end | ||
| Line 1,796: | Line 1,895: | ||
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 | 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 | else | ||
return make_error_msg (substitute (cfg.transl_t.unrecog_lang_scr, {args[1]}), args, | return make_error_msg (substitute (cfg.transl_t.unrecog_lang_scr, {args[1]}), args, template); -- invalid language / script code | ||
end | end | ||
else | else | ||
return make_error_msg (cfg.transl_t.missing_lang_scr, args, | return make_error_msg (cfg.transl_t.missing_lang_scr, args, template); -- missing language / script code so quit | ||
end | |||
local is_latn_text, pos, char; | |||
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 | end | ||
args.italic, msg = validate_italic (args); | args.italic, msg = validate_italic (args); | ||
if msg then | if msg then | ||
return make_error_msg (msg, args, | return make_error_msg (msg, args, template); | ||
end | end | ||
| Line 1,811: | Line 1,917: | ||
end | end | ||
args.engvar = | args.engvar = cfg.engvar_sel_t[args.engvar] or cfg.default_engvar; -- |engvar= when valid; cfg.default_engvar else | ||
if override_table[args.code] then -- is code a language code defined in the override table? | if override_table[args.code] then -- is code a language code defined in the override table? | ||
| Line 1,825: | Line 1,931: | ||
args.code = ''; -- unset because not a language code | args.code = ''; -- unset because not a language code | ||
else | else | ||
return make_error_msg (substitute (cfg.transl_t.unrecog_lang_scr, {args.code}), args, | return make_error_msg (substitute (cfg.transl_t.unrecog_lang_scr, {args.code}), args, template); -- invalid language / script code | ||
end | end | ||
-- here only when all parameters passed to make_translit() are valid | -- here only when all parameters passed to make_translit() are valid | ||
| Line 1,834: | Line 1,940: | ||
--[[--------------------------< T R A N S L >------------------------------------------------------------------ | --[[--------------------------< T R A N S L >------------------------------------------------------------------ | ||
Module entry point from an {{#invoke:}} | Module entry point from an {{#invoke:}}. | ||
]] | ]] | ||
| Line 1,845: | Line 1,951: | ||
--[[--------------------------< C A T E G O R Y _ F R O M _ T A G >-------------------------------------------- | --[[--------------------------< 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 | 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. | All code combinations supported by {{lang}} and the {{lang-??}} templates are supported by this function. | ||
Module entry point from another module | Module entry point from another module. | ||
]] | ]] | ||
| Line 1,865: | Line 1,971: | ||
if msg then | if msg then | ||
local template = (args_t.template and table.concat ({'{{', args_t.template, '}}: '})) or ''; -- make template name (if provided by the template) | local template = (args_t.template and table.concat ({'{{', args_t.template, '}}: '})) or ''; -- make template name (if provided by the template) | ||
return | return make_error_span (template, msg); | ||
end | end | ||
| Line 1,882: | Line 1,988: | ||
--[[--------------------------< C A T E G O R Y _ F R O M _ T A G >-------------------------------------------- | --[[--------------------------< C A T E G O R Y _ F R O M _ T A G >-------------------------------------------- | ||
Module entry point from an {{#invoke:}} | Module entry point from an {{#invoke:}}. | ||
]] | ]] | ||