Repository Public
1import { en } from "./dict/en";2import { fr } from "./dict/fr";34export const LOCALES = ["en", "fr"] as const;5export type Locale = (typeof LOCALES)[number];6export const DEFAULT_LOCALE: Locale = "en";7export type Dict = typeof en;89export const isLocale = (x: string): x is Locale => (LOCALES as readonly string[]).includes(x);10export const getDict = (locale: Locale): Dict => (locale === "fr" ? fr : en);1112export const ROUTES = ["", "/live", "/nodes", "/architecture", "/research", "/benchmarks", "/gallery", "/access"] as const;1314/** Same page in the other language: /en/nodes/node-03 -> /fr/nodes/node-03 */15export function switchLocalePath(pathname: string, to: Locale): string {16 const parts = pathname.split("/");17 if (parts.length > 1 && isLocale(parts[1])) parts[1] = to;18 else parts.splice(1, 0, to);19 return parts.join("/").replace(/\/$/, "") || `/${to}`;20}2122export function formatDate(iso: string, locale: Locale): string {23 const [y, m, d] = iso.split("-").map(Number);24 const date = new Date(Date.UTC(y, (m ?? 1) - 1, d ?? 1));25 return new Intl.DateTimeFormat(locale === "fr" ? "fr-CA" : "en-CA", { year: "numeric", month: "long", ...(d ? { day: "numeric" } : {}), timeZone: "UTC" }).format(date);26}2728export function formatNumber(n: number, locale: Locale): string {29 return new Intl.NumberFormat(locale === "fr" ? "fr-CA" : "en-CA").format(n);30}31