useWebsiteLocale
Creates persistent website-locale state backed by local storage. Whenever the locale changes, the composable updates the root document language through setWebsiteLocale.
The stored locale is applied as soon as the composable runs, so the document language matches a returning visitor's choice on the first render without any startup code. It is applied again on every change.
Importing
ts
import { useWebsiteLocale } from '@almighty-shogun/common';Usage
ts
import { useWebsiteLocale } from '@almighty-shogun/common';
const { locale, setLocale } = useWebsiteLocale();
setLocale('nl');Parameters
key?: string
Local-storage key used to persist the website locale.
Default: application-locale
Returns
locale: Ref<string>
Current website locale.
setLocale(locale: string): void
Updates the locale ref and applies it to the document.
Uses
Type signature
ts
declare function useWebsiteLocale(key?: string): UseWebsiteLocale;
type UseWebsiteLocale = {
readonly locale: Ref<string>;
setLocale(newLocale: string): void;
};