Ariver
2026-06-03 9a85354d8b41e05ba8729cd8f44592291de9117a
privatevoice.src/frontend/src/lib/i18n/index.ts
@@ -1,9 +1,11 @@
import zh from "./zh.json";
import en from "./en.json";
import { writable } from "svelte/store";
type Locale = "zh" | "en";
export type Locale = "zh" | "en";
const translations: Record<Locale, Record<string, any>> = { zh, en };
export const localeRevision = writable(0);
// Detect system language, default to Chinese
function detectLocale(): Locale {
@@ -14,8 +16,16 @@
let currentLocale: Locale = detectLocale();
export function setLocale(locale: Locale) {
  currentLocale = locale;
function normalizeLocale(locale: string): Locale {
  return locale.toLowerCase().startsWith("zh") ? "zh" : "en";
}
export function setLocale(locale: Locale | string) {
  const next = normalizeLocale(locale);
  if (currentLocale !== next) {
    currentLocale = next;
    localeRevision.update((value) => value + 1);
  }
}
export function getLocale(): Locale {