Date formatting for panel fields in a multilingual setup

hi there,

iam stuck with date formats in the panel on my multilingual site (en and de)

eg iam using the following to display a modified date for the page

modified:
  type: info
  label:
    en: Last Modification
    de: Letzte Aktualisierung
  theme: positive
  text: "{{ page.modified('Y-MM-dd') }}"
  width: 1/2
  icon: calendar

or the follwoing to show the same in in table layout

type: pages
layout: table
columns:
.....
  modified:
    value: "{{ page.modified('Y-MM-dd') }}"
    width: 1/12
....

this gives me eg 2024-02-09 as expected
but how would i format the date depending on the selected page language?

i tried with intl but its more a translation to locale then a locale formatting

i would expect 2024-02-09 for en and 09.02.2024 for de

edit: correction, date formatting should depend on users selected language not language of the page of course

You can create a page method, e.g.

'modifiedToFormat' => function() {
  $format = kirby()->language()->code() === 'de' ? 'd.m.Y' : 'Y-m-d';
  return $this->modified($format);
}

Then in your blueprint:

fields:
  info:
    type: info
    text: "{{ page.modifiedToFormat() }}"

thanx a lot, exactly what i was searching for. :+1:

i end up with

Kirby::plugin('my/pageMethods', [
    'pageMethods' => [
        'modifiedToLocale' => function() {
            $format = kirby()->user()->language() === 'de' ? 'dd.MM.Y' : 'Y-MM-dd';
            return $this->modified($format);
        }
    ]
]);