From 97eab2b69ba6c2aae3e1fe1a97b3b81571e4d8d7 Mon Sep 17 00:00:00 2001 From: Robert Korulczyk Date: Tue, 1 Oct 2024 21:59:07 +0200 Subject: [PATCH 1/2] Allow to customize time formats --- framework/core/js/src/common/utils/humanTime.ts | 6 ++++-- framework/core/js/src/forum/components/PostStream.js | 3 ++- framework/core/locale/core.yml | 6 ++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/framework/core/js/src/common/utils/humanTime.ts b/framework/core/js/src/common/utils/humanTime.ts index 870153ae28..cc5b2d4efd 100644 --- a/framework/core/js/src/common/utils/humanTime.ts +++ b/framework/core/js/src/common/utils/humanTime.ts @@ -1,4 +1,6 @@ +import app from '../../common/app'; import dayjs from 'dayjs'; +import extractText from "./extractText"; /** * The `humanTime` utility converts a date to a localized, human-readable time- @@ -23,9 +25,9 @@ export default function humanTime(time: dayjs.ConfigType): string { // in the string. If it wasn't this year, we'll show the year as well. if (diff < -30 * day) { if (d.year() === dayjs().year()) { - ago = d.format('D MMM'); + ago = d.format(extractText(app.translator.trans('core.lib.datetime_formats.humanTimeShort'))); } else { - ago = d.format('ll'); + ago = d.format(extractText(app.translator.trans('core.lib.datetime_formats.humanTimeLong'))); } } else { ago = d.fromNow(); diff --git a/framework/core/js/src/forum/components/PostStream.js b/framework/core/js/src/forum/components/PostStream.js index 13aa8aeb7f..6c1e5dae55 100644 --- a/framework/core/js/src/forum/components/PostStream.js +++ b/framework/core/js/src/forum/components/PostStream.js @@ -5,6 +5,7 @@ import PostLoading from './LoadingPost'; import ReplyPlaceholder from './ReplyPlaceholder'; import Button from '../../common/components/Button'; import ItemList from '../../common/utils/ItemList'; +import extractText from "../../common/utils/extractText"; /** * The `PostStream` component displays an infinitely-scrollable wall of posts in @@ -292,7 +293,7 @@ export default class PostStream extends Component { // set the index to the last post. this.stream.index = indexFromViewPort !== null ? indexFromViewPort + 1 : this.stream.count(); this.stream.visible = visible; - if (period) this.stream.description = dayjs(period).format('MMMM YYYY'); + if (period) this.stream.description = dayjs(period).format(extractText(app.translator.trans('core.lib.datetime_formats.scrubber'))); } /** diff --git a/framework/core/locale/core.yml b/framework/core/locale/core.yml index 24eeb31645..3e2e1e459a 100644 --- a/framework/core/locale/core.yml +++ b/framework/core/locale/core.yml @@ -653,6 +653,12 @@ core: kilo_text: K mega_text: M + # These translations are used for formatting dates using dayjs. + datetime_formats: + humanTimeShort: D MMM + humanTimeLong: ll + scrubber: MMMM YYYY + # These translations are used to punctuate a series of items. series: glue_text: ", " From acec3db54c883230008776d101f18fcd1b499a38 Mon Sep 17 00:00:00 2001 From: Robert Korulczyk Date: Tue, 1 Oct 2024 22:12:55 +0200 Subject: [PATCH 2/2] Fix CS --- framework/core/js/src/common/utils/humanTime.ts | 2 +- framework/core/js/src/forum/components/PostStream.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/core/js/src/common/utils/humanTime.ts b/framework/core/js/src/common/utils/humanTime.ts index cc5b2d4efd..2c60659a55 100644 --- a/framework/core/js/src/common/utils/humanTime.ts +++ b/framework/core/js/src/common/utils/humanTime.ts @@ -1,6 +1,6 @@ import app from '../../common/app'; import dayjs from 'dayjs'; -import extractText from "./extractText"; +import extractText from './extractText'; /** * The `humanTime` utility converts a date to a localized, human-readable time- diff --git a/framework/core/js/src/forum/components/PostStream.js b/framework/core/js/src/forum/components/PostStream.js index 6c1e5dae55..8f3d487ab3 100644 --- a/framework/core/js/src/forum/components/PostStream.js +++ b/framework/core/js/src/forum/components/PostStream.js @@ -5,7 +5,7 @@ import PostLoading from './LoadingPost'; import ReplyPlaceholder from './ReplyPlaceholder'; import Button from '../../common/components/Button'; import ItemList from '../../common/utils/ItemList'; -import extractText from "../../common/utils/extractText"; +import extractText from '../../common/utils/extractText'; /** * The `PostStream` component displays an infinitely-scrollable wall of posts in