Client API
Contents
Import client-only localization helpers from @enonic/nextjs-adapter/client.
Usage
Wrap localized client components in LocaleContextProvider, normally from the locale layout.
'use client';
import {
LocaleContextProvider,
useLocaleContext
} from '@enonic/nextjs-adapter/client';
function Greeting() {
const {localize} = useLocaleContext();
return <p>{localize('greeting')}</p>;
}
export function Localized({locale}) {
return (
<LocaleContextProvider locale={locale}>
<Greeting/>
</LocaleContextProvider>
);
}
Phrase files are loaded through the starter’s @phrases alias.
Functions
LocaleContextProvider
Parameters
LocaleContextProvider() takes a single props object with these properties:
| Name | Type | Description |
|---|---|---|
|
|
|
Descendants that receive the locale context. |
|
|
|
Optional. Initial locale and dictionary to load. |
Returns
A React context provider element.
useLocaleContext
Returns the nearest LocaleContextType. Call only from a React client component below LocaleContextProvider.
Returns
LocaleContextType.
Classes
This entry point exports no classes.
Type Definitions
LocaleContextType
| Name | Type | Description |
|---|---|---|
|
|
|
Active locale. |
|
|
|
Loaded phrases. |
|
|
|
Resolves and formats a phrase. |
|
|
|
Loads another dictionary and activates it. |
Constants
This entry point exports no constants.