SPB Git

spb/earth-now Public License

earth-now.co — real-time planetary dashboard: live world metrics modeled, not streamed.

TypeScript 93% Shell 2.3% SQL 1.4% JavaScript 1.3% Dockerfile 1.2% CSS 0.8%
1.3 KB · 42 lines typescript
Raw Blame History
1/**2 * earth-now.co3 * Author:  Simon-Pierre Boucher4 * Contact: contact@spboucher.ai5 * File:    apps/web/lib/messages.ts6 * Purpose: Pure locale/message helpers (fr + en UI strings) usable from both server and client components7 */89import fr from "../messages/fr.json";10import en from "../messages/en.json";11import type { Locale } from "./api";1213export type MessageKey = keyof typeof fr;14export type Messages = Record<MessageKey, string>;1516const MESSAGES: Record<Locale, Messages> = { fr, en };1718export const DEFAULT_LOCALE: Locale = "fr";1920export function isLocale(value: unknown): value is Locale {21  return value === "fr" || value === "en";22}2324export function getMessages(locale: Locale): Messages {25  return MESSAGES[locale];26}2728/** Translate a key for a locale — usable server-side (pages) and client-side (via useI18n). */29export function translate(locale: Locale, key: MessageKey): string {30  return MESSAGES[locale][key];31}3233/** Format an ISO date for display (UTC, no hand-rolled date arithmetic). */34export function formatDateUtc(iso: string, locale: Locale): string {35  const ms = Date.parse(iso);36  if (Number.isNaN(ms)) return iso;37  return new Intl.DateTimeFormat(locale === "fr" ? "fr-FR" : "en-GB", {38    dateStyle: "medium",39    timeZone: "UTC",40  }).format(new Date(ms));41}42