Module:CS1 translator
Útlit
Hægt er að búa til leiðbeiningar fyrir þessa skriftu á Module:CS1 translator/doc
--[[
TODO: |título=Copia archivada -> |title=Archive copy? Other languages?
TODO: make sure that citation bot doesn't improperly rename translatable templates; see $fix_it currently at https://github.com/ms609/citation-bot/blob/master/Template.php#L85
]]
require ('strict');
local _month_xlate = require ('Module:Month translator')._month_xlate;
local data = mw.loadData ('Module:CS1 translator/data');
local CS1 = require ("Module:Citation/CS1")
local params_main_t = data.params_main_t;
local params_dates_t = data.params_dates_t;
local params_misc_dates_t = data.params_misc_dates_t;
local params_identifiers_t = data.params_identifiers_t;
local params_language_t = data.params_language_t;
--[[--------------------------< I N _ A R R A Y >--------------------------------------------------------------
Whether needle is in haystack
]]
local function in_array (needle, haystack)
if needle == nil then
return false;
end
for n, v in ipairs (haystack) do
if v == needle then
return n;
end
end
return false;
end
--[[--------------------------< A R G S _ G E T >--------------------------------------------------------------
get parameter names and values into an associative table from <frame> (the parameters in the #invoke) and from
the parent frame (the parameters in the calling template); set all parameter names (keys) to lower case, skip
parameters with empty-string values, skip parameters with whitespace-only values, skip duplicate parameter names
(parameter names in the #invoke frame have precedence over the same parameter name in the template frame).
This replaces Module:Arguments.getArgs() because this allows us to set parameter names to lowercase; something
that can't be done with getArgs()
returns <count> (the number of parameters added to <args_t>) because #args_t doesn't always work
]]
local function args_get (frame, args_t)
local count = 0;
for _, frame_t in ipairs ({frame, frame:getParent()}) do -- invoke frame first, then template frame
for k, v in pairs (frame_t.args) do -- for each parameter in the <frames_t.args> associative table
if 'string' == type (k) then -- ignore positional parameters
k = mw.ustring.lower (k); -- set <k> lower here so we only do it once; ustring because ru.wiki
if v and not (args_t[k] or ('' == v) or (v:match ('^%s$'))) then -- skip when <args_t[k]> already present, skip when <v> is empty-string, skip when <v> is whitespace
args_t[k] = v; -- save k/v pair to in <args_t>
count = count + 1;
end
end
end
end
return count; -- return the number of parameters in <args_t>
end
--[[--------------------------< D A T E _ M A K E >------------------------------------------------------------
<args_t> - table of k/v pairs where k is the non-English parameter name and v is the assigned value from frame
<params_dates_t> - table of k/v_t pairs where k is the date part and v_t is a sequence table of non-English date-holding parameter names
<cite_args_t> - a sequence table that holds parameter=value strings (without pipes); for sorting
if args_t[<date_param>] is set, translate month name (if necessary) else assemble and translate date from date
parts args_t[<year_param>], args_t[<month_param>], args_t[<day_param>]. Resulting format is always dmy. Unset
all date values after date created. add translated date as text string to <cite_args_t> sequence table
month names in non-English |year= parameters that hold more than the year portion of a data (French |année=8 mars 2007 for example)
are NOT transla
]]
local function date_make (args_t, cite_args_t, params_dates_t)
local date, year, month, day;
if params_dates_t.date_t then -- TODO: is there a better way to do this?
for _, v in ipairs (params_dates_t.date_t) do -- loop through the date-holding parameters
date = args_t[v]; -- will be nil if not set
if date then break end -- if set, we're done
end
end
if params_dates_t.year_t then
for _, v in ipairs (params_dates_t.year_t) do -- loop through the year-holding parameters -- may also hold month and or day
year = args_t[v]; -- will be nil if not set
if year then break end -- if set, we're done
end
end
if params_dates_t.month_t then
for _, v in ipairs (params_dates_t.month_t) do -- loop through the month-holding parameters
month = args_t[v]; -- will be nil if not set
if month then break end -- if set, we're done
end
end
if params_dates_t.day_t then
for _, v in ipairs (params_dates_t.day_t) do -- loop through the day-holding parameters
day = args_t[v]; -- will be nil if not set
if day then break end -- if set, we're done
end
end
if date then
date = _month_xlate ({date}); -- attempt translation
elseif year then -- if 'year'; without year, any spurious 'month' and/or 'day' params meaningless; pass on as-is to cs1|2 for error handling
if month then
month = _month_xlate ({month}); -- if there is a month parameter, translate its value
local date_parts_t = {day, month, year};
local date_t = {}
for i=1, 3 do -- done this way because members of <date_parts_t> might be nil
if date_parts_t[i] then -- if not nil
table.insert (date_t, date_parts_t[i]); -- add to a temporary table
end
end
date = table.concat (date_t, ' '); -- make the dmy date string
else
-- date = year; -- no date so make |date=<year>
date = _month_xlate ({year}); -- attempt translation if non-English |year= has a month name
end
year = nil; -- unset no longer needed
end
local keys_t = {'date_t', 'year_t', 'month_t', 'day_t'};
for _, key in ipairs (keys_t) do -- loop through the keys_t sequence table
if params_dates_t[key] then -- if there is a matching table
for _, param in ipairs (params_dates_t[key]) do -- get each parameter name and
args_t[param] = nil; -- unset because no longer needed
end
end
end
if date then
cite_args_t['date'] = date -- create and save parameter-like string (without pipe)
if year then
cite_args_t['year'] = year -- do the same here; year because both |date= and |year= are allowed in cs1|2
end
end
end
--[[--------------------------< M I S C _ D A T E _ M A K E >--------------------------------------------------
<args_t> - table of k/v pairs where k is the non-English parameter name and v is the assigned value from frame
<cite_args_t> - a sequence table that holds parameter=value strings (without pipes); for sorting
<in_lang> - language code index into the non-English parameter names table
TODO: translate |orig-date=? can have a translatable date but can also have extraneous text ... At this writing,
_month_xlate() expects only a date.
]]
local function misc_date_make (args_t, cite_args_t, in_lang)
local misc_date;
for _, lang in ipairs ({in_lang, 'en'}) do -- first do non-English names then, because they might be present, look for English parameter names
for param, en_param in pairs (data.params_misc_dates_t[lang]) do
if args_t[param] then -- if the non-English parameter has a value
misc_date = _month_xlate ({args_t[param]}); -- translate the date
cite_args_t[en_param] = misc_date -- make the english parameter
args_t[param] = nil; -- unset, consumed no longer needed
end
end
end
end
--[[--------------------------< S E R I E S _ M A K E >--------------------------------------------------------
assemble the various 'series' parts into |series=
series={{{Reihe|}}} {{{NummerReihe|}}} {{{BandReihe|}}} {{{HrsgReihe|}}}
TODO: should this function be German only or does it need to allow other languages? is German the only language
that combines multiple elements into |series=?
]]
local function series_make (args_t, cite_args_t)
local series_t = {};
local params = {'reihe', 'nummerreihe', 'bandreihe', 'hrsgreihe'};
for _, param in ipairs (params) do
if args_t[param] then
table.insert (series_t, args_t[param]); -- add to temp sequence table
args_t[param] = nil; -- unset, no longer needed
end
end
if 0 ~= #series_t then
local series = table.concat (series_t, ', '); -- concatenate whichever parameters are present
cite_args_t['series'] = series -- and make a parameter
end
end
--[[--------------------------< I S X N _ M A K E >------------------------------------------------------------
make an |isbn= or |issn= parameter. This function applies ((accept-as-written)) markup when there is some sort
of parameter equivalent to cs1|2's (now deprecated) |ignore-isbn-error=
]]
local function isxn_make (args_t, cite_args_t, type, aliases_t, ignore_params_t, ignore_values_t)
local isxn;
local ignore_value;
for _, v in ipairs (aliases_t) do -- loop through the aliases_t sequence table
if args_t[v] then
isxn = args_t[v];
end
args_t[v] = nil; -- unset because no longer needed
end
for _, v in ipairs (ignore_params_t) do -- loop through the ignor_params_t sequence table
if args_t[v] then
ignore_value = args_t[v];
end
args_t[v] = nil; -- unset because no longer needed
end
if isxn and ignore_value and (in_array (ignore_value, ignore_values_t) or ignore_values_t['*']) then -- <ignore_values_t> is a table values that evaluate to 'yes' or wildcard
cite_args_t.type = '((' .. isxn .. '))' -- make parameter but accept this isxn as written
end
end
--[[--------------------------< A T _ M A K E >----------------------------------------------------------------
makes |at= for those templates that have things like |column=. Not qualified by |page= or |pages= so that cs1|2
will emit an error message when both |at= and |page(s)= present.
<aliases_t> is a sequence table of non-English parameter names
<prefix> - text string that prefixes the value in <alias>; 'col. ' for example
]]
local function at_make (args_t, cite_args_t, aliases_t, prefix)
for _, alias in ipairs (aliases_t) do
if args_t[alias] then
cite_args_t.prefix = args_t[alias]
end
args_t[alias] = nil; -- unset, no longer needed
end
end
--[[--------------------------< C H A P T E R _ M A K E _ F R >------------------------------------------------
make |chapter= from concatenation of chapter number (if present) and chapter name; chapter name else
]]
local function chapter_make_fr (args_t, cite_args_t)
local chapter = args_t['titre chapitre'] or args_t['chapitre'];
if chapter and (args_t['numéro chapitre'] or args_t['numéro']) then -- when chapter numbers, concatenate number with chapter name
chapter = (args_t['numéro chapitre'] or args_t['numéro']) .. ' ' .. chapter;
cite_args_t['chapter'] = chapter
elseif chapter then
cite_args_t['chapter'] = chapter -- here when chapter without number
end
args_t['titre chapitre'] = nil; -- unset as no longer needed
args_t['chapitre'] = nil;
args_t['numéro chapitre'] = nil;
args_t['numéro'] = nil;
end
--[[--------------------------< I D _ M A K E >----------------------------------------------------------------
make a comma separated list of identifiers to be included in |id=
<params_identifiers_t> is a sequence table of sequence tables where:
[1] is the non-English parameter name normalized to lower case
[2] is the associated wikitext label to be used in the rendering
[3] is the url prefix to be attached to the identifier value from the template parameter
[4] is the url postfix to be attached to the identifier value
]]
local function id_make (frame, args_t, cite_args_t, params_identifiers_t)
local id_t = {};
local value;
for _, identifier_t in ipairs (params_identifiers_t) do
if args_t[identifier_t[1]] then -- if this identifier parameter has a value
local value_t = {}
if identifier_t[2] then -- if there is a label (all except |id= should have a label)
table.insert (value_t, identifier_t[2]); -- the label
table.insert (value_t, ': '); -- the necessary punctuation and spacing
if identifier_t[3] then -- if an extlink prefix
table.insert (value_t, '['); -- open extlink markup
table.insert (value_t, identifier_t[3]); -- the link prefix
table.insert (value_t, args_t[identifier_t[1]]); -- the identifier value
if identifier_t[4] then -- postfix?
table.insert (value_t, identifier_t[4]); -- the link postfix
end
table.insert (value_t, ' '); -- require space between url and label
table.insert (value_t, args_t[identifier_t[1]]); -- the identifier value as label
table.insert (value_t, ']'); -- close extlink markup
else
table.insert (value_t, args_t[identifier_t[1]]); -- the identifier value
end
else
table.insert (value_t, args_t[identifier_t[1]]); -- no label so value only
end
table.insert (id_t, table.concat (value_t)); -- add to temp sequence table
args_t[identifier_t[1]] = nil; -- unset, no longer needed
end
end
if 0 ~= #id_t then
local id = table.concat (id_t, ', '); -- concatenate whichever parameters are present into a comma-separated list
cite_args_t['id'] = id -- and make a parameter
end
end
--[[--------------------------< T I T L E _ M A K E _ F R >----------------------------------------------------
join |title= with |subtitle= to make new |title=
]]
local function title_make_fr (args_t, cite_args_t)
local title = args_t['titre']; -- get the 'required' title parameter
args_t['titre'] = nil; -- unset as no longer needed
if not title then
title = args_t['titre original'] or args_t['titre vo']; -- if |titre= empty or missing use one of these 'aliases'
args_t['titre original'] = nil; -- unset as no longer needed
args_t['titre vo'] = nil;
end
if title then -- only when there is a title
if args_t['sous-titre'] then -- add subtitle if present
title = title .. ': ' .. args_t['sous-titre'];
args_t['sous-titre'] = nil; -- unset as no longer needed
end
cite_args_t['title'] = (title or '') -- add to cite_args_t
end
end
--[[--------------------------< T I T L E _ M A K E _ P T >----------------------------------------------------
join |title= with |subtitle= to make new |title=
]]
local function title_make_pt (args_t, cite_args_t)
local title = args_t['título'] or args_t['titulo'] or args_t['titlo']; -- get the 'required' title parameter
args_t['título'] = nil; -- unset as no longer needed
args_t['titulo'] = nil;
args_t['titlo'] = nil;
if not title then
return
end
if args_t['subtítulo'] or args_t['subtitulo'] then -- add subtitle if present
title = title .. ': ' .. (args_t['subtítulo'] or args_t['subtitulo']);
args_t['subtítulo'] = nil; -- unset as no longer needed
args_t['subtitulo'] = nil;
end
cite_args_t['title'] = (title or '') -- add to cite_args_t
end
--[[--------------------------< U R L _ S T A T U S _ M A K E >------------------------------------------------
<aliases_t> is a sequence table of |dead-url= parameter aliases
<no_values_t> is a table of k/v pairs where k is a valid parameter value that means 'no' as in |dead-url=no (ie |url-status=live)
]]
local function url_status_make (args_t, cite_args_t, aliases_t, no_values_t)
for _, alias in ipairs (aliases_t) do -- loop through the aliases_t sequence table
if args_t[alias] and no_values_t[args_t[alias]] then -- if the alias has a value and the value equates to 'no'
cite_args_t['url-status'] = 'live'
end
args_t[alias] = nil; -- unset because no longer necessary
end
end
--[[--------------------------< U R L _ A C C E S S _ M A K E >------------------------------------------------
<aliases_t> is a sequence table of |subscription= or |registration= parameter aliases
<values_t> is a table of k/v pairs where k is a valid parameter value that means 'yes' as in |subscription=yes (ie |url-access=subscription)
<values_t> can have a wildcard ('*'=true) which indicates that anything assigned to |subscription= or |registration= is sufficient
]]
local function url_access_make (args_t, cite_args_t, type, aliases_t, values_t)
for _, alias in ipairs (aliases_t) do -- loop through the aliases_t sequence table
if in_array (args_t[alias], values_t) or (args_t[alias] and values_t['*']) then -- if the alias has a value and the value equates to 'yes' or the wildcard
if 'subscription' == type then
cite_args_t['url-access'] = 'subscription'
else
cite_args_t['url-access'] = 'registration'
end
end
args_t[alias] = nil; -- unset because no longer necessary
end
end
--[[--------------------------< L A N G U A G E _ T A G _ G E T >----------------------------------------------
Test <lang> to see if it is a known language tag. If it is, return <lang>.
When <lang> not a known language tag, search through <known_langs_t> for <lang> as a language name; if found
return the associated language tag; <lang> else.
]]
local function language_tag_get (known_langs_t, lang)
if mw.language.isKnownLanguageTag (lang) then
return lang; -- <lang> is a known language tag ('en', 'da', etc); return the tag
end
local lang_lc = lang:lower(); -- make lowercase copy for comparisons
for tag, name in pairs (known_langs_t) do -- loop through <known_langs_t>
if lang_lc == name:lower() then -- looking for <lang_lc>
return tag; -- found it, return the associated language tag
end
end
return lang; -- not a known language or tag; return as is
end
--[[--------------------------< L A N G U A G E _ M A K E >----------------------------------------------------
this function looks at <lang_param_val> to see if it is a language tag known by WikiMedia. If it is a known
language tag, adds |language=<lang_param_val> to cite_args_t and unsets args_t[<lang_param>].
when <lang_param_val> is not a known language tag, fetches a k/v table of known language tags and names from MediaWiki
for the <in_lang> language (a language tag) where 'k' is a language tag and 'v' is the associated language name.
searches that table for <lang_param_val>. If found, adds |language=<tag> to cite_args_t and unsets args_t[<lang_param>]
this function takes no action and returns nothing when <lang_param_val> is not known.
language names are expected to be properly capitalized and spelled according to the rules of the source wiki so
the match must be exact.
]]
local function language_make (args_t, cite_args_t, in_lang, lang_params_t)
local lang_param;
local lang_param_val;
for _, v in ipairs (lang_params_t[in_lang]) do -- loop through the list of 'language' parameters supported at <in_lang>.wiki
if args_t[v] then -- if this parameter has a value
lang_param = v; -- save the parameter name
lang_param_val = args_t[v]; -- save the parameter value
end
args_t[v] = nil; -- unset not needed; if multiple 'language' parameters set, we use the 'last' one
end
if not lang_param_val then
return; -- no 'language' parameter in this template so done
end
local known_langs_t = mw.language.fetchLanguageNames (in_lang, 'all'); -- get k/v table of language names from MediaWiki for <in_lang> language; (k/v pair is ['tag'] = 'name')
local tag = language_tag_get (known_langs_t, lang_param_val); -- returns valid language tag or content of <lang_param_val>
cite_args_t['language'] = tag -- prefer the 'tag' because that is more translatable
args_t[lang_param] = nil; -- unset because no longer needed
end
--[[--------------------------< L A N G U A G E _ M A K E _ P T >----------------------------------------------
Special case for pt which supports some 'language' parameters that are not enumerated and some 'language' parameters
that are enumerated.
Inspects the non-enumerated parameters |codling=, |in=, and |ling=; if any set, return the value.
If none of the non-enumerated parameters are set, inspect the enumeratable parameters |idioma=, |língua=, |lingua=
in that order.
Collects the value from one of the non-enumerated parameters and returns that value or collects all of the values
from one set of the enumeratable parameters and returns only that set of languages.
If other non-enumerated parameters have values or other enumeratable parameter sets have values, they are ignored
so that the template will emit unrecognized parameter errors for the improper mixture of parameter names.
TODO: possible to share this with pl?
]]
local function language_make_pt (args_t, cite_args_t)
local known_langs_t = mw.language.fetchLanguageNames ('pt', 'all'); -- get a table of known language names and tags for Portuguese
local language;
for _, lang_param in ipairs ({'codling', 'in', 'ling'}) do -- non-enumerated language parameters
if args_t[lang_param] then
language = args_t[lang_param];
args_t[lang_param] = nil;
return language_tag_get (known_langs_t, language); -- attempt to get a language tag; return tag or <language>
end
end
local langs_t = {};
for _, lang_param in ipairs ({'idioma', 'língua', 'lingua'}) do -- for each set of enumeratable language parameters
local i=1; -- make an enumerator
while 1 do -- loop forever
if i == 1 then
if args_t[lang_param] or args_t[lang_param..i] then -- if non-enumerated or its enumerated alias
table.insert (langs_t, (args_t[lang_param] or args_t[lang_param..i])); -- prefer non-enumerated
args_t[lang_param] = nil; -- unset as no longer needed
args_t[lang_param..i] = nil;
else
break; -- no <lang_param> or <lang_param1> parameters; break out of while
end
elseif args_t[lang_param..i] then
table.insert (langs_t, args_t[lang_param..i]);
args_t[lang_param..i] = nil; -- unset as no longer needed
elseif 0 ~= #langs_t then -- here when <lang_param..(i-1)> but no <lang_param..i>
for i, lang in ipairs (langs_t) do -- loop through <langs_t> and
langs_t[i] = language_tag_get (known_langs_t, lang); -- attempt to get a language tag; returns tag or <lang>
end
return table.concat (langs_t, ', '); -- make a string and done
else
break; -- no <lang_param .. i> parameter; break out of while; should not get here
end
i = i + 1; -- bump the enumerator
end
end
end
--[[--------------------------< N A M E _ L I S T _ S T Y L E _ M A K E >--------------------------------------
<aliases_t> is a sequence table of |name-list-style= parameter aliases
<values_t> is a table of k/v pairs where 'k' is is the non-English parameter value and 'v' is its translation
for parameters that are |last-author-amp= translations, in the function call write: {['*'] = 'amp'}
]]
local function name_list_style_make (args_t, cite_args_t, aliases_t, values_t)
for _, alias in ipairs (aliases_t) do -- loop through the aliases_t sequence table
if args_t[alias] and (values_t[args_t[alias]] or values_t['*']) then -- if the alias has a recognized value
cite_args_t['name-list-style'] = values_t[args_t[alias]] or values_t['*']
end
args_t[alias] = nil; -- unset because no longer necessary
end
end
--[[--------------------------< R E N D E R >------------------------------------------------------------------
common renderer that translates parameters (after special case translations) and then renders the cs1|2 template
]]
local function render (frame, args_t, cite_args_t, params_main_t, config)
local styles = 'Module:Citation/CS1/styles.css';
local lookups = {
title = frame:getTitle(),
revisionid = frame:preprocess ('{{REVISIONID}}'),
templatestyles = frame:extensionTag ('templatestyles', '', {src=styles})
}
for param, val in pairs (args_t) do -- for each parameter in the template
if val and ('subst' ~= param) then -- when it has an assigned value; skip '|subst=subst:' (from AnomieBOT when it substs the cs1 template)
local enum = param:match ('%d+'); -- get the enumerator if <param> is enumerated; nil else
local param_key = param:gsub ('%d+', '#'); -- replace enumerator with '#' if <param> is enumerated
if params_main_t[mw.ustring.lower(param_key)] then -- if params_main_t[<param_key>] maps to a cs1|2 template parameter
local en_param = params_main_t[mw.ustring.lower(param_key)];
if enum then
en_param = en_param:gsub ('#', enum); -- replace '#' in enumerated cs1|2 parameter with enumerator from non-English parameter
end
cite_args_t[en_param] = val -- use the cs1|2 parameter with enumerator if present
else
cite_args_t[param] = val -- use non-English param
end
end
end
local xlated_msg = '<!-- auto-translated by Module:CS1 translator -->';
return table.concat ({CS1._citation(cite_args_t, config, lookups), xlated_msg}); -- render {{<template>}} template with translated parameters
end
--[[--------------------------< D A T E S _ A N D _ L A N G U A G E >------------------------------------------
date and language parameter functions utilized for almost all translations (pl and pt support enumerated language
parameters)
]]
local function dates_and_language (args_t, cite_args_t, in_lang)
date_make (args_t, cite_args_t, params_dates_t[in_lang]); -- assemble and translate |date=
misc_date_make (args_t, cite_args_t, in_lang);
language_make (args_t, cite_args_t, in_lang, params_language_t); -- translate language from German to appropriate language tag
end
--[[=========================<< C O M B I N E D _ F U N C T I O N S >>=========================================
]]
--[[--------------------------< _ C I T E _ A R >--------------------------------------------------------------
Common function to implement:
{{cite book/Arabic}} (ar:قالب:استشهاد بكتاب)
{{cite journal/Arabic}} (ar:قالب:استشهاد بدورية محكمة)
{{cite news/Arabic{{ (ar:قالب:استشهاد بخبر)
{{cite web/Arabic}} (ar:قالب:استشهاد ويب)
]]
local function _cite_ar (frame)
local args_t = {}; -- a table of k/v pairs that holds the template's parameters
args_get (frame, args_t); -- get the parameters and their values
local config = frame.args
local cite_args_t = {}; -- a sequence table that holds parameter=value strings (without pipes); for sorting
-- special cases
dates_and_language (args_t, cite_args_t, 'ar'); -- translate dates and language parameters
-- url_status_make (args_t, cite_args_t, {'deadurl', 'dead-url', 'dodeurl', 'dode-url'}, {['no'] = true, ['nee'] = true}); -- no Arabic status keywords 2023-12-08
-- id_make (frame, args_t, cite_args_t, params_identifiers_t.ar); -- assemble |id=
return render (frame, args_t, cite_args_t, params_main_t.ar, config); -- now go render the citation
end
--[[--------------------------< _ C I T E _ C A >--------------------------------------------------------------
Common function to implement:
{{cite web/Catalan}} (ca:Plantilla:Ref-web)
]]
local function _cite_ca (frame)
local args_t = {}; -- a table of k/v pairs that holds the template's parameters
args_get (frame, args_t); -- get the parameters and their values
local cite_args_t = {}; -- a sequence table that holds parameter=value strings (without pipes); for sorting
local config = frame.args
-- special cases
dates_and_language (args_t, cite_args_t, 'ca'); -- translate dates and language parameters
return render (frame, args_t, cite_args_t, params_main_t.ca, config); -- now go render the citation
end
--[[--------------------------< _ C I T E _ D A >--------------------------------------------------------------
<includeonly>{{safesubst:<noinclude />#invoke:Sandbox/trappist_the_monk/Literatur|cite_journal_da}}</includeonly><noinclude>{{documentation}}</noinclude>
Common function to implement:
{{cite book/Danish}} (da:Skabelon:Kilde bog)
{{cite journal/Danish}} (da:Skabelon:Kilde )
{{cite web/Danish}} (da:Skabelon:Kilde www)
]]
local function _cite_da (frame)
local args_t = {}; -- a table of k/v pairs that holds the template's parameters
args_get (frame, args_t); -- get the parameters and their values
local cite_args_t = {}; -- a sequence table that holds parameter=value strings (without pipes); for sorting
local config = frame.args
-- special cases
dates_and_language (args_t, cite_args_t, 'da'); -- translate dates and language parameters
url_status_make (args_t, cite_args_t, {'dead-url', 'deadurl', 'dødtlink', 'dødlenke', 'deadlink', 'død-lenke'}, {['no'] = true, ['nej'] = true});
url_access_make (args_t, cite_args_t, 'subscription', {'subscription', 'abonnement'}, {'yes', 'true', 'y', 'ja', 'sand', 'j'});
url_access_make (args_t, cite_args_t, 'registration', {'registration'}, {'yes', 'true', 'y', 'ja', 'sand', 'j'});
isxn_make (args_t, cite_args_t, 'isbn', {'isbn', 'isbn13'}, {'ignorer-isbn-fejl', 'ignoreisbnerror', 'ignore-isbn-error'}, {'yes', 'true', 'y', 'ja', 'sand', 'j'});
return render (frame, args_t, cite_args_t, params_main_t.da, config); -- now go render the citation
end
--[[--------------------------< _ C I T E _ D E >--------------------------------------------------------------
implements {{Literatur}} (de:Vorlage:Literatur), {{Cite web/German}} (de:Vorlage:Internetquelle)
]]
local function _cite_de (frame)
local args_t = {}; -- a table of k/v pairs that holds the template's parameters
args_get (frame, args_t); -- get the parameters and their values
local cite_args_t = {}; -- a sequence table that holds parameter=value strings (without pipes); for sorting
local config = frame.args
-- special cases
dates_and_language (args_t, cite_args_t, 'de'); -- translate dates and language parameters
series_make (args_t, cite_args_t); -- assemble |series=
local isxn;
for _, param in ipairs ({'isbnformalfalsch', 'isbndefekt'}) do -- these two parameters take a 'broken' but valid isbn
if args_t[param] then
isxn = '((' .. args_t[param] .. '))'; -- create |isbn=((<broken isbn>))
end
args_t[param] = nil; -- unset because no longer needed
end
if isxn then
table.insert (cite_args_t, isxn); -- save the parameter
end
if args_t['issnformalfalsch'] then -- these parameter takes a 'broken' but valid issn
isxn = '((' .. args_t['issnformalfalsch'] .. '))'; -- create |issn=((<broken issn>))
table.insert (cite_args_t, isxn); -- save the parameter
end
args_t['issnformalfalsch'] = nil; -- unset because no longer needed
at_make (args_t, cite_args_t, {'Spalten'}, 'col. '); -- assemble |at=col. ...
id_make (frame, args_t, cite_args_t, params_identifiers_t.de); -- assemble |id=
if args_t['hrsg'] then
if config.CitationClass == 'web' then -- cite web/German has different meaning from in de:Vorlage:Literatur (cite book/German)
cite_args_t['publisher'] = args_t['hrsg']
else -- different meaning from the meaning of this same parameter in de:Vorlage:Internetquelle (cite web/German)
cite_args_t['editor'] = args_t['hrsg']
end
args_t['hrsg'] = nil; -- unset, no longer needed
end
if args_t['offline'] then
args_t['offline'] = nil; -- any value means |url-status=dead; there is no form of this param that means |url-status=live; so just unset
end
return render (frame, args_t, cite_args_t, params_main_t.de, config); -- now go render the citation
end
--[[--------------------------< _ C I T E _ E S >--------------------------------------------------------------
implements {{Cita libro}} (:es:Plantilla:Cita_libro)
]]
local function _cite_es (frame)
local args_t = {}; -- a table of k/v pairs that holds the template's parameters
args_get (frame, args_t); -- get the parameters and their values
local cite_args_t = {}; -- a sequence table that holds parameter=value strings (without pipes); for sorting
local config = frame.args
-- special cases
dates_and_language (args_t, cite_args_t, 'es'); -- translate dates and language parameters
url_status_make (args_t, cite_args_t, {'urlmuerta'}, {['no'] = true});
url_access_make (args_t, cite_args_t, 'subscription', {'suscripción', 'subscription'}, {['*'] = true});
url_access_make (args_t, cite_args_t, 'registration', {'registration', 'requiere-registro', 'requiereregistro', 'registro'}, {['*'] = true})
isxn_make (args_t, cite_args_t, 'isbn', {'isbn', 'isbn13'}, {'ignore-isbn-error', 'ignoreisbnerror'}, {['*'] = true}); -- |ignore-isbn-error=<anything>
name_list_style_make (args_t, cite_args_t, {'ampersand', 'lastauthoramp', 'last-author-amp'}, {['*']='amp'});
return render (frame, args_t, cite_args_t, params_main_t.es, config); -- now go render the citation
end
--[[--------------------------< _ C I T E _ F I >--------------------------------------------------------------
implements {{Kirjaviite}} :fi:Malline:Kirjaviite
]]
local function _cite_fi (frame)
local args_t = {}; -- a table of k/v pairs that holds the template's parameters
args_get (frame, args_t); -- get the parameters and their values
local cite_args_t = {}; -- a sequence table that holds parameter=value strings (without pipes); for sorting
local config = frame.args
-- special cases
dates_and_language (args_t, cite_args_t, 'fi'); -- translate dates and language parameters
at_make (args_t, cite_args_t, {'palsta', 'palstat'}, 'col. ')
return render (frame, args_t, cite_args_t, params_main_t.fi, config); -- now go render the citation
end
--[[--------------------------< _ C I T E _ F R >--------------------------------------------------------------
implements {{cite book/French}} (:fr:Modèle:Ouvrage)
]]
local function _cite_fr (frame)
local args_t = {}; -- a table of k/v pairs that holds the template's parameters
args_get (frame, args_t); -- get the parameters and their values
local cite_args_t = {}; -- a sequence table that holds parameter=value strings (without pipes); for sorting
local config = frame.args
-- special cases
dates_and_language (args_t, cite_args_t, 'fr'); -- translate dates and language parameters
if config.CitationClass == 'book' then
chapter_make_fr (args_t, cite_args_t)
else
if args_t['numéro'] then
cite_args_t.issue = args_t['numéro'];
args_t['numéro'] = nil;
end
end
title_make_fr (args_t, cite_args_t);
if args_t['accès url'] then
local values = {['inscription'] = 'subscription', ['payant'] = 'subscription', ['limité'] = 'limited', ['libre'] = 'libre'}; -- 'libre' not supported; include it to get the error message
cite_args_t['url-access'] = (values[args_t['accès url']] or args_t['accès url'])
args_t['accès url'] = nil;
end
url_status_make (args_t, cite_args_t, {'dead-url'}, {['no'] = true, ['non'] = true});
if 'oui' == args_t['et al.'] or 'oui' == args_t['et alii'] then -- accepted value 'oui'; special case |display-authors=etal
cite_args_t['display-authors'] = 'etal'
args_t['et al.'] = nil; -- unset as no longer needed
args_t['et alii'] = nil;
end
if args_t['isbn erroné'] then
cite_args_t['isbn'] = '((' .. args_t['isbn erroné'] .. '))' -- apply accept-as-written markup
args_t['isbn'] = nil; -- can't have |isbn= and |isbn erroné=
args_t['isbn erroné'] = nil; -- unset as no longer needed
end
local volume;
if args_t['titre volume'] or args_t['tome'] then
if args_t['tome'] then
volume = args_t['tome']; -- begin with volume 'number'
end
if volume then
volume = volume .. ' ' .. args_t['tome']; -- append volume 'title'
else
volume = args_t['titre volume']; -- just volume 'title'
end
args_t['titre volume'] = nil; -- unset as no longer needed
args_t['tome'] = nil;
end
id_make (frame, args_t, cite_args_t, params_identifiers_t.fr); -- assemble |id=
if args_t['pages'] then
args_t['pages'] = nil; -- unset; alias of |pages totales=; no equivalent in cs1|2
end
return render (frame, args_t, cite_args_t, params_main_t.fr, config); -- now go render the citation
end
--[[--------------------------< _ C I T E _ I T >--------------------------------------------------------------
implements {{Cita libro}} (:it:Template:Cita_libro)
]]
local function _cite_it (frame)
local args_t = {}; -- a table of k/v pairs that holds the template's parameters
args_get (frame, args_t); -- get the parameters and their values
local cite_args_t = {}; -- a sequence table that holds parameter=value strings (without pipes); for sorting
local config = frame.args
-- special cases
dates_and_language (args_t, cite_args_t, 'it'); -- translate dates and language parameters
url_status_make (args_t, cite_args_t, {'urlmorto'}, {['no'] = true});
url_access_make (args_t, cite_args_t, 'subscription', {'richiestasottoscrizione'}, {['*'] = true}); -- |richiestasottoscrizione=<anything> -> |url-access=subscription
isxn_make (args_t, cite_args_t, 'isbn', {'isbn', 'isbn13'}, {'ignoraisbn'}, {['*'] = true}); -- |ignore-isbn-error=<anything>
name_list_style_make (args_t, cite_args_t, {'lastauthoramp'}, {['*']='amp'}); -- listed in ~/Whitelist and ~/Configuration but not supported in main module
if args_t['etal'] then -- apparently any value (typically 's', 'sì', or 'si'); rather like |display-authors=etal
cite_args_t['display-authors'] = 'etal'
args_t['etal'] = nil;
end
if args_t['etalcuratori'] then
cite_args_t['display-editors'] = 'etal'
args_t['etalcuratori'] = nil;
end
return render (frame, args_t, cite_args_t, params_main_t.it, config); -- now go render the citation
end
--[[--------------------------< _ C I T E _ N L >--------------------------------------------------------------
<includeonly>{{safesubst:<noinclude />#invoke:Sandbox/trappist_the_monk/Literatur|cite_journal_nl}}</includeonly><noinclude>{{documentation}}</noinclude>
Common function to implement:
{{cite book/Dutch}} (nl:Sjabloon:Citeer boek)
{{cite journal/Dutch}} (nl:Sjabloon:Citeer journal)
{{cite web/Dutch}} (nl:Sjabloon:Citeer)
]]
local function _cite_nl (frame)
local args_t = {}; -- a table of k/v pairs that holds the template's parameters
args_get (frame, args_t); -- get the parameters and their values
local cite_args_t = {}; -- a sequence table that holds parameter=value strings (without pipes); for sorting
local config = frame.args
-- special cases
dates_and_language (args_t, cite_args_t, 'nl'); -- translate dates and language parameters
url_status_make (args_t, cite_args_t, {'deadurl', 'dead-url', 'dodeurl', 'dode-url'}, {['no'] = true, ['nee'] = true});
id_make (frame, args_t, cite_args_t, params_identifiers_t.nl); -- assemble |id=
return render (frame, args_t, cite_args_t, params_main_t.nl, config); -- now go render the citation
end
--[[--------------------------< _ C I T E _ P L >--------------------------------------------------------------
<includeonly>{{safesubst:<noinclude />#invoke:Sandbox/trappist_the_monk/Literatur|cite_journal_pl}}</includeonly><noinclude>{{documentation}}</noinclude>
Common function to implement:
{{citation/Polish}} (pl:Szablon:Cytuj)
{{cite book/Polish}} (pl:Szablon:Cytuj książkę)
{{cite journal/Polish}} (pl:Szablon:Cytuj pismo)
{{cite web/Polish}} (pl:Szablon:Cytuj stronę)
]]
local function _cite_pl (frame)
local args_t = {}; -- a table of k/v pairs that holds the template's parameters
args_get (frame, args_t); -- get the parameters and their values
local cite_args_t = {}; -- a sequence table that holds parameter=value strings (without pipes); for sorting
local config = frame.args
-- special cases
date_make (args_t, cite_args_t, params_dates_t.pl); -- assemble and translate |date=
misc_date_make (args_t, cite_args_t, 'pl');
if 'tak' == args_t['odn'] then -- |ref=tak is more-or-less the same as |ref=harv at en.wiki
args_t['odn'] = nil; -- unset because superfluous at en.wiki
end
if args_t['tom'] or args_t['tytuł tomu'] then
local volume;
if args_t['tom'] then
volume = args_t['tom'];
end
if args_t['tytuł tomu'] then
if volume then
volume = volume .. ' ' .. args_t['tytuł tomu'];
else
volume = args_t['tytuł tomu'];
end
end
if volume then
cite_args_t['volume'] = volume
args_t['tom'] = nil; -- unset as no longer needed
args_t['tytuł tomu'] = nil;
end
end
local i=1; -- make a counter
local language;
while 1 do -- loop forever TODO: same enough as pt to combine with language_make_pt()?
if i == 1 then
if args_t['język'] or args_t['język1'] then -- if non-enumerated or its enumerated alias
language = args_t['język'] or args_t['język1']; -- prefer non-enumerated
args_t['język'] = nil; -- unset as no longer needed
args_t['język1'] = nil;
else
break;
end
elseif args_t['język'..i] then
language = language .. ', ' .. args_t['język'..i];
args_t['język'..i] = nil; -- unset as no longer needed
else
break;
end
i = i + 1; -- bump the counter
end
if language then
cite_args_t['language'] = language
end
return render (frame, args_t, cite_args_t, params_main_t.pl, config); -- now go render the citation
end
--[[--------------------------< _ C I T E _ P T >--------------------------------------------------------------
Common function to implement:
{{citation/Portuguese}} (pt:Predefinição:Citation)
{{cite book/Portuguese}} (pt:Predefinição:Citar livro)
{{cite journal/Portuguese}} (pt:Predefinição:Citar periódico)
{{cite news/Portuguese}} (pt:Predefinição:Citar jornal)
{{cite web/Portuguese}} (pt:Predefinição:Citar web)
]]
local function _cite_pt (frame)
local args_t = {}; -- a table of k/v pairs that holds the template's parameters
args_get (frame, args_t); -- get the parameters and their values
local cite_args_t = {}; -- a sequence table that holds parameter=value strings (without pipes); for sorting
local config = frame.args
-- special cases
date_make (args_t, cite_args_t, params_dates_t.pt); -- assemble and translate |date=
misc_date_make (args_t, cite_args_t, 'pt');
title_make_pt (args_t, cite_args_t); -- join |title= with |subtitle= to make new title
url_status_make (args_t, cite_args_t, {'datali', 'dead-url', 'deadurl', 'li', 'ligação inactiva', 'ligação inativa', 'urlmorta'}, {['no'] = true, ['não'] = true});
local language = language_make_pt (args_t, cite_args_t); -- get string of language tags and/or unknown language names (or nil if no language parameters)
if language then
cite_args_t['language'] = language
end
return render (frame, args_t, cite_args_t, params_main_t.pt, config); -- now go render the citation
end
--[[--------------------------< _ C I T E _ S V >--------------------------------------------------------------
<includeonly>{{safesubst:<noinclude />#invoke:Sandbox/trappist_the_monk/Literatur|cite_journal_sv}}</includeonly><noinclude>{{documentation}}</noinclude>
Common function to implement:
{{cite book/Swedish}} (sv:Mall:Bokref)
{{cite journal/Swedish}} (sv:Mall:Tidskriftsref)
{{cite web/Swedish}} (sv:Mall:Webbref)
]]
local function _cite_sv (frame)
local args_t = {}; -- a table of k/v pairs that holds the template's parameters
args_get (frame, args_t); -- get the parameters and their values
local cite_args_t = {}; -- a sequence table that holds parameter=value strings (without pipes); for sorting
local config = frame.args
-- special cases
dates_and_language (args_t, cite_args_t, 'sv'); -- translate dates and language parameters
name_list_style_make (args_t, cite_args_t, {'författarsep'}, {['*'] = 'amp'});
id_make (frame, args_t, cite_args_t, params_identifiers_t.sv)
return render (frame, args_t, cite_args_t, params_main_t.sv, config); -- now go render the citation
end
--[[=========================<< C I T E B O O K F U N C T I O N S >>=======================================
]]
--[[--------------------------< C I T E _ B O O K _ R U >------------------------------------------------------
implements {{Книга}} (:ru:Шаблон:Книга)
]]
local function _cite_ru (frame)
local args_t = {}; -- a table of k/v pairs that holds the template's parameters
args_get (frame, args_t); -- get the parameters and their values
local cite_args_t = {}; -- a sequence table that holds parameter=value strings (without pipes); for sorting
local config = frame.args
-- special cases
dates_and_language (args_t, cite_args_t, 'ru'); -- translate dates and language parameters
at_make (args_t, cite_args_t, {'столбцы'}, 'col. ')
return render (frame, args_t, cite_args_t, params_main_t.ru, config); -- now go render the citation
end
--[[=========================<< C I T E W E B F U N C T I O N S >>=========================================
]]
--[[--------------------------< _ C I T E _ N O >--------------------------------------------------------------
implements
{{cite book/Norwegian}} (:no:Mal:Kilde bok)
{{cite journal/Norwegian}} (:no:Mal:Kilde artikkel)
{{cite web/Norwegian}} (:no:Mal:Kilde www)
]]
local function _cite_no (frame)
local args_t = {}; -- a table of k/v pairs that holds the template's parameters
args_get (frame, args_t); -- get the parameters and their values
local cite_args_t = {}; -- a sequence table that holds parameter=value strings (without pipes); for sorting
local config = frame.args
-- special cases
dates_and_language (args_t, cite_args_t, 'no'); -- translate dates and language parameters
url_status_make (args_t, cite_args_t, {'død-lenke', 'dødlenke'}, {['no'] = true, ['nei'] = true});
url_access_make (args_t, cite_args_t, 'subscription', {'abonnement', 'abb'}, {'yes', 'true', 'y', 'ja'}); -- for |subscription=
url_access_make (args_t, cite_args_t, 'registration', {'registrering'}, {'yes', 'true', 'y', 'ja'}); -- for |registration=
if args_t['url-tilgang'] then -- translate value assigned to |url-access= TODO: make this into a shared function?
local values = {['abonnement'] = 'subscription', ['registrering'] = 'registration', ['begrenset'] = 'limited', ['åpen'] = 'åpen'}; -- 'åpen' not supported; include it to get the error message
cite_args_t['url-access'] = (values[args_t['url-tilgang']] or args_t['url-tilgang'])
args_t['url-tilgang'] = nil;
end
isxn_make (args_t, cite_args_t, 'isbn', {'isbn', 'isbn13'}, {'ignorer-isbn-feil', 'ignorerisbnfeil'}, {'yes', 'true', 'y', 'ja'});
if not args_t['navnelisteformat'] then
name_list_style_make (args_t, cite_args_t, {'sisteforfatteramp'}, {['*']='amp'});
end
return render (frame, args_t, cite_args_t, params_main_t.no, config); -- now go render the citation
end
--[[--------------------------< _ C I T E _ T R >--------------------------------------------------------------
implements {{Web kaynağı}} (:tr:Şablon:Web_kaynağı, :tr:Şablon:Akademik dergi kaynağı (journal))
]]
local function _cite_tr (frame)
local args_t = {}; -- a table of k/v pairs that holds the template's parameters
args_get (frame, args_t); -- get the parameters and their values
local cite_args_t = {}; -- a sequence table that holds parameter=value strings (without pipes); for sorting
local config = frame.args
-- special cases
dates_and_language (args_t, cite_args_t, 'tr'); -- translate dates and language parameters
url_status_make (args_t, cite_args_t, {'ölüurl', 'ölü-url', 'bozukurl'}, {['hayır'] = true, ['h'] = true, ['no'] = true});
if not (args_t['url-access'] or args_t['url-erişimi'] or args_t['URLerişimi']) then
url_access_make (args_t, cite_args_t, 'subscription', {'subscription'}, {'yes', 'true', 'y', 'e', 'evet', 'doğru'})
url_access_make (args_t, cite_args_t, 'registration', {'registration'}, {'yes', 'true', 'y', 'e', 'evet', 'doğru'})
end
isxn_make (args_t, cite_args_t, 'isbn', {'isbn', 'isbn13'}, {'ignore-isbn-error', 'ignoreisbnerror'}, {'yes', 'true', 'y', 'e', 'evet', 'doğru'});
name_list_style_make (args_t, cite_args_t, {'last-author-amp', 'lastauthoramp', 'sonyazarve'}, {['*']='amp'}); -- listed in ~/Whitelist and ~/Configuration (SonYazarVe) not supported in main
return render (frame, args_t, cite_args_t, params_main_t.tr); -- now go render the citation
end
--[[=========================<< I N T E R M E D I A T E F U N C T I O N S >>=================================
]]
--[[--------------------------< _ C I T E _ E S _ I T >--------------------------------------------------------
Because the Spanish and Italian templates {{cita news}}, {{cita libro}}, and {{cita web}} share the names but
nothing else, they must be distinguished one from the other. This is done by looking at their (required) title
parameters:
título – Spanish
titolo – Italian
<funct_t> is a k/v table where k is the ISO 639-1 language code (es: Spanish; it: Italian) and v is the matching
funtion that handles this {{cita news}}, {{cita libro}}, or {{cita web}} template
it.wiki supports positional parameters for <url> ({{{1}}}) and <title> ({{{2}}}); because it is necessary to use
the |title= equivalent to determine which function to call, the it.wiki positional parameters are not supported.
]]
local function _cite_es_it (frame)
local f_title = frame.args['título']; -- look for Spanish |title= parameter in the frame
local p_title = frame:getParent().args['título']; -- and in the parent frame
if (f_title and '' ~= f_title) or (p_title and '' ~= p_title) then -- when set and not be an empty string
return _cite_es(frame); -- call the Spanish version
end
f_title = frame.args['titolo']; -- look for Italian |title= parameter
p_title = frame:getParent().args['titolo'];
if (f_title and '' ~= f_title) or (p_title and '' ~= p_title) then -- when set and not be an empty string
return _cite_it(frame); -- call the Italian version
end
-- when here return an error message
return '<span style="color:#d33">{{cita book/news/web}} requires |título= (Spanish) or |titolo= (Italian)</span>';
end
--[[--------------------------< C I T E _ W E B _ D A _ N O >--------------------------------------------------
implements {{cite web/Danish}} (da:Skabelon:Kilde_www and no:Mal:Kilde_www)
this function counts the number of parameter names that are listed in params_main_t.da and params_main_t.no and then
from those counts, decides which of cite_web_da() or cite_web_no() to call.
]]
local function cite_web_da_no (frame)
local args_t = {}; -- a table of k/v pairs that holds the template's parameters
args_get (frame, args_t); -- get the parameters and their values
local count_da = 0; -- number of parameter that are listed in <params_main_t.da>
local count_no = 0; -- number of parameter that are listed in <params_main_t.no>
for k, _ in pairs (args_t) do -- for each parameter in <args_t>
for _, map_t in ipairs ({params_main_t, params_misc_dates_t}) do -- and for each of these tables
for _, code in ipairs ({'da', 'no'}) do -- and for each of these language codes
if map_t[code][k] and 'da' == code then -- when this is a Danish parameter
count_da = count_da + 1; -- bump the Danish counter
end
if map_t[code][k] and 'no' == code then -- when this is a Norwegian parameter
count_no = count_no + 1; -- bump the Norwegian counter
end
end
end
end
if count_da >= count_no then -- when count of da.wiki params greater than or equal to count of no.wiki parms
return _cite_da (frame); -- assume this is a da.wiki cite web
else
return _cite_no (frame); -- else assume this is a no.wiki cite web
end
end
--[[--------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------
]]
return {
_cite_ar = _cite_ar,
_cite_ca = _cite_ca,
_cite_da = _cite_da,
_cite_de = _cite_de,
_cite_es = _cite_es,
_cite_fi = _cite_fi,
_cite_fr = _cite_fr,
_cite_it = _cite_it,
_cite_nl = _cite_nl,
_cite_pl = _cite_pl,
_cite_pt = _cite_pt,
_cite_sv = _cite_sv,
_cite_ru = _cite_ru,
_cite_no = _cite_no,
_cite_tr = _cite_tr,
_cite_es_it = _cite_es_it,
cite_web_da_no = cite_web_da_no, -- common entry point for {{cite web/Danish or Norwegian}} (Danish da:Skabelon:Kilde www / Norwegian no:Mal:Kilde www)
}