Module:Lang: Difference between revisions

Content deleted Content added
sync from sandbox;
sync from sandbox;
Line 41:
]]
 
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:
--[[--------------------------< 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:
--[[--------------------------< 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 94:
 
--[[--------------------------< P A R A M E T E R _ V A L I D A T E >------------------------------------------
 
]]
 
Line 186 ⟶ 187:
--[[--------------------------< 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 acceptible assigned value, return the matching css font-style property value or,
Line 262 ⟶ 263:
--[[--------------------------< I N _ A R R A Y >--------------------------------------------------------------
 
Whether needle is in haystack.
 
]]
Line 281 ⟶ 282:
--[[--------------------------< F O R M A T _ I E T F _ T A G >------------------------------------------------
 
prettifyPrettify ietf tags to use recommended subtag formats:
code: lower case
script: sentence case
Line 317 ⟶ 318:
--[[--------------------------< 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 ⟶ 332:
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 ⟶ 339:
 
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.
]]
Line 519 ⟶ 520:
--[[--------------------------< 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 551 ⟶ 550:
--[[--------------------------< 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
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.
 
]]
 
Line 656:
[[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:
 
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 ⟶ 692:
--[[--------------------------< 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 ⟶ 699:
 
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 transl()
Line 708 ⟶ 705:
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.
 
]]
 
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 796 ⟶ 792:
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 ⟶ 819:
 
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 ⟶ 828:
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 ⟶ 847:
--[[--------------------------< R E N D E R _ M A I N T >------------------------------------------------------
 
renderRender mainenance messages and categories.
 
]]
Line 884 ⟶ 874:
--[[--------------------------< 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 ⟶ 896:
--[[--------------------------< 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 963 ⟶ 953:
--[[--------------------------< 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 ⟶ 974:
--[[--------------------------< 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 1,022 ⟶ 1,012:
Conversely, when <text> is written using the Latn script, the IETF script subtag, if present, should be Latn.
 
returnsReturns an error message when mismatch detected; nil else.
 
]]
 
local function text_script_match_test (script, is_latn_text, pos)
if is_set (script) then -- don't bother with the rest of this if <script> is nil or empty string
if is_latn_text then -- when text is wholly Latn script
if ('Latn' ~= script and 'latn' ~= 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' == script) then -- but Latn script is specified
return substitute (cfg.text_script_match_test_t.latn_scr_mismatch, {pos}); -- emit an error message with position of first offending character
end
end
Line 1,042 ⟶ 1,033:
--[[--------------------------< I S _ L A T I N >--------------------------------------------------------------
 
createdCreated 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
other script with Greek 'θ'.
Line 1,075 ⟶ 1,066:
--[[--------------------------< _ 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,091:
 
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,097:
 
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,131 ⟶ 1,122:
end
 
local is_latn_text, pos = is_latin (args.text, subtags.script); -- make a boolean
 
msg = text_script_match_test (subtags.script, is_latn_text, pos)
if msg then -- if an error detected then there is an error message
return make_error_msg (msg, args, template);
Line 1,179 ⟶ 1,170:
--[[--------------------------< 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,207:
--[[--------------------------< 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,304 ⟶ 1,295:
 
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,317 ⟶ 1,308:
 
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,333 ⟶ 1,324:
 
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,402 ⟶ 1,393:
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
 
Line 1,483 ⟶ 1,474:
--[[--------------------------< 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,505:
--[[--------------------------< 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,525:
--[[--------------------------< _ 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,537:
--[[--------------------------< 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,557:
--[[--------------------------< _ 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,604:
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:
 
Line 1,626 ⟶ 1,617:
 
{{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. Langx now
uses auto-italics code adapted from {{lang}} (doesn't support poem tags).
 
]]
Line 1,644 ⟶ 1,635:
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,649:
--[[--------------------------< I S _ I E T F _ T A G >--------------------------------------------------------
 
Module entry point from an {{#invoke:}}.
 
]]
Line 1,688 ⟶ 1,679:
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,695:
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
 
Line 1,730 ⟶ 1,721:
--[[--------------------------< N A M E _ F R O M _ T A G >----------------------------------------------------
 
Module entry point from an {{#invoke:}}.
 
]]
Line 1,745 ⟶ 1,736:
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,761:
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,768:
--[[--------------------------< T A G _ F R O M _ N A M E >----------------------------------------------------
 
Module entry point from an {{#invoke:}}.
 
]]
Line 1,789 ⟶ 1,780:
--[[--------------------------< I S _ L A N G _ N A M E >------------------------------------------------------
 
Module entry point from an {{#invoke:}}.
 
]]
Line 1,801 ⟶ 1,792:
--[[--------------------------< _ T R A N S L >----------------------------------------------------------------
 
Module entry point from another module.
 
]]
Line 1,885 ⟶ 1,876:
--[[--------------------------< T R A N S L >------------------------------------------------------------------
 
Module entry point from an {{#invoke:}}.
 
]]
Line 1,896 ⟶ 1,887:
--[[--------------------------< 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,916 ⟶ 1,907:
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
 
Line 1,933 ⟶ 1,924:
--[[--------------------------< C A T E G O R Y _ F R O M _ T A G >--------------------------------------------
 
Module entry point from an {{#invoke:}}.
 
]]