Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Use translation strings for comment timestamps

Anand Baburajanbfaf0730bf4d
diff --git a/web/packages/base/locales/en-US/translation.json b/web/packages/base/locales/en-US/translation.json
index 873a215597..f6fbfaed79 100644
--- a/web/packages/base/locales/en-US/translation.json
+++ b/web/packages/base/locales/en-US/translation.json
@@ -155,6 +155,10 @@
"commented_on_a_video": "Commented on a video",
"replied_to_a_comment": "Replied to a comment",
"liked_a_comment": "Liked a comment",
+ "just_now": "just now",
+ "minutes_ago": "{{count}}m ago",
+ "hours_ago": "{{count}}h ago",
+ "days_ago": "{{count}}d ago",
"like_anonymously": "Like anonymously",
"join_album_and_like": "Join album and like",
"keep_it_private": "Or keep it just between you and the memory.",
diff --git a/web/packages/gallery/components/viewer/CommentsSidebar.tsx b/web/packages/gallery/components/viewer/CommentsSidebar.tsx
index a19e7b355f..dede805b3e 100644
--- a/web/packages/gallery/components/viewer/CommentsSidebar.tsx
+++ b/web/packages/gallery/components/viewer/CommentsSidebar.tsx
@@ -41,7 +41,7 @@ import {
deleteReaction,
} from "ente-new/photos/services/reaction";
import { type UnifiedReaction } from "ente-new/photos/services/social";
-import { t } from "i18next";
+import i18n, { t } from "i18next";
import React, {
useCallback,
useEffect,
@@ -183,22 +183,28 @@ const formatTimeAgo = (timestampMicros: number): string => {
const now = Date.now();
const diff = now - timestampMs;
const minutes = Math.floor(diff / 60000);
- if (minutes < 1) return "just now";
- if (minutes < 60) return `${minutes}m ago`;
+ if (minutes < 1) return t("just_now");
+ if (minutes < 60) return t("minutes_ago", { count: minutes });
const hours = Math.floor(minutes / 60);
- if (hours < 24) return `${hours}h ago`;
+ if (hours < 24) return t("hours_ago", { count: hours });
const days = Math.floor(hours / 24);
- if (days < 7) return `${days}d ago`;
+ if (days < 7) return t("days_ago", { count: days });
- // For 7+ days, show actual date
+ // For 7+ days, show actual date using locale-aware formatting
const date = new Date(timestampMs);
const currentYear = new Date(now).getFullYear();
- const month = date.toLocaleString("en-US", { month: "short" });
- const day = date.getDate();
+ const locale = i18n.language;
if (date.getFullYear() === currentYear) {
- return `${month} ${day}`;
+ return date.toLocaleDateString(locale, {
+ month: "short",
+ day: "numeric",
+ });
}
- return `${month} ${day}, ${date.getFullYear()}`;
+ return date.toLocaleDateString(locale, {
+ month: "short",
+ day: "numeric",
+ year: "numeric",
+ });
};
const getParentComment = (