@i18n-micro/react
React bindings for i18n-micro — hooks, context, and UI components.
Entry points: @i18n-micro/react, @i18n-micro/react/client, @i18n-micro/react/router, @i18n-micro/react/server.
@i18n-micro/react
Components
I18nGroup
function I18nGroup(props: I18nGroupProps): HostElement
See I18nGroupProps
I18nLink
function I18nLink(props: I18nLinkProps): HostElement
See I18nLinkProps
I18nProvider
function I18nProvider(props: I18nProviderProps): HostElement
I18nSwitcher
function I18nSwitcher(props: I18nSwitcherProps): HostElement
I18nT
function I18nT(props: I18nTProps): HostElement
See I18nTProps
Hooks
useI18n
function useI18n(options?: UseI18nOptions): UseI18nReturn
See UseI18nOptions · UseI18nReturn
useI18nContext
function useI18nContext(): I18n
See I18n
useI18nDefaultLocale
function useI18nDefaultLocale(): string | null
useI18nLocales
function useI18nLocales(): Locale[] | null
See Locale
useI18nRouter
function useI18nRouter(): I18nRoutingStrategy | null
useLocaleSwitch
setLocale that loads first. A store write is synchronous for React, even inside
startTransition, so a reader that suspends on a missing dictionary would show its fallback:
this keeps the old UI until the messages are in. The last call wins; a failed load rejects
and leaves the locale as it was.
function useLocaleSwitch(
load: (locale: string) => unknown,
): [ (locale: string) => Promise<void>, boolean ]
useT
One translation as a value: the component renders only when this string changes, not on every locale or message write, nor when a provider gets a new adapter object.
function useT(
key: TranslationKey,
params?: Params,
defaultValue?: string,
routeName?: string,
): string
See TranslationKey · Params
Constants
I18nConfigContext
const I18nConfigContext: React.Context<I18nConfig | null>
See I18nConfig
I18nContext
The instance alone, stable while the app runs: useT and <I18nT> read only this, so a new
adapter object does not render them.
const I18nContext: React.Context<I18n | null>
See I18n
Types
I18nConfig
What a provider adds to its instance. It changes with its props, an adapter built in render on every render.
interface I18nConfig
useI18n() object of the current snapshot, shared by every consumer of this provider.t does not change with an adapter.I18nGroupProps
interface I18nGroupProps extends Omit<HostAttrs<HTMLDivElement>, 'children'>
I18nLinkProps
type I18nLinkProps = HostAnchorAttrs<HTMLAnchorElement> & { … }
I18nProviderProps
interface I18nProviderProps extends Partial<I18nOptions>
See I18nOptions
I18nRoutingStrategy
Routing strategy interface for i18n Implement this interface to integrate with any router library Matches Vue/Solid package interface for consistency
interface I18nRoutingStrategy
I18nSwitcherProps
interface I18nSwitcherProps extends HostAttrs<HTMLDivElement>
disabled: true in the locale config. Disabled locales are omitted from the dropdown items, but still shown as the
active button label.I18nTComponent
What fills a {name} placeholder: a node, or a function returning one (it may use hooks).
type I18nTComponent = HostNode | (() => HostNode)
I18nTProps
interface I18nTProps extends Omit<HostAttrs<HTMLElement>, 'children' | 'defaultValue'>, Omit<I18nTRenderProps, 'tag'>
{name} placeholders. Beats a param of the same name.See I18nTRenderProps
RouteTarget
Where a link or a switch goes.
type RouteTarget = string | {
path?: string;
}
UseI18nOptions
interface UseI18nOptions
UseI18nReturn
interface UseI18nReturn
Re-exports
Declared in another package of this repository and documented on its page.
- From
@i18n-micro/core:defaultPlural·interpolate·FormatService - From
@i18n-micro/runtime:createI18n·ReactI18n(asI18n) ·ReactI18nOptions(asI18nOptions) - From
@i18n-micro/types:CleanTranslation·Getter·Locale·LocaleCode·ModuleOptions·Params·PluralFunc·TranslationKey·Translations
@i18n-micro/react/client
The same exports as @i18n-micro/react above.
@i18n-micro/react/router
Also exports, as @i18n-micro/react does: I18nRoutingStrategy.
Functions
createReactRouterAdapter
Factory for React Router adapter Implements routing utilities for React Router Uses react-router-dom APIs for navigation and path resolution
function createReactRouterAdapter(
locales: Locale[],
defaultLocale: string,
location: ReturnType<typeof useLocation>,
navigate: ReturnType<typeof useNavigate>,
): I18nRoutingStrategy
See Locale · I18nRoutingStrategy
@i18n-micro/react/server
Also exports, as @i18n-micro/react does: createI18n · defaultPlural · interpolate · FormatService · ReactI18n · I18nTComponent · ReactI18nOptions.
Components
I18nT
<I18nT> for a server component. Its text stays out of the client bundle.
function I18nT(props: ServerI18nTProps): HostElement
See ServerI18nTProps
Types
ServerI18nTProps
interface ServerI18nTProps extends I18nTProps
See I18nTProps
Generated from the TypeScript sources and their JSDoc by pnpm run docs:generate.
Back to all packages · Integration guides