Module:Lang: திருத்தங்களுக்கு இடையிலான வேறுபாடு
உள்ளடக்கம் நீக்கப்பட்டது உள்ளடக்கம் சேர்க்கப்பட்டது
imported>Lingam "--[=[ Lua support for the {{lang}}, {{lang-xx}}, and {{transliteration}} templates and replacement of various supporting templates. ]=] require('strict'); local getArgs = require ('Module:Arguments').getArgs; local unicode = require ("Module:Unicode data"); -- for is_latin() and is_rtl() local yesno = require ('Module:Yesno'); local lang_data = mw.lo..."-இப்பெயரில் புதிய பக்கம் உருவாக்கப்பட்டுள்ளது |
imported>Balajijagadesh சி en:Module:Lang இலிருந்து திருத்தம் இறக்குமதி செய்யப்பட்டன |
||
வரிசை 1:
--[=[
Lua support for the {{lang}}, {{langx}}, {{lang-
]=]
வரிசை 8:
local getArgs = require ('Module:Arguments').getArgs;
local unicode = require ("Module:Unicode data"); -- for
local yesno = require ('Module:Yesno');
வரிசை 22:
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/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
வரி 33 ⟶ 38:
local maint_cats = {}; -- maintenance categories go here
local maint_msgs = {}; -- and their messages go here
--[[--------------------------< 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 >----------------------------------------------------------
Substitutes $1, $2, etc in <message> with data from <data_t>. Returns plain-text substituted string when
<data_t> not nil; returns <message> else.
]]
local function substitute (message, data_t)
return data_t and mw.message.newRawMessage (message, data_t):plain() or message;
end
--[[--------------------------< 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.
]]
local function make_error_msg (msg, args_t, template)
local category;
local text; -- handle the oddity that is {{langx}}
if cfg.templates_t.langxx == template then
text = args_t.text or args_t[1]; -- for {{lang-xx}}
else
text = args_t.text or args_t[2]; -- for {{lang}}, {{langx}}, and {{transliteration}}
end
if cfg.templates_t.transliteration == template then
category = cfg.make_error_msg_t.xlit_err_cat;
else
category = cfg.make_error_msg_t.lang_err_cat;
end
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|$6]])</span>$7',
{
text or cfg.make_error_msg_t.undefined,
cfg.misc_text_t.error,
template,
msg,
category,
cfg.misc_text_t.help,
category_link
})
end
--[[--------------------------< P A R A M E T E R _ V A L I D A T E >------------------------------------------
]]
local function parameter_validate (args_t, template)
local err_msg = cfg.parameter_validate_t.invalid_param;
if cfg.templates_t.lang == template then -- for {{lang}}
for param, _ in pairs (args_t) do
if not cfg.known_params_t.params_lang_t[param] and -- unique {{lang}} parameters
not cfg.known_params_t.common_params_all_t[param] then -- common to all
return substitute (err_msg, {param}); -- <param> not found so abandon
end
end
elseif cfg.templates_t.langx == template then -- for {{langx}}
for param, _ in pairs (args_t) do
if not cfg.known_params_t.params_langx_t[param] and -- unique {{langx}} parameters
not cfg.known_params_t.params_x_t[param] and -- common to {{langx}} and {{lang-xx}}
not cfg.known_params_t.common_params_all_t[param] then -- common to all
return substitute (err_msg, {param}); -- <param> not found so abandon
end
end
elseif cfg.templates_t.langxx == template then -- for {{lang-xx}}
for param, _ in pairs (args_t) do
if not cfg.known_params_t.params_lang_xx_t[param] and -- unique {{lang-xx}} parameters
not cfg.known_params_t.params_x_t[param] and -- common to {{langx}} and {{lang-xx}}
not cfg.known_params_t.common_params_all_t[param] then -- common to all
return substitute (err_msg, {param}); -- <param> not found so abandon
end
end
end
end
--[[--------------------------< I S _ S E T >------------------------------------------------------------------
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not
an empty string.
]]
local function is_set (
return not (var == nil or var == '');
end
வரி 94 ⟶ 190:
--[[--------------------------< V A L I D A T E _ I T A L I C >------------------------------------------------
When |italic= is set and has an acceptible assigned value, return the matching css font-style property value or,
வரி 104 ⟶ 200:
The return value nil causes the calling lang, lang_xx, or transl function to set args.italic according to the template's
defined default ('inherit' for {{lang}}, 'inherit' or 'italic' for {{lang-
the individual template's requirements, 'italic' for {{transliteration}}) or to the value appropriate to |script=, if set ({{lang}}
and {{lang-
Accepted values and the values that this function returns are are:
வரி 119 ⟶ 215:
local function validate_italic (args)
local properties = {[
local count = 0
வரி 129 ⟶ 225:
if count > 1 then -- return nil and an error message if more than one is set
return nil,
end
வரி 138 ⟶ 234:
--[=[--------------------------< V A L I D A T E _ C A T _ A R G S >----------------------------------------------------------
Default behavior of the {{lang}} and {{lang-
This default functionality may be suppressed by setting |nocat=yes or |cat=no. This function selects one of these two parameters
to control categorization.
வரி 170 ⟶ 266:
--[[--------------------------< I N _ A R R A Y >--------------------------------------------------------------
Whether needle is in haystack.
]]
local function in_array (
if needle == nil then
return false;
end
for n,v in ipairs (
if v == needle then
return n;
வரி 189 ⟶ 285:
--[[--------------------------< F O R M A T _ I E T F _ T A G >------------------------------------------------
code: lower case
script: sentence case
வரி 225 ⟶ 321:
--[[--------------------------< G E T _ I E T F _ P A R T S >--------------------------------------------------
primary language subtag (required) - 2 or 3 character IANA language code
script subtag - four character IANA script code
வரி 239 ⟶ 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
வரி 245 ⟶ 341:
the synonymous three-character codes in the lang= attribute.
For {{lang-
because those parameters are superfluous to the IETF subtags in |code=).
parts are returned as nil; the sixth returned item is an error message (if an error detected) or nil.
]]
வரி 259 ⟶ 355:
if not is_set (source) then
return nil, nil, nil, nil, nil,
end
வரி 314 ⟶ 410:
if not code then
return nil, nil, nil, nil, nil,
end
வரி 320 ⟶ 416:
if not (override_table[code] or lang_table[code] or synonym_table[code] or lang_dep_table[code]) then
return nil, nil, nil, nil, nil,
end
if synonym_table[code] then -- if 639-2/639-2T code has a 639-1 synonym
table.insert (maint_cats,
table.insert (maint_msgs,
code = synonym_table[code]; -- use the synonym
end
வரி 331 ⟶ 427:
if is_set (script) then
if is_set (args_script) then
return code, nil, nil, nil, nil,
end
else
வரி 340 ⟶ 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,
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,
end
end
வரி 351 ⟶ 447:
if is_set (region) then
if is_set (args_region) then
return code, nil, nil, nil, nil,
end
else
வரி 360 ⟶ 456:
region = region:lower(); -- ensure that we use and return lower case version of this
if not region_table[region] then
return code, script, nil, nil, nil,
end
end
வரி 366 ⟶ 462:
if is_set (variant) then
if is_set (args_variant) then
return code, nil, nil, nil, nil,
end
else
வரி 375 ⟶ 471:
variant = variant:lower(); -- ensure that we use and return lower case version of this
if not variant_table[variant] then -- make sure variant is valid
return code, script, region, nil, nil,
end -- does this duplicate/replace tests in lang() and lang_xx()?
if is_set (script) then -- if script set it must be part of the 'prefix'
if not in_array (table.concat ({code, '-', script}), variant_table[variant]['prefixes']) then
return code, script, region, nil, nil,
end
elseif is_set (region) then -- if region set, there are some prefixes that require lang code and region (en-CA-newfound)
if not in_array (code, variant_table[variant]['prefixes']) then -- first see if lang code is all that's required (en-oxendict though en-GB-oxendict is preferred)
if not in_array (table.concat ({code, '-', region}), variant_table[variant]['prefixes']) then -- now try for lang code and region (en-CA-newfound)
return code, script, region, nil, nil,
end
end
else -- cheap way to determine if there are prefixes; fonipa and others don't have prefixes; # operator always returns 0
if variant_table[variant]['prefixes'][1] and not in_array (code, variant_table[variant]['prefixes']) then
return code, script, region, nil, nil,
end
end
வரி 397 ⟶ 493:
private = private:lower(); -- ensure that we use and return lower case version of this
if not override_table[table.concat ({code, '-x-', private})] then -- make sure private tag is valid; note that index
return code, script, region, nil, nil,
end
end
வரி 403 ⟶ 499:
end
--[=[-------------------------< M A K E _ W I K I L I N K >----------------------------------------------------
வரி 457 ⟶ 523:
--[[--------------------------< D I V _ M A R K U P _ A D D >--------------------------------------------------
]]
local function div_markup_add (text, style)
if text:find ('^\n[%*:;#]') then -- look for list markup; list markup must begin at start of text
if 'italic' == style then
வரி 489 ⟶ 553:
--[[--------------------------< T I T L E _ W R A P P E R _ M A K E >------------------------------------------
<title text> is in the tool-tip in the wiki's local language and <content_text> is non-local-language text in
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.
]]
வரி 575 ⟶ 640:
local title_text;
if 'zxx' == code then -- special case for this tag 'no linguistic content'
title_text =
elseif mw.ustring.find (language, 'languages', 1, true) then
title_text =
else
title_text =
end
வரி 594 ⟶ 659:
[[Category:Articles containing <language>-language text]]
[[Category:Articles containing explicitly cited English-language text]]
[[Category:Articles with text in <language> languages]]
வரி 603 ⟶ 668:
local function make_category (code, language_name, nocat, name_get)
if ((0 ~= namespace) or nocat) and not name_get then -- only categorize in article space
return ''; -- return empty string for concatenation
வரி 611 ⟶ 673:
if mw.ustring.find (language_name, 'languages', 1, true) then
return substitute ('[[$1 $2]]', {cfg.make_category_t.collective_cat, language_name});
end
if this_wiki_lang_tag == code then
cfg.make_category_t.cat_prefix,
cfg.make_category_t.explicit_cat,
language_name,
cfg.make_category_t.cat_postfix,
});
else
return substitute ('[[$1 $2-$3]]', { -- category for individual languages
cfg.make_category_t.cat_prefix,
language_name,
cfg.make_category_t.cat_postfix,
});
end
end
வரி 630 ⟶ 695:
--[[--------------------------< M A K E _ T R A N S L I T >----------------------------------------------------
The value |script= is not used in {{transliteration}} for this purpose; instead it uses |code. Because language scripts
வரி 637 ⟶ 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 transl()
வரி 643 ⟶ 708:
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_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
வரி 657 ⟶ 721:
title_text = language_name; -- write a generic tool tip
if not mw.ustring.find (language_name, 'languages', 1, true) then -- collective language names (plural 'languages' is part of the name)
title_text = substitute ('$1-$2', {title_text, cfg.misc_text_t.
end
title_text = substitute ('$1 $2', {title_text, mw.ustring.lower (cfg.engvar_t[engvar]['
elseif is_set (std) and is_set (tscript) then -- when both are specified
வரி 665 ⟶ 729:
if title_t[std][tscript] then -- and if script for that standard is legitimate
if script_table[tscript] then
title_text =
title_text,
title_t[std][tscript:lower()],
script_table[tscript],
cfg.make_translit_t.script,
cfg.make_translit_t.transliteration,
});
else
title_text = title_text .. title_t[std]['default']; -- use the default if script not in std table; TODO: maint cat? error message because script not found for this standard?
வரி 680 ⟶ 750:
if title_t[std][code] then -- if language code is in the table (transl may not provide a language code)
title_text =
title_text,
title_t[std][code:lower()],
language_name,
cfg.misc_text_t.language,
cfg.make_translit_t.transliteration,
});
else -- code doesn't match
title_text = title_text .. title_t[std]['default']; -- so use the standard's default
வரி 692 ⟶ 768:
else
if is_set (tscript) then
title_text =
title_text,
language_name,
cfg.make_translit_t.script,
cfg.make_translit_t.transliteration,
});
elseif is_set (code) then
if not mw.ustring.find (language_name, 'languages', 1, true) then -- collective language names (plural 'languages' is part of the name)
title_text =
title_text,
cfg.misc_text_t.language,
});
end
title_text =
title_text,
cfg.make_translit_t.transliteration,
});
else
title_text =
title_text,
cfg.make_translit_t.transliteration,
});
end
end
end
local
if is_set (code) then -- when a language code is provided (always with {{lang-
code = code:match ('^(%a%a%a?)'); -- strip all subtags leaving only the language subtag
if not style then -- nil for the default italic style
else
tag = string.format(tag, style, "%s", "%s")
end
else
end
if '' == title_text then -- when there is no need for a tool-tip
return
else
title_text = 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, tag, 'span'); -- wrap with a tool-tip span and done
end
end
வரி 736 ⟶ 822:
This function checks the content of args.text and returns empty string if nothing is amiss else it returns an
error message.
Italic rendering is controlled by the |italic= template parameter so italic markup should never appear in args.text
வரி 745 ⟶ 831:
local function validate_text (template, args)
if not is_set (args.text) then
return make_error_msg (
end
if args.text:find ("%f[\']\'\'\'\'%f[^\']") or args.text:find ("\'\'\'\'\'[\']+") then -- because we're looking, look for 4 appostrophes or 6+ appostrophes
return make_error_msg (
end
local style = args.italic;
if (
if args.text:find ("%f[\']\'\'%f[^\']") or args.text:find ("%f[\']\'\'\'\'\'%f[^\']") then -- italic but not bold, or bold italic
return make_error_msg (
end
end
வரி 764 ⟶ 850:
--[[--------------------------< R E N D E R _ M A I N T >------------------------------------------------------
]]
local function render_maint (nocat)
local maint = {};
வரி 791 ⟶ 877:
--[[--------------------------< P R O T O _ P R E F I X >------------------------------------------------------
will be rendered outside of italic markup (if used).
do nothing.
proto_param is boolean or nil; true adds splat prefix regardless of language name; false removes and
regardless of language name; nil does nothing; presumes that the value in text is correct but removes extra splac.
]]
வரி 813 ⟶ 899:
--[[--------------------------< H A S _ P O E M _ T A G >------------------------------------------------------
the content that will replace the stripmarker.
வரி 870 ⟶ 956:
--[[--------------------------< V A L I D A T E _ P R O T O >--------------------------------------------------
empty string (or parameter omitted) returns as nil; any other value returns
return value for use in error message.
]]
local function validate_proto (proto_param)
if
return true;
elseif
return false;
elseif is_set (proto_param) then
return nil,
else
return nil; -- missing or empty
வரி 891 ⟶ 977:
--[[--------------------------< L A N G U A G E _ N A M E _ G E T >--------------------------------------------
]]
வரி 913 ⟶ 999:
if lang_dep_table[code] and cat then -- because deprecated code may have been overridden to en.wiki preferred name
table.insert (maint_cats,
table.insert (maint_msgs,
end
return name; -- name from data tables or nil
end
--[[--------------------------< T E X T _ S C R I P T _ M A T C H _ T E S T >----------------------------------
IETF script subtag should match the script of the <text>. This module does not attempt to know all scripts and
what they look like. It does know what Latn script looks like so when <text> is written using other than the Latn
script, the IETF script subtag, if present, should not 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, 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 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 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
end
end
--[[--------------------------< 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 binary_search (target, ranges_t)
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)
if (target < ranges_t[idx_bot][1]) or (target > ranges_t[idx_top][2]) then -- invalid; target out of range
return; -- abandon
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
--[[--------------------------< 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
வரி 923 ⟶ 1,121:
--[[--------------------------< _ L A N G >--------------------------------------------------------------------
<includeonly>{{#invoke:lang|lang}}</includeonly>
]]
வரி 940 ⟶ 1,138:
local msg; -- for error messages
local tag = 'span'; -- initial value for make_text_html()
local template = args.template or
maint_cats = {}; -- initialize because when this module required into another module, these only declared once so only initialzed once
வரி 948 ⟶ 1,146:
if args[1] and args.code then
return make_error_msg (
else
args.code = args[1] or args.code; -- prefer args.code
வரி 954 ⟶ 1,152:
if args[2] and args.text then
return make_error_msg (
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
வரி 966 ⟶ 1,164:
args.text, tag = html_tag_select (args.text); -- inspects text; returns appropriate html tag with text trimmed accordingly
args.rtl = args.rtl ==
args.proto, msg = validate_proto (args.proto); -- return boolean, or nil, or nil and error message flag
if msg then
return make_error_msg (
end
வரி 976 ⟶ 1,174:
if msg then
return make_error_msg (
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
வரி 986 ⟶ 1,192:
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
args.italic = 'italic'; -- DEFAULT for {{lang}} templates is upright; but if latn script set for font-style:italic
else
வரி 1,004 ⟶ 1,210:
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
args.text = invert_italics (args.text)
end
வரி 1,012 ⟶ 1,218:
table.insert (out, make_text_html (args.code, args.text, tag, args.rtl, args.italic, args.size, language_name));
table.insert (out, make_category (code, language_name, args.nocat));
table.insert (out, render_maint (args.nocat)); -- maintenance messages and categories
return table.concat (out); -- put it all together and done
வரி 1,020 ⟶ 1,226:
--[[--------------------------< L A N G >----------------------------------------------------------------------
<includeonly>{{#invoke:lang|lang}}</includeonly>
]]
local function lang (frame)
local
valueFunc = function (key, value)
if 2 == key or 'text' == key then -- the 'text' parameter; do not trim wite space
வரி 1,044 ⟶ 1,250:
});
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, cfg.templates_t.lang); -- verify that all supplied parameters are supported by {{lang-??}}
if msg then
return make_error_msg (msg, args_t, cfg.templates_t.lang); -- when template has unsupported params, abandon with error message
end
return _lang (args_t);
end
வரி 1,050 ⟶ 1,263:
--[[--------------------------< T R A N S L A T I O N _ M A K E >----------------------------------------------
Also used by {{lang-x2}}.
]]
வரி 1,061 ⟶ 1,274:
if 'none' ~= args_t.label then -- if we want a label
table.insert (translation_t, '<small>'); -- open the <small> html tag
if
table.insert (translation_t, substitute ('<abbr title="
else
table.insert (translation_t, make_wikilink (
end
table.insert (translation_t, " </small>"); -- close the <small> html tag
வரி 1,073 ⟶ 1,286:
--[[--------------------------< _ L A N G _ X X >
For the {{lang-
other parameters can, usually should, be written in the template call. For {{lang-
that can have multiple writing systems, it may be appropriate to set |script= as well.
For each {{lang-
styling that should be applied to text.
வரி 1,104 ⟶ 1,317:
any other text replaces language-name label - automatic wikilinking disabled
for those {{lang-
|translit = text that is a transliteration of text
|translit-std = the standard that applies to the transliteration
|translit-script = ISO 15924 script name; falls back to code
For {{lang-
{{{1}}} text
{{{2}}} transliterated text
வரி 1,117 ⟶ 1,330:
]]
local function _lang_xx (args, base_template) -- base_template will be either of 'Langx' or 'Lang-xx'
local out = {};
local language_name; -- used to make display text, article links
வரி 1,126 ⟶ 1,339:
local translit_script_name; -- name associated with IANA (ISO 15924) script code
local translit;
local msg; -- for error messages
local tag = 'span'; -- initial value for make_text_html()
local template = args.template or
maint_cats = {}; -- initialize because when this module required into another module, these only declared once so only initialzed once
maint_msgs = {};
local text_idx = (cfg.templates_t.langx == base_template) and 2 or 1; -- for {{langx}} 'text' positional parameter is '2'
local translit_idx = (cfg.templates_t.langx == base_template) and 3 or 2;
local xlate_idx = (cfg.templates_t.langx == base_template) and 4 or 3;
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[
end
msg = validate_text (template, args); -- ensure that |text= is set, does not contain italic markup and is protected from improper bolding
if is_set (msg) then
வரி 1,147 ⟶ 1,363:
args.text, tag = html_tag_select (args.text); -- inspects text; returns appropriate html tag with text trimmed accordingly
if args[
return make_error_msg (
else
args.translit = args[
end
args.engvar = cfg.engvar_sel_t[args.engvar] or cfg.default_engvar; -- |engvar= when valid; cfg.default_engvar else
if args[xlate_idx] and (args.translation or args.lit) then
return make_error_msg (substitute (cfg.lang_xx_t.conflict_n_lit, {translit_idx}), args, template);
elseif args.translation and args.lit then
return make_error_msg (
else
args.translation = args[
end
if args.links and args.link then
return make_error_msg (
else
args.link = args.link or args.links; -- prefer args.link
வரி 1,169 ⟶ 1,388:
validate_cat_args (args); -- determine if categorization should be suppressed
args.rtl = args.rtl ==
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
வரி 1,177 ⟶ 1,396:
end
if args.translit then
local latn, pos, char;
latn, args.translit, pos, char = is_latin (args.translit, (('' ~= subtags.private) and (code .. '-x-' .. subtags.private)) or code);
if not latn then
return make_error_msg (substitute (cfg.lang_xx_t.translit_nonlatn, {pos, char}), args, template);
end
end
local is_latn_text, text, pos, char = is_latin (args.text, code); -- make a boolean
args.text = text; -- may have been modified (accept-as-written markup removed)
msg = text_script_match_test (subtags.script, is_latn_text, pos, char)
if msg then -- if an error detected then there is an error message
return make_error_msg (msg, args, template);
end
args.italic, msg = validate_italic (args);
if msg then
return make_error_msg (msg, args, template);
end
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 ('latn' == subtags.script)
(this_wiki_lang_tag ~= code and not is_set (subtags.script) and is_latn_text) then -- text is not this wiki's language, no script specified and is wholly latn script (auto-italics)
args.italic = 'italic'; -- set font-style:italic
else
args.italic =
end
end
else -- {{lang-xx}} does not do auto italics; retained for those wikis that don't support {{langx}}
if nil == args.italic then -- args.italic controls
if is_set (subtags.script) then
if 'latn' == subtags.script then
args.italic = 'italic'; -- |script=Latn; set for font-style:italic
else
args.italic = initial_style_state; -- italic not set; script is not latn; set for font-style:<initial_style_state>
end
else
args.italic = initial_style_state; -- here when |italic= and |script= not set; set for font-style:<initial_style_state>
end
end
end
வரி 1,204 ⟶ 1,451:
args.proto, msg = validate_proto (args.proto); -- return boolean, or nil, or nil and error message flag
if msg then
return make_error_msg (
end
வரி 1,218 ⟶ 1,465:
end
else
if
table.insert (out, language_name); -- language name without wikilink
else
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 ietf 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
table.insert (out, make_wikilink (lang_data.article_name[code], language_name)); -- language name with wikilink from override data
else
table.insert (out, make_wikilink (
end
end
வரி 1,232 ⟶ 1,481:
end
if
args.text = invert_italics (args.text)
end
வரி 1,240 ⟶ 1,489:
table.insert (out, make_text_html (args.code, args.text, tag, args.rtl, args.italic, args.size, ('none' == args.label) and language_name or nil))
if is_set (args.translit) and not
table.insert (out, ', '); -- comma to separate text from translit
if 'none' ~= args.label then
வரி 1,249 ⟶ 1,498:
translit_script_name = language_name; -- fall back on language name
end
local translit_title_obj = mw.title.makeTitle (0, substitute ('$1 $2',{cfg.lang_xx_t.romanization, translit_script_name})); -- make a title object; no engvar, article titles use US spelling
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', {cfg.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 ('
end
table.insert (out, ' </small>'); -- close the small tag
end
translit = make_translit (args.code, language_name, args.translit, args['translit-std'], args['translit-script'], nil, args.engvar)
if is_set (translit) then
table.insert (out, translit);
else
return make_error_msg (
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));
வரி 1,279 ⟶ 1,535:
--[[--------------------------< L A N G _ X X _ A R G S _ G E T >----------------------------------------------
Text positional parameters are not trimmed here but are selectively trimmed at html_tag_select().
]]
local function lang_xx_args_get (frame, base_template)
local
{
parentFirst= true, -- parameters in the template override parameters set in the {{#invoke:}}
valueFunc = function (key, value)
if ((cfg.templates_t.langx == base_template) and 2 or 1) == key then
return value; -- return untrimmed 'text' positional parameter
elseif value then -- all other values: if the value is not nil
value = mw.text.trim (value); -- trim whitespace
வரி 1,302 ⟶ 1,560:
});
return
end
வரி 1,308 ⟶ 1,566:
--[[--------------------------< L A N G _ X X _ I T A L I C >--------------------------------------------------
Entry point for those {{lang-
]]
local function lang_xx_italic (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|...}}
local msg = parameter_validate (args, cfg.templates_t.langxx); -- verify that all supplied parameters are supported by {{lang-??}}
if msg then
return make_error_msg (msg, args, cfg.templates_t.langxx); -- when template has unsupported params, abandon with error message
end
initial_style_state = 'italic';
return _lang_xx (args, cfg.templates_t.langxx) .. '[[Category:Pages using Lang-xx templates]]'; -- temporary category
end
வரி 1,322 ⟶ 1,586:
--[[--------------------------< _ L A N G _ X X _ I T A L I C >------------------------------------------------
Entry point
]]
வரி 1,328 ⟶ 1,592:
local function _lang_xx_italic (args)
initial_style_state = 'italic';
return _lang_xx (args, cfg.templates_t.langxx);
end
வரி 1,334 ⟶ 1,598:
--[[--------------------------< L A N G _ X X _ I N H E R I T >------------------------------------------------
Entry point for those {{lang-
]]
local function lang_xx_inherit (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|...}}
local msg = parameter_validate (args, cfg.templates_t.langxx); -- verify that all supplied parameters are supported by {{lang-??}}
if msg then
return make_error_msg (msg, args, cfg.templates_t.langxx); -- when template has unsupported params, abandon with error message
end
initial_style_state = 'inherit';
return _lang_xx (args, cfg.templates_t.langxx) .. '[[Category:Pages using Lang-xx templates]]'; -- temporary category
end
வரி 1,348 ⟶ 1,618:
--[[--------------------------< _ L A N G _ X X _ I N H E R I T >----------------------------------------------
Entry point from another module.
]]
வரி 1,354 ⟶ 1,624:
local function _lang_xx_inherit (args)
initial_style_state = 'inherit';
return _lang_xx (args, cfg.templates_t.langxx);
end
--[[--------------------------< _ L A N G X >------------------------------------------------------------------
Entry point from another module.
]]
local function _langx (args_t)
local langx_data = mw.loadData ('Module:Lang/langx'); -- get necessary data
local rtl_t = langx_data.rtl_t; -- get list of language tags for languages that are rendered right-to-left
local link_t = langx_data.link_t; -- get list of language tags for {{lang-??}} templates that set |link=<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, cfg.templates_t.langx);
if msg then
return make_error_msg (msg, args_t, cfg.templates_t.langx);
end
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
return make_error_msg (cfg.get_ietf_parts_t.missing_lang_tag, args_t, cfg.templates_t.langx);
end
args_t.rtl = args_t.rtl or (rtl_t[args_t.code] and cfg.keywords_t.affirmative); -- prefer |rtl= in template call, use rtl_t else
args_t.link = args_t.link or link_t[args_t.code]; -- prefer |link= in template call, use link_t felse
args_t.size = args_t.size or size_t[args_t.code]; -- prefer |size= in template call, use size_t else
args_t[1] = nil; -- unset to mimic {{lang-??}} templates which set |code=xx
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, cfg.templates_t.langx);
end
--[[--------------------------< L A N G X >--------------------------------------------------------------------
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> |<transl> |<xlate> }}
{{langx |<tag> |<text> |<transl> |<xlate> }}
The calls to lang_xx_args_get() and _lang_xx() use 'Langx' as a flag for those functions to select the proper
positional parameters.
{{lang-??}} depends on the calling template to select 'inherit' or 'italic' to establish the default rendering.
{{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).
]]
local function langx (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);
end
வரி 1,362 ⟶ 1,694:
Returns true when a language name associated with IETF language tag exists; nil else. IETF language tag must be valid.
All code combinations supported by {{lang}} and the {{lang-
Module entry point from another module.
]]
வரி 1,378 ⟶ 1,710:
--[[--------------------------< I S _ I E T F _ T A G >--------------------------------------------------------
Module entry point from an {{#invoke:}}.
]]
வரி 1,404 ⟶ 1,736:
Returns language name associated with IETF language tag if valid; error message else.
All code combinations supported by {{lang}} and the {{lang-
Set invoke's |link= parameter to yes to get wikilinked version of the language name.
Module entry point from another module.
]]
வரி 1,415 ⟶ 1,747:
local subtags = {}; -- IETF subtags script, region, variant, and private
local raw_code = args[1]; -- save a copy of the input IETF subtag
local link =
local label = args.label;
local code; -- the language code
வரி 1,424 ⟶ 1,756:
if msg then
local template = (args['template'] and table.concat ({'{{', args['template'], '}}: '})) or ''; -- make template name (if provided by the template)
return
end
வரி 1,430 ⟶ 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
if 'yes' ~= args.raw then
language_name = language_name:gsub ('%s+%b()', ''); -- remove IANA parenthetical disambiguators or qualifiers from names that have them
end
if link then -- when |link=yes, wikilink the language name
if mw.ustring.find (language_name, 'languages', 1, true) then
language_name = make_wikilink (language_name, label); -- collective language name uses simple wikilink
elseif lang_data.article_name[
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?
language_name = make_wikilink (lang_data.article_name[code], label or language_name); -- language name with wikilink from override data
else
language_name = make_wikilink (
end
end
வரி 1,448 ⟶ 1,784:
--[[--------------------------< N A M E _ F R O M _ T A G >----------------------------------------------------
Module entry point from an {{#invoke:}}.
]]
வரி 1,463 ⟶ 1,799:
that disambiguator must be omitted (they are not present in the data name-to-tag tables).
Module entry point from another module.
]]
வரி 1,478 ⟶ 1,814:
return tag, true; -- language name found so return tag and done; second return used by is_lang_name()
else
msg =
end
else
msg =
end
வரி 1,488 ⟶ 1,824:
template = table.concat ({'{{', args['template'], '}}: '}); -- make template name (if provided by the template)
end
return
end
வரி 1,494 ⟶ 1,831:
--[[--------------------------< T A G _ F R O M _ N A M E >----------------------------------------------------
Module entry point from an {{#invoke:}}.
]]
வரி 1,506 ⟶ 1,843:
--[[--------------------------< I S _ L A N G _ N A M E >------------------------------------------------------
Module entry point from an {{#invoke:}}.
]]
வரி 1,518 ⟶ 1,855:
--[[--------------------------< _ T R A N S L >----------------------------------------------------------------
Module entry point from another module.
]]
வரி 1,528 ⟶ 1,865:
local script; -- IANA script
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
வரி 1,537 ⟶ 1,875:
if not title_table[args.translit_std] then
return make_error_msg (
end
else
வரி 1,545 ⟶ 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?
args[1]:match ('^%a%a%a?%-x%-')) then -- or is args[1] a private-use tag
return make_error_msg (
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 (
end
end
வரி 1,557 ⟶ 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
else
return make_error_msg (
end
else
return make_error_msg (
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
args.italic, msg = validate_italic (args);
if msg then
return make_error_msg (msg, args,
end
வரி 1,571 ⟶ 1,916:
args.italic = nil; -- set to nil;
end
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?
வரி 1,584 ⟶ 1,931:
args.code = ''; -- unset because not a language code
else
return make_error_msg (
end
-- here only when all parameters passed to make_translit() are valid
return make_translit (args.code, language_name, args.text, args.translit_std, script, args.italic, args.engvar);
end
வரி 1,593 ⟶ 1,940:
--[[--------------------------< T R A N S L >------------------------------------------------------------------
Module entry point from an {{#invoke:}}.
]]
வரி 1,604 ⟶ 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-
Module entry point from another module.
]]
வரி 1,615 ⟶ 1,962:
local subtags = {}; -- IETF subtags script, region, variant, and private
local raw_code = args_t[1]; -- save a copy of the input IETF subtag
local link =
local label = args_t.label;
local code; -- the language code
வரி 1,624 ⟶ 1,971:
if msg then
local template = (args_t.template and table.concat ({'{{', args_t.template, '}}: '})) or ''; -- make template name (if provided by the template)
return
end
வரி 1,641 ⟶ 1,988:
--[[--------------------------< C A T E G O R Y _ F R O M _ T A G >--------------------------------------------
Module entry point from an {{#invoke:}}.
]]
வரி 1,656 ⟶ 2,003:
category_from_tag = category_from_tag,
lang = lang, -- entry point for {{lang}}
langx = langx, -- entry point for {{langx}}
lang_xx_inherit = lang_xx_inherit, -- entry points for {{lang-??}}
lang_xx_italic = lang_xx_italic,
வரி 1,667 ⟶ 2,015:
_category_from_tag = _category_from_tag, -- entry points when this module is require()d into other modules
_lang = _lang,
_langx = _langx,
_lang_xx_inherit = _lang_xx_inherit,
_lang_xx_italic = _lang_xx_italic,
| |||