mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-11-13 17:08:20 +00:00
refactor: clamp\storage dry
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user