| | |
| | | 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 { |
| | |
| | | |
| | | 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 { |