π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[web][photos] Format dates in the selected app language (#13959)
Yugendhra023de898e9b0
diff --git a/desktop/changes/dates-follow-language.md b/desktop/changes/dates-follow-language.mdnew file mode 100644index 0000000000..8cc7cfdd29--- /dev/null+++ b/desktop/changes/dates-follow-language.md@@ -0,0 +1 @@+- Fixed dates and times not following the selected app language. - @y9ndradiff --git a/web/packages/base/i18n-date.ts b/web/packages/base/i18n-date.tsindex 4c71126d1b..e4a4f58be3 100644--- a/web/packages/base/i18n-date.ts+++ b/web/packages/base/i18n-date.ts@@ -1,28 +1,36 @@import i18n, { t } from "i18next";-// These module-level formatters rely on locale changes doing a full reload.-const _dateFormat = new Intl.DateTimeFormat(i18n.language, {+const lazyDateTimeFormat = (options: Intl.DateTimeFormatOptions) => {+ let format: Intl.DateTimeFormat | undefined;++ return () => {+ if (format === undefined) {+ format = new Intl.DateTimeFormat(i18n.language, options);+ }+ return format;+ };+};++const dateFormat = lazyDateTimeFormat({weekday: "short",day: "numeric",month: "short",year: "numeric",});-const _dateWithoutWeekdayFormat = new Intl.DateTimeFormat(i18n.language, {+const dateWithoutWeekdayFormat = lazyDateTimeFormat({day: "numeric",month: "short",year: "numeric",});-const _dateWithoutYearFormat = new Intl.DateTimeFormat(i18n.language, {+const dateWithoutYearFormat = lazyDateTimeFormat({weekday: "short",day: "numeric",month: "short",});-const _timeFormat = new Intl.DateTimeFormat(i18n.language, {- timeStyle: "short",-});+const timeFormat = lazyDateTimeFormat({ timeStyle: "short" });interface FormattedDateOptions {omitWeekdayWhenYearIncluded?: boolean;@@ -30,16 +38,16 @@ interface FormattedDateOptions {export const formattedDate = (date: Date, options?: FormattedDateOptions) =>(isSameYear(date)- ? _dateWithoutYearFormat+ ? dateWithoutYearFormat(): options?.omitWeekdayWhenYearIncluded- ? _dateWithoutWeekdayFormat- : _dateFormat+ ? dateWithoutWeekdayFormat()+ : dateFormat()).format(date);const isSameYear = (date: Date) =>new Date().getFullYear() === date.getFullYear();-export const formattedTime = (date: Date) => _timeFormat.format(date);+export const formattedTime = (date: Date) => timeFormat().format(date);export const formattedDateTime = (dateOrEpochMicroseconds: Date | number,