mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-11-13 17:08:20 +00:00
style: fix formatting via prettier
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
import { BASE_LOCALE, isLocale, type Dict, type Locale } from './dict';
|
||||
import { ru } from './ru';
|
||||
import { en } from './en';
|
||||
import { BASE_LOCALE, isLocale, type Dict, type Locale } from "./dict";
|
||||
import { ru } from "./ru";
|
||||
import { en } from "./en";
|
||||
|
||||
const STORAGE_KEY = 'locale';
|
||||
const STORAGE_KEY = "locale";
|
||||
|
||||
const DICTS: Record<Locale, Dict> = { ru, en };
|
||||
|
||||
let locale = $state<Locale>(BASE_LOCALE);
|
||||
|
||||
function storage(): Storage | null {
|
||||
return typeof localStorage === 'undefined' ? null : localStorage;
|
||||
return typeof localStorage === "undefined" ? null : localStorage;
|
||||
}
|
||||
|
||||
export function getLocale(): Locale {
|
||||
@@ -29,13 +29,11 @@ export function getMergedDict(): Dict {
|
||||
get(_target, section: string) {
|
||||
const a = (active as unknown as Record<string, unknown>)[section];
|
||||
const b = (base as unknown as Record<string, unknown>)[section];
|
||||
if (
|
||||
a && b && typeof a === 'object' && typeof b === 'object'
|
||||
) {
|
||||
if (a && b && typeof a === "object" && typeof b === "object") {
|
||||
return { ...(b as object), ...(a as object) };
|
||||
}
|
||||
return a ?? b;
|
||||
}
|
||||
},
|
||||
}) as Dict;
|
||||
}
|
||||
|
||||
@@ -47,14 +45,14 @@ export function setLocale(next: Locale): void {
|
||||
|
||||
/** Читает сохранённый выбор и синхронизирует атрибут lang. Вызывается на клиенте. */
|
||||
export function initLocale(): void {
|
||||
if (typeof window === 'undefined') return;
|
||||
if (typeof window === "undefined") return;
|
||||
const saved = storage()?.getItem(STORAGE_KEY);
|
||||
if (isLocale(saved)) locale = saved;
|
||||
syncLangAttr();
|
||||
}
|
||||
|
||||
function syncLangAttr(): void {
|
||||
if (typeof document !== 'undefined') {
|
||||
if (typeof document !== "undefined") {
|
||||
document.documentElement.lang = locale;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user