pure
    Preparing search index...

    Type Alias LocaleOptions<TLocale>

    type LocaleOptions<TLocale extends string> = {
        default: TLocale;
        initial?: TLocale;
        onBeforeChange?: (
            newLocale: string,
            checkCancel: () => void,
        ) => void | Promise<void>;
        persist?: boolean;
        supported: readonly TLocale[];
    }

    Type Parameters

    • TLocale extends string
    Index

    Properties

    default: TLocale

    The default locale if the user's preferred locale is not supported. This must be one of the items in supported.

    initial?: TLocale

    Initial value for locale

    If not set, it will default to calling getPreferredLocale(), which is based on the browser's language settings.

    If persist is true, it will also check the value from localStorage

    If the initial value is not supported, it will default to the default locale

    onBeforeChange?: (
        newLocale: string,
        checkCancel: () => void,
    ) => void | Promise<void>

    Hook to be called by setLocale, but before setting the locale and thus notifying the subscribers.

    Internally, this is synchronized by the serial function, which means if another setLocale is called before the hook finishes, the set operation of the current call will not happen and the locale will only be set after the hook finishes in the new call.

    If there are race conditions in the hook, checkCancel should be used after any async operations, which will throw an error if another call happened.

    Note that this hook will not be called during initialization.

    persist?: boolean

    Persist the locale preference to localStorage

    supported: readonly TLocale[]

    List of supported locale or languages. These can be full locale strings like "en-US" or just languages like "en"