refactor(i18n,format): translate ETA strings; consolidate time/duration formatters

- formatEta was hardcoded English (violated the trilingual rule) -> time.eta.* keys
  in EN/HU/DE; Scheduler's countdown 'now' likewise.
- relativeFromMs added to format.ts; NotificationsPanel drops its duplicate
  relativeTime/relativeFromMs and the now-orphaned notifications.time.* keys.
- Channels' fmtTotalDuration moved to format.ts as formatTotalHours.
This commit is contained in:
npeter83 2026-06-29 00:22:21 +02:00
parent 5768c1a5cb
commit 9eaec27c7c
10 changed files with 61 additions and 64 deletions

View file

@ -19,7 +19,7 @@ import {
type VideoHiddenMeta,
type VideoWatchedMeta,
} from "../lib/notifications";
import { channelYouTubeUrl } from "../lib/format";
import { channelYouTubeUrl, relativeFromMs, relativeTime } from "../lib/format";
import type { Page } from "../lib/urlState";
import { LEVEL_STYLE } from "./Toaster";
@ -29,22 +29,6 @@ import { LEVEL_STYLE } from "./Toaster";
// there's one indicator and one place to look. Transient toasts still pop via the Toaster.
const POLL_MS = 8000;
function relativeTime(iso: string | null, t: (k: string, o?: any) => string): string {
if (!iso) return "";
return relativeFromMs(new Date(iso).getTime(), t);
}
function relativeFromMs(ms: number, t: (k: string, o?: any) => string): string {
const secs = Math.max(0, Math.round((Date.now() - ms) / 1000));
// Reuse the bell's relative-time strings (notifications.time.*) — same format, no dupes.
if (secs < 60) return t("notifications.time.justNow");
const mins = Math.round(secs / 60);
if (mins < 60) return t("notifications.time.minutes", { count: mins });
const hours = Math.round(mins / 60);
if (hours < 24) return t("notifications.time.hours", { count: hours });
return t("notifications.time.days", { count: Math.round(hours / 24) });
}
export default function NotificationsPanel({
filters,
setFilters,
@ -253,7 +237,7 @@ function NotificationRow({
<div className="flex items-baseline gap-2">
<span className="font-medium text-sm">{title}</span>
<span className="text-[11px] text-muted shrink-0">
{relativeTime(n.created_at, t)}
{relativeTime(n.created_at)}
</span>
</div>
{body && <div className="text-sm text-muted mt-0.5">{body}</div>}
@ -338,7 +322,7 @@ function ClientActivityRow({
{n.title && <div className="text-sm font-semibold">{n.title}</div>}
<div className="text-sm break-words">{n.message}</div>
<div className="flex items-center gap-2 mt-0.5">
<span className="text-[11px] text-muted">{relativeFromMs(n.ts, t)}</span>
<span className="text-[11px] text-muted">{relativeFromMs(n.ts)}</span>
{needsAction && (
<span className="text-[10px] uppercase tracking-wide font-semibold text-accent">
{t("notifications.actionNeeded")}