Changes
Jump to navigation
Jump to search
m
Deprecating <source> tag: phab:T237267
<includeonly>{{Shared Template Warning|Module:DateI18n}}</includeonly>
== Summary ==
This module is intended for creating of date strings in any language. It serves as a back-end of [[c:template:Date|Date]] template on Wikimedia Commons and it is being used by several other modules like [[d:Q20962109|Module:ISOdate]] or [[d:Q26905045|Module:Complex date]].
== Using this module from templates ==
=== Date ===
This module should only be called from {{tl|Date}} template. Please call that template to access this module. Also see {{tl|Date}} template for full documentation
Usage:
: <code><nowiki>{{#invoke:</nowiki>DateI18n|Date|year=...|month=...|day=...|hour=...|minute=...|second=...|tzhour=...|tzmin=...|lang=...}}</code>
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 [[w:HCalendar|hCalendar]]). See [[c:Commons:Microformats Project|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 [[:en:Nominative case|nominative]] or [[:en:Genitive case|genitive]] [[:en:Grammatical case|grammatical case]]. With ''case'' parameter one can overwrite the preferred case with some other one used by a given language. Parser function {{#time}} stores [[:en:Nominative case|nominative]] and [[:en:Genitive case|genitive]] forms, others are stored in [[c:Data:I18n/MonthCases.tab|Data:I18n/MonthCases.tab]]. This functionality is mostly used by [[d:Q26905045|Module:Complex date]].
;trim_year
:''trim_year'' parameter
Example:
: <code><nowiki>{{#invoke:DateI18n|Date|year=1990|month=Oct|day=01|lang=en}}</nowiki></code> produces {{#invoke:DateI18n|Date|year=1990|month=Oct|day=01|lang=en}}
== Using this module from Lua code ==
In order to use the functions in this module from another Lua module you first have to import this module.
Example:
: <code>local DateMod = require('Module:DateI18n')</code>
=== _Date ===
Usage:
: <code>date_string = DateMod._Date({year,month,day,hour,minute, second},lang)</code>
== I18n tables ==
This module stores all the language specific settings in two files in "[[mw:Help:Tabular Data|Data]]" namespace: [[c:Data:DateI18n.tab|Data:DateI18n.tab]] and [[c:Data:I18n/MonthCases.tab|Data:I18n/MonthCases.tab]]
=== [[c:Data:DateI18n.tab|Data:DateI18n.tab]] ===
Translation table with different forms of dates. Outputs are in the format used by [[mw:Help:Extension:ParserFunctions##time|{{#time}} parser function]]. There are several date formats supported, which depend on the data provided
:{| class="wikitable"
|+ 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 [[mw:Help:Tabular Data|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 <code><nowiki>"{”default”:”j F Y”,”d01”:”j'<sup>er</sup>' F Y”}"</nowiki></code>. This string is converted to following json code by replacing ”-double-quotes with regular straight double-quotes
<syntaxhighlight lang=json>
{
"default": "j F Y",
"d01": ”j'<sup>er</sup>' F Y"
}
</syntaxhighlight>
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 [[mw:Help:Extension:ParserFunctions##time|{{#time}} parser function]] we will replace single quotes with double quotes which have special meaning for that function.
===[[c:Data:I18n/MonthCases.tab|Data:I18n/MonthCases.tab]] ===
[[:en:Grammatical case|Grammatical case]]s of month names in different languages used by [[Module:DateI18n]] and [[d:Q26905045|Module:Complex date]].
== Summary ==
This module is intended for creating of date strings in any language. It serves as a back-end of [[c:template:Date|Date]] template on Wikimedia Commons and it is being used by several other modules like [[d:Q20962109|Module:ISOdate]] or [[d:Q26905045|Module:Complex date]].
== Using this module from templates ==
=== Date ===
This module should only be called from {{tl|Date}} template. Please call that template to access this module. Also see {{tl|Date}} template for full documentation
Usage:
: <code><nowiki>{{#invoke:</nowiki>DateI18n|Date|year=...|month=...|day=...|hour=...|minute=...|second=...|tzhour=...|tzmin=...|lang=...}}</code>
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 [[w:HCalendar|hCalendar]]). See [[c:Commons:Microformats Project|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 [[:en:Nominative case|nominative]] or [[:en:Genitive case|genitive]] [[:en:Grammatical case|grammatical case]]. With ''case'' parameter one can overwrite the preferred case with some other one used by a given language. Parser function {{#time}} stores [[:en:Nominative case|nominative]] and [[:en:Genitive case|genitive]] forms, others are stored in [[c:Data:I18n/MonthCases.tab|Data:I18n/MonthCases.tab]]. This functionality is mostly used by [[d:Q26905045|Module:Complex date]].
;trim_year
:''trim_year'' parameter
Example:
: <code><nowiki>{{#invoke:DateI18n|Date|year=1990|month=Oct|day=01|lang=en}}</nowiki></code> produces {{#invoke:DateI18n|Date|year=1990|month=Oct|day=01|lang=en}}
== Using this module from Lua code ==
In order to use the functions in this module from another Lua module you first have to import this module.
Example:
: <code>local DateMod = require('Module:DateI18n')</code>
=== _Date ===
Usage:
: <code>date_string = DateMod._Date({year,month,day,hour,minute, second},lang)</code>
== I18n tables ==
This module stores all the language specific settings in two files in "[[mw:Help:Tabular Data|Data]]" namespace: [[c:Data:DateI18n.tab|Data:DateI18n.tab]] and [[c:Data:I18n/MonthCases.tab|Data:I18n/MonthCases.tab]]
=== [[c:Data:DateI18n.tab|Data:DateI18n.tab]] ===
Translation table with different forms of dates. Outputs are in the format used by [[mw:Help:Extension:ParserFunctions##time|{{#time}} parser function]]. There are several date formats supported, which depend on the data provided
:{| class="wikitable"
|+ 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 [[mw:Help:Tabular Data|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 <code><nowiki>"{”default”:”j F Y”,”d01”:”j'<sup>er</sup>' F Y”}"</nowiki></code>. This string is converted to following json code by replacing ”-double-quotes with regular straight double-quotes
<syntaxhighlight lang=json>
{
"default": "j F Y",
"d01": ”j'<sup>er</sup>' F Y"
}
</syntaxhighlight>
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 [[mw:Help:Extension:ParserFunctions##time|{{#time}} parser function]] we will replace single quotes with double quotes which have special meaning for that function.
===[[c:Data:I18n/MonthCases.tab|Data:I18n/MonthCases.tab]] ===
[[:en:Grammatical case|Grammatical case]]s of month names in different languages used by [[Module:DateI18n]] and [[d:Q26905045|Module:Complex date]].