モジュール:Citation/Show date/Configuration

local lang_obj = mw.language.getContentLanguage();								-- make a language object for the local language; used here for languages and dates 
------------------------------------------------------------------------------------------
boolean settings used to control various things.  these setting located here to make them easy to find
																				-- these settings local to this module only
local local_digits_from_mediawiki = false;										-- for i18n; when true, module fills date_names'local_digits' from MediaWiki; manual fill required else; always false at en.wiki
local local_date_names_from_mediawiki = false;									-- for i18n; when true, module fills date_names'locallong' and date_names'localshort' from MediaWiki;
																				-- manual translation required else; ; always false at en.wiki
																				-- these settings exported to other modules
local date_name_auto_xlate_enable = false;										-- when true translates English month-names to the local-wiki's language month names; always false at en.wiki
local date_digit_auto_xlate_enable = false;										-- when true translates Western date digit to the local-wiki's language digits (date_names'local_digits'); always false at en.wiki
------------------------------------------------------------------------------------------
Translation table
The following contains fixed text that may be output as part of a citation.
This is separated from the main body to aid in future translations of this
module.
local messages = {
	'mismatch' = 
	}
--------------------------------------------------------------------------------------
This table of tables lists local language date names and fallback English date names.
The code in Date_validation will look first in the local table for valid date names.
If date names are not found in the local table, the code will look in the English table.
Because citations can be copied to the local wiki from en.wiki, the English is
required when the date-name translation function date_name_xlate() is used.
In these tables, season numbering is defined by
Extended Date/Time Format (EDTF) Specification (https://www.loc.gov/standards/datetime/)
which became part of ISO 8601 in 2019.  See '§Sub-year groupings'. The standard
defines various divisions using numbers 21-41. CS1|2 only supports generic seasons.
EDTF does support the distinction between north and south hemisphere seasons
but CS1|2 has no way to make that distinction.
33-36 = Quarter 1, Quarter 2, Quarter 3, Quarter 4 (3 months each)
The standard does not address 'named' dates so, for the purposes of CS1|2,
Easter and Christmas are defined here as 98 and 99, which should be out of the
ISO 8601 (EDTF) range of uses for a while.
local_date_names_from_mediawiki is a boolean.  When set to:
	true – module will fetch local month names from MediaWiki for both date_names'locallong' and date_names'localshort'; this will unconditionally overwrite manual translations
	false – module will *not* fetch local month names from MediaWiki
Caveat lector:  There is no guarantee that MediaWiki will provide short month names.  At your wiki you can test
the results of the MediaWiki fetch in the debug console with this command (the result is alpha sorted):
	=mw.dumpObject (p.date_names'local')
While the module can fetch month names from MediaWiki, it cannot fetch the quarter, season, and named date names
from MediaWiki.  Those must be translated manually.
local local_date_names_from_mediawiki = false;									-- when false, manual translation required for date_names'locallong' and date_names'localshort'; overwrites manual translations
																				-- when true, module fetches long and short month names from MediaWiki
local date_names = {
	'en' = {																	-- English
		'long'	= {'January' = 1, 'February' = 2, 'March' = 3, 'April' = 4, 'May' = 5, 'June' = 6, 'July' = 7, 'August' = 8, 'September' = 9, 'October' = 10, 'November' = 11, 'December' = 12},
		'short'	= {'Jan' = 1, 'Feb' = 2, 'Mar' = 3, 'Apr' = 4, 'May' = 5, 'Jun' = 6, 'Jul' = 7, 'Aug' = 8, 'Sep' = 9, 'Oct' = 10, 'Nov' = 11, 'Dec' = 12},
		'quarter' = {'First Quarter' = 33, 'Second Quarter' = 34, 'Third Quarter' = 35, 'Fourth Quarter' = 36},
		'season'	= {'Winter' = 24, 'Spring' = 21, 'Summer' = 22, 'Fall' = 23, 'Autumn' = 23},
		'named'	= {'Easter' = 98, 'Christmas' = 99},
		},
																				-- when local_date_names_from_mediawiki = false
	'local' = {																-- replace these English date names with the local language equivalents
		'long'	= {'1月' = 1, '2月' = 2, '3月' = 3, '4月' = 4, '5月' = 5, '6月' = 6, '7月' = 7, '8月' = 8, '9月' = 9, '10月' = 10, '11月' = 11, '12月' = 12},
		'short'	= {'1月' = 1, '2月' = 2, '3月' = 3, '4月' = 4, '5月' = 5, '6月' = 6, '7月' = 7, '8月' = 8, '9月' = 9, '10月' = 10, '11月' = 11, '12月' = 12},
		'quarter' = {'第1四半期' = 33, '第2四半期' = 34, '第3四半期' = 35, '第4四半期' = 36},
		'season'	= {'冬' = 24, '春' = 21, '夏' = 22, '秋' = 23},
		'named'	= {'イースター' = 98, 'クリスマス' = 99},
		},
	'inv_en_long' = {},														-- used in date reformatting; copy of date_names'en'.long where k/v are inverted: 1= etc.
	'inv_en_short' = {},														-- used in date reformatting; copy of date_names'en'.short where k/v are inverted: 1= etc.
	'inv_local_long' = {},													-- used in date reformatting & translation; copy of date_names'local'.long where k/v are inverted: 1= etc.
	'inv_local_short' = {},													-- used in date reformatting & translation; copy of date_names'local'.short where k/v are inverted: 1= etc.
	'inv_local_quarter' = {},													-- used in date translation; copy of date_names'local'.quarter where k/v are inverted: 1= etc.
	'inv_local_season' = {},													-- used in date translation; copy of date_names'local'.season where k/v are inverted: 1= etc.
	'inv_local_named' = {},													-- used in date translation; copy of date_names'local'.named where k/v are inverted: 1= etc.
	'local_digits' = {'0' = '0', '1' = '1', '2' = '2', '3' = '3', '4' = '4', '5' = '5', '6' = '6', '7' = '7', '8' = '8', '9' = '9'},	-- used to convert local language digits to Western 0-9
	'xlate_digits' = {},
	}
if local_date_names_from_mediawiki then											-- if fetching local month names from MediaWiki is enabled
	local long_t = {};
	local short_t = {};
	for i=1, 12 do																-- loop 12x and 
		local name = lang_obj:formatDate('F', '2022-' .. i .. '-1');			-- get long month name for each i
		long_tname = i;														-- save it
		name = lang_obj:formatDate('M', '2022-' .. i .. '-1');					-- get short month name for each i
		short_tname = i;														-- save it
	end
	date_names'locallong' = long_t;										-- write the long table – overwrites manual translation
	date_names'localshort' = short_t;										-- write the short table – overwrites manual translation
end
																				-- create inverted date-name tables for reformatting and/or translation
for _, invert_t in pairs  do
	for name, i in pairs (date_names'local'invert_t1) do					-- this table is 'name' = i
		date_namesinvert_t2i = name;										-- invert to get i = 'name' for conversions from ymd
	end
end
for _, invert_t in pairs  do
	for name, i in pairs (date_names'en'invert_t1) do						-- this table is 'name' = i
		date_namesinvert_t2i = name;										-- invert to get i = 'name' for conversions from ymd
	end
end
if local_digits_from_mediawiki then												-- if fetching local digits from MediaWiki is enabled
	local digits_t = {};
	for i=0, 9 do																-- loop 10x and 
		digits_t lang_obj:formatNum (i) = tostring (i);						-- format the loop indexer as local lang table index and assign loop indexer (a string) as the value
	end
	date_names'local_digits' = digits_t;
end
for ld, ed in pairs (date_names.local_digits) do								-- make a digit translation table for simple date translation from en to local language using local_digits table
	date_names.xlate_digits ed = ld;											-- en digit becomes index with local digit as the value
end
-- 英語版の  や  に関連する処理は移入しない
-------------------------------------------------------------
return 	{
	date_name_auto_xlate_enable = date_name_auto_xlate_enable,
	date_digit_auto_xlate_enable = date_digit_auto_xlate_enable,
	date_names = date_names,
	messages = messages
	}