మాడ్యూల్:Citation/CS1: కూర్పుల మధ్య తేడాలు

Content deleted Content added
post-update update;
language; generic name;
పంక్తి 1,359:
 
local function is_generic (item, value)
local test_val;
value = mw.ustring.lower(value); -- switch value to lower case
 
for _, generic_value in ipairs (cfg.special_case_translation[item]) do -- spin through the list of known generic value fragments
test_val = generic_value['en'][2] and value:lower() or value; -- when set to 'true', plaintext search using lowercase value
if value:find (generic_value['en'][1], 1, generic_value['en'][2]) then
 
if test_val:find (generic_value['en'][1], 1, generic_value['en'][2]) then
return true; -- found English generic value so done
 
elseif generic_value['local'] then -- to keep work load down, generic_<value>['local'] should be nil except when there is a local version of the generic value
iftest_val mw.ustring.find (value, generic_value['local'][1], 1,= generic_value['local'][2]) then --and mw.ustring.lower(value) becauseor mightvalue; -- notwhen beset Latinto script'true', plaintext search using lowercase value
 
if mw.ustring.find (test_val, generic_value['local'][1], 1, generic_value['local'][2]) then -- mw.ustring() because might not be Latin script
return true; -- found local generic value so done
end
Line 1,501 ⟶ 1,507:
 
 
--[[--------------------------< GN A M E T _ IT SA O 6 3 9G _ CG OE D ET >------------------------------------------------------
 
attempt to decode |language=<lang_param> and return language name and matching tag; nil else.
Validates language names provided in |language= parameter if not an ISO639-1 or 639-2 code.
 
This function looks for:
Returns the language name and associated two- or three-character code. Because
<lang_param> as a tag in cfg.lang_code_remap{}
case of the source may be incorrect or different from the case that WikiMedia uses,
<lang_param> as a name in cfg.lang_name_remap{}
the name comparisons are done in lower case and when a match is found, the Wikimedia
version (assumed to be correct) is returned along with the code. When there is no
<lang_param> as a name in cfg.mw_languages_by_name_t
match, we return the original language name string.
<lang_param> as a tag in cfg.mw_languages_by_tag_t
when those fail, presume that <lang_param> is an IETF-like tag that MediaWiki does not recognize. Strip all
script, region, variant, whatever subtags from <lang_param> to leave just a two or three character language tag
and look for the new <lang_param> in cfg.mw_languages_by_tag_t{}
 
on success, return name and matching tag; on failure return nil
mw.language.fetchLanguageNames(<local wiki language>, 'all') returns a list of
languages that in some cases may include extensions. For example, code 'cbk-zam'
and its associated name 'Chavacano de Zamboanga' (MediaWiki does not support
code 'cbk' or name 'Chavacano'. Most (all?) of these languages are not used a
'language' codes per se, rather they are used as sub-domain names: cbk-zam.wikipedia.org.
A list of language names and codes supported by fetchLanguageNames() can be found
at Template:Citation Style documentation/language/doc
 
]]
Names that are included in the list will be found if that name is provided in the
|language= parameter. For example, if |language=Chavacano de Zamboanga, that name
will be found with the associated code 'cbk-zam'. When names are found and the
associated code is not two or three characters, this function returns only the
WikiMedia language name.
 
local function name_tag_get (lang_param)
Some language names have multiple entries under different codes:
local lang_param_lc = mw.ustring.lower (lang_param); -- use lowercase as an index into the various tables
Aromanian has code rup and code roa-rup
When this occurs, this function returns the language name and the 2- or 3-character code
 
local name = cfg.lang_code_remap[lang_param_lc]; -- assume <lang_param_lc> is a tag; attempt to get remapped language name
Adapted from code taken from Module:Check ISO 639-1.
if name then -- when <name>, <lang_param> is a tag for a remapped language name
return name, lang_param; -- so return <name> from remap and <lang_param>
end
 
if cfg.lang_name_remap[lang_param_lc] then -- not a tag, assume <lang_param_lc> is a name; attempt to get remapped language tag
]]
return cfg.lang_name_remap[lang_param_lc][1], cfg.lang_name_remap[lang_param_lc][2]; -- for this <lang_param_lc>, return a (possibly) new name and appropriate tag
 
