https://de.wikipedia.org/w/index.php?action=history&feed=atom&title=Modul%3ADateI18n Modul:DateI18n - Versionsgeschichte 2025-05-26T00:20:27Z Versionsgeschichte dieser Seite in Wikipedia MediaWiki 1.45.0-wmf.2 https://de.wikipedia.org/w/index.php?title=Modul:DateI18n&diff=195600600&oldid=prev Ederporto: Modul: WikidataIB hat dieses Modul als Abhängigkeit, daher importiere ich das englische Äquivalent, damit es richtig funktioniert. 2020-01-07T16:56:50Z <p>Modul: WikidataIB hat dieses Modul als Abhängigkeit, daher importiere ich das englische Äquivalent, damit es richtig funktioniert.</p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="de"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Nächstältere Version</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Version vom 7. Januar 2020, 18:56 Uhr</td> </tr><tr> <td colspan="2" class="diff-lineno">Zeile 1:</td> <td colspan="2" class="diff-lineno">Zeile 1:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>--[[ </div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>--[[ </div></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td> <td colspan="2" class="diff-empty diff-side-added"></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This module is intended for processing of date strings.</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>This module is intended for processing of date strings.</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> </table> Ederporto https://de.wikipedia.org/w/index.php?title=Modul:DateI18n&diff=195600587&oldid=prev Ederporto: AZ: Die Seite wurde neu angelegt: --[[ This module is intended for processing of date strings. Copied from https://commons.wikimedi… 2020-01-07T16:56:25Z <p><a href="/wiki/Hilfe:Zusammenfassung_und_Quellen#Auto-Zusammenfassung" title="Hilfe:Zusammenfassung und Quellen">AZ</a>: Die Seite wurde neu angelegt: --[[ This module is intended for processing of date strings. Copied from https://commons.wikimedi…</p> <p><b>Neue Seite</b></p><div>--[[ <br /> <br /> This module is intended for processing of date strings.<br /> <br /> Copied from https://commons.wikimedia.org/w/index.php?title=Module:Date&amp;oldid=224728211<br /> Used by Module:ISOdate, Module:Complex date, Module:WikidataIB<br /> <br /> Authors and maintainers:<br /> * User:Parent5446 - original version of the function mimicking template:ISOdate<br /> * User:Jarekt - original version of the functions mimicking template:Date and template:ISOyear<br /> <br /> ]]<br /> <br /> <br /> local p = {}<br /> <br /> -- =======================================<br /> -- === Dependencies ======================<br /> -- =======================================<br /> local i18n = require(&#039;Module:I18n/date&#039;) -- get localized translations of date formats<br /> local yesno = require(&#039;Module:Yesno&#039;)<br /> <br /> local function langSwitch(list,lang)<br /> local langList = mw.language.getFallbacksFor(lang)<br /> table.insert(langList,1,lang)<br /> for i,language in ipairs(langList) do<br /> if list[language] then<br /> return list[language]<br /> end<br /> end<br /> end<br /> <br /> --[[<br /> Date<br /> <br /> This function can be used to provide an ISOdate template. <br /> <br /> Usage:<br /> {{#invoke:Date|Date|year=|month=|day=|hour=|minute=|second=|tzhour=|tzmin=|lang=en}}<br /> <br /> Parameters:<br /> year,month,day,hour,minute,second: broken down date-time component strings<br /> tzhour, tzmin: timezone offset from UTC, hours and minutes<br /> lang: The language to display it in<br /> case: Language format (genitive, etc.) for some languages<br /> class: CSS class for the &lt;time&gt; node, use &quot;&quot; for no metadata at all<br /> <br /> Error Handling:<br /> <br /> ]]<br /> function p.Date(frame)<br /> local args = frame.args<br /> if not (args.lang and mw.language.isSupportedLanguage(args.lang)) then <br /> args.lang = frame:callParserFunction( &quot;int&quot;, &quot;lang&quot; ) -- get user&#039;s chosen language <br /> end<br /> return p._Date( <br /> { <br /> args.year or &#039;&#039;, <br /> args.month or &#039;&#039;,<br /> args.day or &#039;&#039;, <br /> args.hour or &#039;&#039;, <br /> args.minute or &#039;&#039;, <br /> args.second or &#039;&#039;,<br /> args.tzhour or &#039;&#039;,<br /> args.tzmin or &#039;&#039;<br /> },<br /> args.lang, -- language<br /> args.case or &#039;&#039;, -- allows to specify grammatical case for the month for languages that use them<br /> args.class or &#039;dtstart&#039;, -- allows to set the html class of the time node where the date is included. This is useful for microformats.<br /> args.trim_year or &#039;100-999&#039; -- by default pad one and 2 digit years to be 4 digit long, while keeping 3 digit years as is<br /> ) <br /> end<br /> <br /> <br /> function p._Date(datevec, lang, case, class, trim_year) <br /> -- make sure inputs are in the right format<br /> for i = #datevec + 1, 8 do<br /> datevec[i] = &#039;&#039;<br /> end<br /> if not case then case = &#039;&#039; end<br /> if not class then class = &#039;&#039; end<br /> if not trim_year then trim_year = &#039;100-999&#039; end<br /> <br /> -- if language is not provided than look up users language<br /> -- WARNING: This step should be done by the template as it does not seem to work as well here (cache issues?)<br /> if not lang or not mw.language.isValidCode( lang ) then<br /> lang = &#039;en&#039;<br /> end<br /> <br /> -- Just in case someone broke the internationalization code than fix the english defaults<br /> if i18n.DateLang[&#039;en&#039;] == nil then<br /> i18n.DateLang[&#039;en&#039;] = &#039;en-form&#039;<br /> end <br /> if i18n.DateFormat[&#039;en-form&#039;] == nil then<br /> i18n.DateFormat[&#039;en-form&#039;] = {YMDHMS=&#039;j F Y, H:i:s&#039;, YMDHM=&#039;j F Y, H:i&#039;, YMD=&#039;j F Y&#039;, YM=&#039;F Y&#039;, MD=&#039;j F&#039;, Y=&#039;Y&#039;}<br /> end<br /> <br /> -- create datecode based on which variables are provided and check for out of bound values<br /> local maxval = {9999, 12, 31, 23, 59, 60, 23, 59} -- max values for year, month, ...<br /> local c = {&#039;Y&#039;, &#039;M&#039;, &#039;D&#039;, &#039;H&#039;, &#039;M&#039;, &#039;S&#039;, &#039;&#039;, &#039;&#039;}<br /> local datecode = &#039;&#039; -- a string signifying which combination of variables was provided<br /> local datenum = {} -- date-time encoded as a vector = [year, month, ... , second]<br /> for i, v in ipairs( datevec ) do<br /> if v~=nil and v~=&#039;&#039; then<br /> datecode = datecode .. c[i]<br /> datenum[i] = tonumber(v)<br /> if datenum[i]==nil and i==2 then<br /> -- month is not a number -&gt; check if it is a month name in English<br /> v = mw.language.new(&#039;en&#039;):formatDate( &quot;n&quot;, v)<br /> datenum[i] = tonumber(v)<br /> end<br /> if datenum[i]==nil or datenum[i]&gt;maxval[i] then<br /> -- Some numbers are out of range -&gt; abort and return the empty string<br /> return &#039;&#039;<br /> end<br /> end<br /> end<br /> <br /> -- create time stamp string (for example 2000-02-20 02:20:20) based on which variables were provided<br /> local timeStamp<br /> if datecode == &#039;YMDHMS&#039; then<br /> timeStamp = string.format(&#039;%04i-%02i-%02i %02i:%02i:%02i&#039;, datenum[1], datenum[2], datenum[3], datenum[4], datenum[5], datenum[6] )<br /> elseif datecode == &#039;YMDHM&#039; then<br /> timeStamp = string.format(&#039;%04i-%02i-%02i %02i:%02i&#039;, datenum[1], datenum[2], datenum[3], datenum[4], datenum[5] )<br /> elseif datecode:sub(1,3)==&#039;YMD&#039; then<br /> timeStamp = string.format(&#039;%04i-%02i-%02i&#039;, datenum[1], datenum[2], datenum[3] )<br /> datecode = &#039;YMD&#039; -- &#039;YMD&#039;, &#039;YMDHMS&#039; and &#039;YMDHM&#039; are the only supported format starting with &#039;YMD&#039;. All others will be converted to &#039;YMD&#039;<br /> elseif datecode == &#039;YM&#039; then<br /> timeStamp = string.format(&#039;%04i-%02i&#039;, datenum[1], datenum[2] )<br /> elseif datecode:sub(1,1)==&#039;Y&#039; then<br /> timeStamp = string.format(&#039;%04i&#039;, datenum[1] )<br /> datecode = &#039;Y&#039; <br /> elseif datecode == &#039;M&#039; then<br /> timeStamp = string.format(&#039;%04i-%02i-%02i&#039;, 2000, datenum[2], 1 )<br /> class = &#039;&#039; -- date not complete -&gt; no html formating or micro-tagging of date string<br /> elseif datecode == &#039;MD&#039; then<br /> timeStamp = string.format(&#039;%04i-%02i-%02i&#039;, 2000, datenum[2], datenum[3] )<br /> class = &#039;&#039; -- date not complete -&gt; no html formating or micro-tagging of date string<br /> else<br /> return &#039;&#039; -- format not supported<br /> end<br /> <br /> -- ==========================================================<br /> -- === Create Date String using in chosen language<br /> -- ==========================================================<br /> <br /> -- which form should the date take? <br /> -- Use langSwitch to pick formating for each language<br /> local langDateForm = langSwitch(i18n.DateLang, lang)<br /> <br /> -- special case of French and Gallic dates, which require different date format for the 1st day of the month<br /> if datenum[3]==1 and (langDateForm==&#039;fr-form&#039; or langDateForm==&#039;ga-form&#039;) then<br /> langDateForm = langDateForm .. &#039;1&#039; -- ordinal form for the first day of the month<br /> end<br /> -- special case of Basque dates, which require different date format for the 1st, 11th, 21st and 31st day of the month<br /> if langDateForm==&#039;eu-form&#039; then<br /> if (datenum[3]==1 or datenum[3]==21) then<br /> langDateForm = &#039;eu-form01&#039;<br /> elseif (datenum[3]==11 or datenum[3]==31) then<br /> langDateForm = &#039;eu-form11&#039;<br /> end<br /> end<br /> <br /> -- Look up country specific format input to {{#time}} function<br /> local dFormat = i18n.DateFormat[langDateForm][datecode]<br /> <br /> -- overwrite default grammatical case of the month (applies mostly to Slavic languages)<br /> if (case==&#039;gen&#039;) then<br /> -- CAUTION: at the moment i18n.DateFormat uses &quot;F&quot; only as month name, but this might change and this operation does not check if &#039;F&#039; is in &quot;&quot; brackets or not, so if some language starts using &#039;F&#039; in &quot;&quot; than this will not work for that language<br /> dFormat = dFormat:gsub(&quot;F&quot;, &quot;xg&quot;); <br /> end<br /> if (case==&#039;nom&#039;) then<br /> -- CAUTION: at the moment i18n.DateFormat uses &quot;xg&quot; only as month name, but this might change and this operation does not check if &#039;xg&#039; is in &quot;&quot; brackets or not, so if some language starts using &#039;xg&#039; in &quot;&quot; than this will not work for that language<br /> dFormat = dFormat:gsub(&quot;xg&quot;, &quot;F&quot;);<br /> end<br /> if ((lang==&#039;ru&#039; or lang==&#039;pl&#039; or lang==&#039;cs&#039; or lang==&#039;sl&#039; or lang==&#039;sk&#039;) and (case==&#039;loc&#039; or case==&#039;ins&#039;)) or<br /> (lang==&#039;fi&#039; and (case==&#039;ptv&#039; or case==&#039;ine&#039;or case==&#039;ela&#039;or case==&#039;ill&#039;) ) then<br /> local monthEn = mw.language.new(&#039;en&#039;):formatDate( &quot;F&quot;, timeStamp) -- month name in English<br /> -- month name using proper case and language. It relies on messages stored in MediaWiki namespace for some cases and languages<br /> -- That is why this IF statement uses &quot;lang&quot; not &quot;langDateForm&quot; variable to decide<br /> local monthMsg = mw.message.new( string.format(&#039;%s-%s&#039;, monthEn, case ) ):inLanguage( lang )<br /> if not monthMsg:isDisabled() then -- make sure it exists<br /> local month=monthMsg:plain()<br /> dFormat = dFormat:gsub(&#039;F&#039;, &#039;&quot;&#039;..month..&#039;&quot;&#039;); -- replace default month with month name we already looked up<br /> dFormat = dFormat:gsub(&#039;xg&#039;, &#039;&quot;&#039;..month..&#039;&quot;&#039;);<br /> end<br /> end<br /> -- Special case related to Quechua and Kichwa languages<br /> -- see https://commons.wikimedia.org/wiki/Template_talk:Date#Quechua from 2014<br /> if (lang==&#039;qu&#039; or lang==&#039;qug&#039;) and case==&#039;nom&#039; then<br /> dFormat = dFormat:gsub(&#039;F&quot;pi&quot;&#039;, &#039;F&#039;);<br /> end <br /> <br /> -- Lua only date formating using {{#time}} parser function (new)<br /> -- prefered call which gives &quot;Lua error: too many language codes requested.&quot; on the [[Module talk:Date/sandbox/testcases]] page<br /> --local datestr = mw.language.new(lang):formatDate( dFormat, timeStamp) <br /> local datestr = mw.getCurrentFrame():callParserFunction( &quot;#time&quot;, { dFormat, timeStamp, lang } )<br /> <br /> -- Another special case related to Thai solar calendar<br /> if lang==&#039;th&#039; and datenum[1]~= nil and datenum[1]&lt;=1940 then<br /> -- As of 2014 {{#time}} parser function did not resolve those cases properly<br /> -- See https://en.wikipedia.org/wiki/Thai_solar_calendar#New_year for reference<br /> -- Disable once https://bugzilla.wikimedia.org/show_bug.cgi?id=66648 is fixed<br /> if datecode==&#039;Y&#039; then -- date is ambiguous<br /> datestr = string.format(&#039;%04i หรือ %04i&#039;, datenum[1]+542, datenum[1]+543 ) <br /> elseif datenum[2]&lt;=3 then -- year is wrong (one too many)<br /> datestr = datestr:gsub( string.format(&#039;%04i&#039;, datenum[1]+543), string.format(&#039;%04i&#039;, datenum[1]+542 ) )<br /> end<br /> end<br /> <br /> -- If year&lt;1000 than either keep it padded to the length of 4 digits or trim it<br /> -- decide if the year will stay padded with zeros (for years in 0-999 range)<br /> if datenum[1]~= nil and datenum[1]&lt;1000 then<br /> local trim = yesno(trim_year,nil)<br /> if trim == nil then<br /> local YMin, YMax = trim_year:match( &#039;(%d+)-(%d+)&#039; )<br /> trim = (YMin~=nil and datenum[1]&gt;=tonumber(YMin) and datenum[1]&lt;=tonumber(YMax)) <br /> end<br /> <br /> -- If the date form isn&#039;t the Thai solar calendar, don&#039;t zero pad years in the range of 100-999. <br /> -- If at some point support for Islamic/Hebrew/Japanese years is added, they may need to be skipped as well. <br /> if trim then<br /> --local yearStr1 = mw.language.new(lang):formatDate( &#039;Y&#039;, timeStamp)<br /> local yearStr1 = mw.getCurrentFrame():callParserFunction( &quot;#time&quot;, { &#039;Y&#039;, timeStamp, lang } )<br /> --local yearStr1 = datestr:match( &#039;%d%d%d%d&#039; ) -- 4 digits in a row (in any language) - that must be a year<br /> local yearStr2 = yearStr1<br /> local zeroStr = mw.ustring.sub(yearStr1,1,1)<br /> for i=1,3 do -- trim leading zeros<br /> if mw.ustring.sub(yearStr2,1,1)==zeroStr then<br /> yearStr2 = mw.ustring.sub(yearStr2, 2, 5-i)<br /> else<br /> break<br /> end<br /> end<br /> datestr = datestr:gsub( yearStr1, yearStr2 )<br /> --datestr = string.format(&#039;%s (%s, %s)&#039;, datestr, yearStr1, yearStr2 )<br /> end<br /> end<br /> <br /> -- append timezone if present<br /> if datevec[7] ~= &#039;&#039; and (datecode == &#039;YMDHMS&#039; or datecode == &#039;YMDHM&#039;) then<br /> local tzstr, tzhournum = &#039;&#039;, tonumber(datevec[7])<br /> if tzhournum &lt; 0 then tzstr = &#039;−&#039; else tzstr = &#039;+&#039; end<br /> tzstr = tzstr..string.format(&quot;%02d&quot;, math.abs(tzhournum))..&#039;:&#039;<br /> if datevec[8] ~= &#039;&#039; then tzstr = tzstr..datevec[8] else tzstr = tzstr..&#039;00&#039; end<br /> datestr = datestr..&#039; &#039;..tzstr<br /> end<br /> <br /> -- html formating and tagging of date string<br /> if class ~= &#039;&#039; then<br /> local DateHtmlTags = &#039;&lt;span style=&quot;white-space:nowrap&quot;&gt;&lt;time class=&quot;%s&quot; datetime=&quot;%s&quot;&gt;%s&lt;/time&gt;&lt;/span&gt;&#039;<br /> datestr = DateHtmlTags:format(class, timeStamp, datestr)<br /> end<br /> return datestr<br /> end<br /> <br /> return p</div> Ederporto