-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Option to provide non translated strings in a fallback locale (#1659)
- Loading branch information
1 parent
6966f19
commit f4a94b5
Showing
4 changed files
with
30 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@bigcommerce/catalyst-core": minor | ||
--- | ||
|
||
If a string is not provided in the selected locale, the translation system will fallback to "en" for that specific entry. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,34 @@ | ||
import deepmerge from 'deepmerge'; | ||
import { notFound } from 'next/navigation'; | ||
import { getRequestConfig } from 'next-intl/server'; | ||
|
||
import { locales } from './routing'; | ||
|
||
// The language to fall back to if the requested message string is not available. | ||
const fallbackLocale = 'en'; | ||
|
||
export default getRequestConfig(async ({ requestLocale }) => { | ||
const locale = await requestLocale; | ||
|
||
if (!locale || !locales.includes(locale)) { | ||
notFound(); | ||
} | ||
|
||
if (locale === fallbackLocale) { | ||
return { | ||
locale, | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access | ||
messages: (await import(`../messages/${locale}.json`)).default, | ||
}; | ||
} | ||
|
||
return { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access | ||
messages: (await import(`../messages/${locale}.json`)).default, | ||
locale, | ||
messages: deepmerge( | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access | ||
(await import(`../messages/${fallbackLocale}.json`)).default, | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access | ||
(await import(`../messages/${locale}.json`)).default, | ||
), | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.