From 14866d1e420df0f8a0967f259461cf09afd1b81b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20Ho=CC=88rrmann?= Date: Mon, 17 Jan 2022 19:41:13 +0100 Subject: [PATCH] Add missing locale setting to dateRelative()` Fixes #2 --- index.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/index.php b/index.php index e89f7b9..ca8075e 100755 --- a/index.php +++ b/index.php @@ -119,7 +119,15 @@ ); }, 'toRelative' => function ($field, $from = 'now') { - return dateRelative($field->value(), $from); + if (kirby()->language()) { + $locale = kirby() + ->language() + ->locale(); + } else { + $locale = option('locale'); + } + + return dateRelative($field->value(), $from, $locale); }, 'toTime' => function ($field, $format = 'H:i') { return $field->toDateTime()->format($format); @@ -269,7 +277,7 @@ function datetime($datetime = 'now') return new DateTime($datetime); } -function dateRelative($to, $from = 'now') +function dateRelative($to, $from = 'now', $locale = null) { $from = datetime($from); $to = datetime($to); @@ -306,9 +314,14 @@ function dateRelative($to, $from = 'now') $direction = ''; } - return tt('hananils.date-methods.' . $id . $direction, [ - 'count' => $count - ]); + return tt( + 'hananils.date-methods.' . $id . $direction, + null, + [ + 'count' => $count + ], + $locale + ); } function dateFormatted(