Jump to content

Module:Month translator/data

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Trappist the monk (talk | contribs) at 16:54, 20 December 2018. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local langs = {'ca', 'de', 'es', 'fi', 'fr', 'it', 'pl', 'pt', 'sv'};

local en_months = {'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'};


--[[--------------------------< P A T T E R N S >--------------------------------------------------------------

table of tables that hold pattern and other information used to extract date parts for translation and reconstrution

Tables have the form:
	[1] - pattern for a particular date format; must include captures for the requiste date components:
			day, month, year which ever are included in the date format
	[2] - a letter 'd', 'm', or 'y' that identified the content of the first (left-most) capture
	[3] - same as [2] for the second capture
	[4] - same as [2] for the last (right-most) capture
	[5] - string identifier that specified the format of the matching date:
			'dmy' - day month year
			'm' - month only (mostly for debug)
			'mdy' - month day, year
			'my' - month year

ymd numeric dates have no hames so are not translated; use |df= parameter in the cs1|2 template for that.

]]

local patterns = {
	{'^(%d%d?) +(%a+) +(%d%d%d%d%a?)$', 'd', 'm', 'y'},							-- dd Mmm yyyy
	{'^(%d%d?) +de +(%a+) +de +(%d%d%d%d%a?)$', 'd', 'm', 'y'},					-- dd de Mmm de yyyy
	{'^(%a+) +(%d%d%d%d%a?)$', 'm', 'y'},										-- Mmm yyyy
	{'^(%a+) +de +(%d%d%d%d%a?)$', 'm', 'y'},									-- Mmm de yyyy
	{'^(%a+) +(%d%d?) *, +(%d%d%d%d%a?)$', 'm', 'd', 'y'},						-- Mmm dd, yyyy
	{'^(%a+)$', 'm'},															-- month only; mostly for debug purposes

--	{'^(%d%d?) +(%a+) +(%d%d%d%d%a?)$', 'd', 'm', 'y', 'dmy'},					-- dd Mmm yyyy
--	{'^(%d%d?) +de +(%a+) +de +(%d%d%d%d%a?)$', 'd', 'm', 'y', 'dmy'},			-- dd de Mmm de yyyy
--	{'^(%a+) +(%d%d%d%d%a?)$', 'm', 'y', nil, 'my'},							-- Mmm yyyy
--	{'^(%a+) +de +(%d%d%d%d%a?)$', 'm', 'y', nil, 'my'},						-- Mmm de yyyy
--	{'^(%a+) +(%d%d?) *, +(%d%d%d%d%a?)$', 'm', 'd', 'y', 'mdy'},				-- Mmm dd, yyyy
--	{'^(%a+)$', 'm', nil, nil, 'm'},											-- month only; mostly for debug purposes
	};


--[[--------------------------< O V E R R I D E _ N A M E S >--------------------------------------------------

table of non-English month names that are valid but are not in the list of names taken from MediaWiki with 
month_names_get().  Items in this list have the form:
	['<non-English month name>'] = 'English month name',
]]

local override_names = {
	[''] = '',
	}

--[[--------------------------< M O N T H _ N A M E S _ G E T >------------------------------------------------

creates a translation table of non-English month names listed in lang{} mapped to English month names listed in
en_months{}.  

]]

local function month_names_get ()
	local month_names = {};

	for _, lang in ipairs (langs) do											-- spin through the languages table
		local lang_obj = mw.getLanguage (lang);									-- make a language object for the current language
		for i, en_month in ipairs (en_months) do								-- spin through the English month-names table
			month_names[lang_obj:formatDate('F', en_month):lower()] = en_month;	-- translate the English name to the current language and store in the translations table
			if 'pl' == lang then												-- for polish and other languages that have nominative and genitive forms
				month_names[lang_obj:formatDate('xg', en_month):lower()] = en_month;	-- translate English to genitive form and save
			end
		end
	end
	return month_names;
end


--[[--------------------------< E X P O R T E D   T A B L E S >------------------------------------------------
]]

return {
	month_names = month_names_get (),
	override_names = override_names,
	patterns = patterns,
	}