Module:CS1 translator
Appearance
Usage
{{#invoke:CS1 translator|function_name}}
Templates supported by this module are auto-subst'd by User:AnomieBOT/docs/TemplateSubster because {{subst:}}
does not work inside <ref>...</ref>
tags. Templates must be listed in Category:Wikipedia templates to be automatically substituted.
Supported templates
require ('Module:No globals');
local _month_xlate = require ('Module:Month translator')._month_xlate;
local getArgs = require ('Module:Arguments').getArgs;
local literatur_params_map = {
['Titel'] = 'title',
['Herausgeber'] = 'editor',
['Sammelwerk'] = 'periodical',
['Verlag'] = 'publisher',
['Ort'] = 'location',
['Jahr'] = 'year',
['ISBN'] = 'isbn',
['Seiten'] = 'page',
['Online'] = 'url',
['Band'] = 'volume',
['Datum'] = 'date',
['Tag'] = '_day',
['Monat'] = '_month',
['Jahr'] = 'year',
['Nummer'] = 'number',
['Autor'] = 'author',
['Originalsprache'] = 'language',
['Originaltitel'] = 'title',
['Originaljahr'] = 'orig-date',
}
--[[--------------------------< 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( var )
return not (var == nil or var == '')
end
--[[--------------------------< L I T E R A T U R >------------------------------------------------------------
]]
local function literatur (frame)
local args_t = getArgs (frame);
local cite_args_t = {};
--error (mw.dumpObject (args_t))
if not args_t['Datum'] and args_t['Jahr'] and args_t['Monat'] then
table.insert (cite_args_t, table.concat ({'date', '=', _month_xlate ({mw.text.trim ((args_t['Tag'] or '') .. ' ' .. args_t['Monat'] .. ' ' .. args_t['Jahr'])})}));
elseif args_t['Datum'] then
table.insert (cite_args_t, table.concat ({'date', '=', _month_xlate ({args_t['Datum']})}));
end
args_t['Tag'] = nil;
args_t['Monat'] = nil;
args_t['Jahr'] = nil;
args_t['Datum'] = nil;
for param, val in pairs (args_t) do
if val then
if literatur_params_map[param] then -- if literatur param maps to cs1|2 template parameter
table.insert (cite_args_t, table.concat ({literatur_params_map[param], '=', val})); -- use the cs1|2 parameter
else
table.insert (cite_args_t, table.concat ({param, '=', val})); -- use literatur param
end
end
end
table.sort (cite_args_t);
--error (mw.dumpObject (cite_args_t))
local out_t = {}
for _, arg in ipairs (cite_args_t) do
local param, val = arg:match ('([^=]+)=(.+)');
out_t[param] = val;
end
--error (mw.dumpObject (out_t))
return frame:expandTemplate{title = 'citation', args = out_t};
end
return {literatur = literatur}