モジュール:Cite/sandbox

require ('strict');
local isSandbox = mw.getCurrentFrame():getTitle():find('sandbox', 1, true)		--日本語版独自: sandboxを分岐
local sandbox = isSandbox and '/sandbox' or 
local cfg = mw.loadData ('Module:Cite/config' .. sandbox);
--------------------------------------------------------------------------------------
Substitutes $1, $2, etc in  with data from . Returns plain-text substituted string when
not nil; returns  else.
local function substitute (message, data_t)
	return data_t and mw.message.newRawMessage (message, data_t):plain() or message;
end
------------------------------------------------------------------------------
Assembles an error message from module name, message text, help link, and error category.
local function make_error_msg (frame, msg)
	local module_name = frame:getTitle();										-- get the module name for prefix and help-link label
	local namespace = mw.title.getCurrentTitle().namespace;						-- used for categorization
	local category_link = (0 == namespace) and substitute (, {cfg.settings_t.err_category}) or ;
	return substitute ('Error: : $3 ($5)$6',
		{
		module_name,															-- the module name with namespace
		module_name:gsub ('Module:', ),										-- the module name without namespace
		msg,																	-- the error message
		cfg.settings_t.help_text_link,											-- help wikilink to text at help page
		cfg.settings_t.help,													-- help wikilink display text
		category_link															-- link to error category (for main namespace errors only)
		})
end
	
-------------------------------------------------------------------------------------------------
Function to call Module:Citation/CS1/sandbox with appropriate parameters.  For use when an article exceeds the
post-expand include size limit.
	title=Title
local function cite (frame, template)
	local args_t = require ('Module:Arguments').getArgs (frame, {frameOnly=true});
	template = template:lower();												-- lowercase for table indexes
	
	if not cfg.known_templates_ttemplate then									-- do we recognize this template name?
		return make_error_msg (frame, substitute (cfg.settings_t.unknown_name, {template}));	-- nope; abandon with error message
	end
	local config_t = {'CitationClass' = cfg.citation_classes_ttemplate or template};	-- set CitationClass value
	
	local subpage = '/CS1'														--日本語版独自: CS-jaを分岐
	if args_t1 == '和書' then subpage = '/CS-ja' end
	if args_t.language then
		if args_t.language:lower() == 'ja' then subpage = '/CS-ja' end
		if args_t.language:lower() == 'ja-jp' then subpage = '/CS-ja' end
		if args_t.language:lower() == 'japanese' then subpage = '/CS-ja' end
		if args_t.language:lower() == '日本語' then subpage = '/CS-ja' end
	end
	
	return require ('Module:Citation' .. subpage .. sandbox)._citation (nil, args_t, config_t);	-- go render the citation
end
-------------------------------------------------------------------------------------------
return setmetatable({}, {__index =												-- returns an empty TABLE whose metatable has the __index set so that, for any given KEY, it returns
	function(_, template)														-- this anonymous function called as function(TABLE, KEY)
		return function (frame) return cite (frame, template) end;				-- which in turn returns a function that calls cite() with the KEY name
	end
})