This commit is contained in:
2026-09-08 23:34:42 +02:00
parent 91b61caa37
commit 754b84e5f6
18 changed files with 304 additions and 72 deletions
+21
View File
@@ -0,0 +1,21 @@
import { STRINGS, type Strings } from '../i18n/strings'
export type Locale = 'it' | 'en'
/**
* Site language, persisted in a cookie so SSR renders the right language on
* the first request. `t(key)` reads the current locale's UI string.
*/
export function useLocale() {
const locale = useCookie<Locale>('lang', { default: () => 'it', sameSite: 'lax' })
function setLocale(value: Locale) {
locale.value = value
}
function t<K extends keyof Strings>(key: K): Strings[K] {
return STRINGS[locale.value][key]
}
return { locale, setLocale, t }
}