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.2 KB · 46 lines tsx
Raw Blame History
1/**2 * earth-now.co3 * Author:  Simon-Pierre Boucher4 * Contact: contact@spboucher.ai5 * File:    apps/web/lib/i18n.tsx6 * Purpose: Tiny client-side locale context (fr/en) — provider + useI18n hook, UI strings only (metric text comes from the API)7 */89"use client";1011import { createContext, useContext, type ReactNode } from "react";12import type { Locale } from "./api";13import { getMessages, type MessageKey } from "./messages";1415interface I18nContextValue {16  locale: Locale;17  setLocale: (locale: Locale) => void;18  t: (key: MessageKey) => string;19}2021const I18nContext = createContext<I18nContextValue | null>(null);2223export function I18nProvider({24  locale,25  setLocale,26  children,27}: {28  locale: Locale;29  setLocale: (locale: Locale) => void;30  children: ReactNode;31}) {32  const messages = getMessages(locale);33  const value: I18nContextValue = {34    locale,35    setLocale,36    t: (key) => messages[key],37  };38  return <I18nContext.Provider value={value}>{children}</I18nContext.Provider>;39}4041export function useI18n(): I18nContextValue {42  const ctx = useContext(I18nContext);43  if (ctx === null) throw new Error("useI18n must be used inside <I18nProvider>");44  return ctx;45}46