Skip to content

Commit 221d702

Browse files
authored
docs: Fallbacks from other locales (#124)
1 parent 5946cd1 commit 221d702

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

packages/website/pages/docs/usage/error-handling.mdx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,20 @@ function getMessageFallback({namespace, key, error}) {
3131
<App />
3232
</NextIntlProvider>
3333
```
34+
35+
## Fallbacks from other locales
36+
37+
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`.
38+
39+
```jsx
40+
import deepmerge from 'deepmerge';
41+
42+
// pages/index.js
43+
export async function getStaticProps({locale}) {
44+
const userMessages = (await import(`../../messages/${locale}.json`)).default;
45+
const defaultMessages = (await import(`../../messages/en.json`)).default;
46+
const messages = deepmerge(defaultMessages, userMessages);
47+
48+
return {props: {messages}};
49+
}
50+
```

0 commit comments

Comments
 (0)