Skip to content

Commit

Permalink
Add missing locale setting to dateRelative()`
Browse files Browse the repository at this point in the history
Fixes #2
  • Loading branch information
nilshoerrmann committed Jan 17, 2022
1 parent 73623f8 commit 14866d1
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 14866d1

Please sign in to comment.