forked from nodejs/nodejs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
meta: updated next-intl and dependent packages (nodejs#6130)
* meta: updated next-intl and dependent packages * Update i18n.tsx Signed-off-by: Brian Muenzenmeyer <[email protected]> --------- Signed-off-by: Brian Muenzenmeyer <[email protected]> Co-authored-by: Brian Muenzenmeyer <[email protected]>
- Loading branch information
1 parent
65f52b8
commit 6f85f19
Showing
4 changed files
with
207 additions
and
135 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 |
---|---|---|
@@ -1,11 +1,36 @@ | ||
import type { RichTranslationValues } from 'next-intl'; | ||
import { getRequestConfig } from 'next-intl/server'; | ||
|
||
export const defaultRichTextValues: RichTranslationValues = { | ||
import { availableLocaleCodes } from './next.locales.mjs'; | ||
|
||
// Loads the Application Locales/Translations Dynamically | ||
const loadLocaleDictionary = async (locale: string) => { | ||
if (locale === 'en') { | ||
// This enables HMR on the English Locale, so that instant refresh | ||
// happens while we add/change texts on the source locale | ||
return import('./i18n/locales/en.json').then(f => f.default); | ||
} | ||
|
||
if (locale in availableLocaleCodes) { | ||
// Other languages don't really require HMR as they will never be development languages | ||
// so we can load them dynamically | ||
return import(`./i18n/locales/${locale}.json`).then(f => f.default); | ||
} | ||
|
||
throw new Error(`Unsupported locale: ${locale}`); | ||
}; | ||
|
||
// Defines default Rich Text Components | ||
const defaultRichTextValues: RichTranslationValues = { | ||
graySpan: c => <span className="small color-lightgray">{c}</span>, | ||
}; | ||
|
||
// Provides `next-intl` configuration for RSC/SSR | ||
export default getRequestConfig(async ({ locale }) => ({ | ||
messages: (await import(`./i18n/locales/${locale}.json`)).default, | ||
// This is the dictionary of messages to be loaded | ||
messages: await loadLocaleDictionary(locale), | ||
// Default Rich Text Translations | ||
defaultTranslationValues: defaultRichTextValues, | ||
// We always define the App timezone as UTC | ||
timeZone: 'Etc/UTC', | ||
})); |
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
Oops, something went wrong.