Module:DateI18n/doc
This is a documentation subpage for Module:DateI18n. It contains usage information, categories and other content that is not part of the original Module page. |
Summary
editThis module is intended for creating of date strings in any language. It serves as a back-end of Date template on Wikimedia Commons and it is being used by several other modules like Module:ISOdate or Module:Complex date.
Using this module from templates
editDate
editThis module should only be called from {{Date }} template. Please call that template to access this module. Also see {{Date }} template for full documentation
Usage:
{{#invoke:DateI18n|Date|year=...|month=...|day=...|hour=...|minute=...|second=...|tzhour=...|tzmin=...|lang=...}}
Parameters:
- year, month, day, hour, minute, second
- (most are optional) parameters specifying part of the date
- tzhour, tzmin
- (optional and rarely used) time zone offset from UTC
- lang
- (optional) language to be used to display the date. If not specified language of the user will be used
- class
- (optional) Allows setting of the HTML class of the time node where the date is included. This is useful for microformats. The default value is, for legacy reasons, "dtstart" (used by hCalendar). See the microformats project. "class=" will remove all metadata.
- case
- (optional) By default each language uses preferred form of the date, which typically has month in nominative or genitive grammatical case. With case parameter one can overwrite the preferred case with some other one used by a given language. Parser function {{#time}} stores nominative and genitive forms, others are stored in Data:I18n/MonthCases.tab. This functionality is mostly used by Module:Complex date.
- trim_year
- trim_year parameter
Example:
{{#invoke:DateI18n|Date|year=1990|month=Oct|day=01|lang=en}}
produces
Using this module from Lua code
editIn order to use the functions in this module from another Lua module you first have to import this module.
Example:
local DateMod = require('Module:DateI18n')
_Date
editUsage:
date_string = DateMod._Date({year,month,day,hour,minute, second},lang)
I18n tables
editThis module stores all the language specific settings in two files in "Data" namespace: Data:DateI18n.tab and Data:I18n/MonthCases.tab
Translation table with different forms of dates. Outputs are in the format used by {{#time}} parser function. There are several date formats supported, which depend on the data provided
Date formats Format string Meaning Comments YMDHMS YYYY:MM:DD, HH:MM:SS format for year, month, day, hour, minutes, seconds Most items in the list use format created from YMD format with hour, minutes and seconds added with ", HH:MM:SS". All languages using this format do not have to be listed, as they default to English. YMDHM YYYY:MM:DD, HH:MM format for year, month, day, hour, minutest Most items in the list use format created from YMD format with hour and minutes added with ", HH:MM". All languages using this format do not have to be listed, as they default to English. YMD YYYY:MM:DD format for year, month, day The languages using the same format as English do not need to be listed. YM YYYY:MM (year-month) format for year and month The languages using the same format as English do not need to be listed. MD MM:DD (month-day) format for month and day The languages using the same format as English do not need to be listed. Y YYYY (year only) format for year Most languages show year as a simple number, those do not have to be listed as they will default to English. M month name only Most languages show year as a simple number, those do not have to be listed as they will default to English.
- Special cases
Some languages like French Catalan, Gallic or Basque use different form for year-month-day dates depending on the day of the month. the format of the Tabular Data allowed only simple strings to be stored in multi-language arrays. In order to overcome that we stored data in strings that might look like "{”default”:”j F Y”,”d01”:”j'<sup>er</sup>' F Y”}"
. This string is converted to following json code by replacing ”-double-quotes with regular straight double-quotes
{
"default": "j F Y",
"d01": ”j'<sup>er</sup>' F Y"
}
than parsed and converted into Lua dictionary table. We convert day from the date into a key by adding "d" to a 2-digit integer representing day. If that key is in the dictionary than that form will be used otherwise we will use default form. The final step before passing it to {{#time}} parser function we will replace single quotes with double quotes which have special meaning for that function.
Grammatical cases of month names in different languages used by Module:DateI18n and Module:Complex date.