local function get_iso639_code (lang, this_wiki_code)
if cfg.lang_name_remap[lang:lower()] then -- if there is a remapped name (because MediaWiki uses something that we don't think is correct)
return cfg.lang_name_remap[lang:lower()][1], cfg.lang_name_remap[lang:lower()][2]; -- for this language 'name', return a possibly new name and appropriate code
end
 
local tag = cfg.mw_languages_by_name_t[lang_param_lc]; -- assume that <lang_param_lc> is a language name; attempt to get its matching tag
local ietf_tag; -- because some languages have both IETF-like tags and ISO 639-like tags
local ietf_name;
if tag then
local langlc = mw.ustring.lower (lang); -- lower-case version for comparisons
return cfg.mw_languages_by_tag_t[tag], tag; -- <lang_param_lc> is a name so return the name from the table and <tag>
end
 
for tag, name in pairs= (cfg.languages) do mw_languages_by_tag_t[lang_param_lc]; -- scanassume thethat list<lang_param_lc> tois seea iftag; weattempt canto findget ourits matching language name
if langlc == mw.ustring.lower (name) then
if name then
if 2 == #tag or 3 == #tag then -- two- or three-character tags preferred over IETF-like tags with the same name
return name, taglang_param; -- found<lang_param_lc> itis a tag so return the <name> and the tag
end
ietf_tag = tag; -- remember that we found an IETF-like tag and save its name and tag
ietf_name = name; -- but keep looking for a 2- or 3-char tag version
end
end
tag = lang_param_lc:match ('^(%a%a%a?)%-.*'); -- is tag an IETF-like tag that MediaWiki doesn't recognize? <tag> gets the language subtag; nil else
if ietf_tag and ietf_name then -- when we didn't find name with 2- or 3-char tag but did find IETF-like tag
 
return ietf_name, ietf_tag; -- return name with IETF-like tag
if tag then
else
returnname lang= cfg.mw_languages_by_tag_t[tag]; -- notattempt found,to returnget originala language textname using the shortened <tag>
if name then
return name, tag; -- <lang_param_lc> is an unrecognized IETF-like tag so return <name> and language subtag
end
end
end
Line 1,583 ⟶ 1,582:
 
local function language_parameter (lang)
local codetag; -- thesome two-form orof threeIETF-characterlike language codetag; language subtag with optional region, sript, vatiant, etc subtags
local lang_subtag; -- ve populates |language= with mostly unecessary region subtags the MediaWiki does not recognize; this is the base language subtag
local name; -- the language name
local language_list = {}; -- table of language names to be rendered
local names_tablenames_t = {}; -- table made from the value assigned to |language=
 
local this_wiki_name = mw.language.fetchLanguageName (cfg.this_wiki_code, cfg.this_wiki_code); -- get this wiki's language name
 
names_tablenames_t = mw.text.split (lang, '%s*,%s*'); -- names should be a comma separated list
 
for _, lang in ipairs (names_table) do -- reuse lang
name = cfg.lang_code_remap[lang:lower()]; -- first see if this is a code that is not supported by MediaWiki but is in remap
 
if not name then
name = mw.language.fetchLanguageName (lang:lower(), cfg.this_wiki_code); -- get language name if <lang> is a MediaWiki known code; empty string if not known
end
 
if utilities.is_set (name) then -- if |language= specified a valid code
code = lang:lower(); -- save it
else
name, code = get_iso639_code (lang, cfg.this_wiki_code); -- attempt to get code from name (assign name here so that we are sure of proper capitalization)
end
 
for _, lang in ipairs (names_t) do -- reuse lang here because we don't yet know if lang is a language name or a language tag
if utilities.is_set (code) then
name, tag = cfg.lang_code_remap[code]name_tag_get or name(lang); -- overrideattempt wikimediato whenget theyname/tag misusepair languagefor codes/names<lang>
 
if utilities.is_set (tag) then
code = code:gsub ('^(%a%a%a?)%-.*', '%1'); -- for categorization, strip any IETF-like tags from language tag
lang_subtag = tag:gsub ('^(%a%a%a?)%-.*', '%1'); -- for categorization, strip any IETF-like tags from language tag
 
if cfg.this_wiki_code ~= codelang_subtag then -- when the language is not the same as this wiki's language
if 2 == codelang_subtag:len() then -- and is a two-character codetag
utilities.add_prop_cat ('foreign-lang-source', {name, codelang_subtag}, codelang_subtag); -- categorize it; codetag appended to allow for multiple language categorization
else -- or is a recognized language (but has a three-character codetag)
utilities.add_prop_cat ('foreign-lang-source-2', {codelang_subtag}, codelang_subtag); -- categorize it differently TODO: support multiple three-character codetag categories per cs1|2 template?
end
elseif cfg.local_lang_cat_enable then -- when the language and this wiki's language are the same and categorization is enabled
utilities.add_prop_cat ('local-lang-source', {name, codelang_subtag}); -- categorize it
end
else
name = lang; -- return whatever <lang> has so that we show something
utilities.set_message ('maint_unknown_lang'); -- add maint category if not already added
end
Line 1,628 ⟶ 1,617:
name = utilities.make_sep_list (#language_list, language_list);
if (1 == #language_list) and (codetag == cfg.this_wiki_code) then -- when only one language, find lang name in this wiki lang name; for |language=en-us, 'English' in 'American English'
return ''; -- if one language and that language is this wiki's return an empty string (no annotation)
end
"https://te.wikipedia.org/wiki/మాడ్యూల్:Citation/CS1" నుండి వెలికితీశారు