Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Fallbacks from other locales #124

Merged
merged 1 commit into from
Aug 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/website/pages/docs/usage/error-handling.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,20 @@ function getMessageFallback({namespace, key, error}) {
<App />
</NextIntlProvider>
```

## Fallbacks from other locales

If you have incomplete messages for a given locale and would like to use messages from another locale as a fallback, you can merge the two before passing them to `NextIntlProvider`.

```jsx
import deepmerge from 'deepmerge';

// pages/index.js
export async function getStaticProps({locale}) {
const userMessages = (await import(`../../messages/${locale}.json`)).default;
const defaultMessages = (await import(`../../messages/en.json`)).default;
const messages = deepmerge(defaultMessages, userMessages);

return {props: {messages}};
}
```