temp
This commit is contained in:
@@ -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 }
|
||||
}
|
||||
Reference in New Issue
Block a user