refactor: clamp\storage dry

This commit is contained in:
2026-10-09 22:09:02 +05:00
parent d58f6c90be
commit 07c6475c21
15 changed files with 68 additions and 77 deletions
+2 -5
View File
@@ -1,6 +1,7 @@
import { BASE_LOCALE, isLocale, type Dict, type Locale } from "./dict";
import { ru } from "./ru";
import { en } from "./en";
import { safeSetItem, storage } from "../storage";
const STORAGE_KEY = "locale";
@@ -8,10 +9,6 @@ const DICTS: Record<Locale, Dict> = { ru, en };
let locale = $state<Locale>(BASE_LOCALE);
function storage(): Storage | null {
return typeof localStorage === "undefined" ? null : localStorage;
}
export function getLocale(): Locale {
return locale;
}
@@ -39,7 +36,7 @@ export function getMergedDict(): Dict {
export function setLocale(next: Locale): void {
locale = next;
storage()?.setItem(STORAGE_KEY, next);
safeSetItem(STORAGE_KEY, next);
syncLangAttr();
}