Module:LatestUpdate: Difference between revisionsGive feedback
Added Plural rules for different languages |
Gammaton32 (talk | contribs) added days_since_date to calculate time since any given date |
||
| (One intermediate revision by one other user not shown) | |||
| Line 177: | Line 177: | ||
-- [1] = "há %d dia", | -- [1] = "há %d dia", | ||
-- [2] = "há %d dias" | -- [2] = "há %d dias" | ||
-- } | |||
} | |||
-- Special-case wording for 0 and 1 days, keyed by day count. | |||
-- A language missing an entry here falls back to the plural forms above. | |||
local relative_days = { | |||
en = { | |||
[0] = "today", | |||
[1] = "yesterday" | |||
}, | |||
es = { | |||
[0] = "hoy", | |||
[1] = "ayer" | |||
}, | |||
fr = { | |||
[0] = "aujourd'hui", | |||
[1] = "hier" | |||
}, | |||
ko = { | |||
[0] = "오늘", | |||
[1] = "어제" | |||
}, | |||
ru = { | |||
[0] = "сегодня", | |||
[1] = "вчера" | |||
}, | |||
tr = { | |||
[0] = "bugün", | |||
[1] = "dün" | |||
}, | |||
cs = { | |||
[0] = "dnes", | |||
[1] = "včera" | |||
}, | |||
["zh-hans"] = { | |||
[0] = "今天", | |||
[1] = "昨天" | |||
}, | |||
["zh-hant"] = { | |||
[0] = "今天", | |||
[1] = "昨天" | |||
}, | |||
-- uncomment when needed | |||
-- pl = { | |||
-- [0] = "dzisiaj", | |||
-- [1] = "wczoraj" | |||
-- }, | |||
-- uk = { | |||
-- [0] = "сьогодні", | |||
-- [1] = "вчора" | |||
-- }, | |||
-- de = { | |||
-- [0] = "heute", | |||
-- [1] = "gestern" | |||
-- }, | |||
-- it = { | |||
-- [0] = "oggi", | |||
-- [1] = "ieri" | |||
-- }, | |||
-- pt = { | |||
-- [0] = "hoje", | |||
-- [1] = "ontem" | |||
-- } | -- } | ||
} | } | ||
| Line 207: | Line 284: | ||
month = month_number, | month = month_number, | ||
day = tonumber(update.day), | day = tonumber(update.day), | ||
hour = 0 | |||
}) | |||
local now = os.time() | |||
local diff_seconds = os.difftime(now, update_time) | |||
local days = math.floor(diff_seconds / 86400) | |||
if days < 0 then | |||
return 0 | |||
end | |||
return days | |||
end | |||
p.days_since_date = function(frame) | |||
local update_time = os.time({ | |||
year = frame.args[3], | |||
month = frame.args[1], | |||
day = frame.args[2], | |||
hour = 0 | hour = 0 | ||
}) | }) | ||
| Line 240: | Line 338: | ||
local days = p.days_since() | local days = p.days_since() | ||
local relative = relative_days[lang] | |||
if relative and relative[days] then | |||
return relative[days] | |||
end | |||
local plural_rule = plural_rules[lang] or plural_rules.en | local plural_rule = plural_rules[lang] or plural_rules.en | ||