SayProvider is a React context provider that makes a localized Say instance available to all descendant components in your component tree.
This is a client component that uses the
'use client' directive. It can only be used in client-side React code.Import
Props
The current locale code (e.g.,
'en', 'fr', 'es').The translation messages object for the current locale. This should contain all the translation keys and their corresponding values.
The child components that will have access to the Say instance via the
useSay() hook.Usage
Wrap your component tree withSayProvider to make translations available to all descendant components:
With dynamic locale switching
How it works
TheSayProvider component:
- Creates a
Sayinstance with the provided locale and messages - Immediately loads and activates the locale
- Freezes the instance to create a
ReadonlySayobject - Provides the instance via React Context to all descendant components
useSay() hook.