Skip to content

Commit 6f85f19

Browse files
meta: updated next-intl and dependent packages (#6130)
* meta: updated next-intl and dependent packages * Update i18n.tsx Signed-off-by: Brian Muenzenmeyer <brian.muenzenmeyer@gmail.com> --------- Signed-off-by: Brian Muenzenmeyer <brian.muenzenmeyer@gmail.com> Co-authored-by: Brian Muenzenmeyer <brian.muenzenmeyer@gmail.com>
1 parent 65f52b8 commit 6f85f19

4 files changed

Lines changed: 207 additions & 135 deletions

File tree

i18n.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
11
import type { RichTranslationValues } from 'next-intl';
22
import { getRequestConfig } from 'next-intl/server';
33

4-
export const defaultRichTextValues: RichTranslationValues = {
4+
import { availableLocaleCodes } from './next.locales.mjs';
5+
6+
// Loads the Application Locales/Translations Dynamically
7+
const loadLocaleDictionary = async (locale: string) => {
8+
if (locale === 'en') {
9+
// This enables HMR on the English Locale, so that instant refresh
10+
// happens while we add/change texts on the source locale
11+
return import('./i18n/locales/en.json').then(f => f.default);
12+
}
13+
14+
if (locale in availableLocaleCodes) {
15+
// Other languages don't really require HMR as they will never be development languages
16+
// so we can load them dynamically
17+
return import(`./i18n/locales/${locale}.json`).then(f => f.default);
18+
}
19+
20+
throw new Error(`Unsupported locale: ${locale}`);
21+
};
22+
23+
// Defines default Rich Text Components
24+
const defaultRichTextValues: RichTranslationValues = {
525
graySpan: c => <span className="small color-lightgray">{c}</span>,
626
};
727

28+
// Provides `next-intl` configuration for RSC/SSR
829
export default getRequestConfig(async ({ locale }) => ({
9-
messages: (await import(`./i18n/locales/${locale}.json`)).default,
30+
// This is the dictionary of messages to be loaded
31+
messages: await loadLocaleDictionary(locale),
32+
// Default Rich Text Translations
33+
defaultTranslationValues: defaultRichTextValues,
34+
// We always define the App timezone as UTC
1035
timeZone: 'Etc/UTC',
1136
}));

layouts/DocsLayout.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,11 @@ const DocsLayout: FC<PropsWithChildren> = ({ children }) => {
1414
apiLts: {
1515
ltsNodeVersion: lts ? `v${lts.major}.x` : undefined,
1616
fullLtsNodeVersion: lts ? lts.versionWithPrefix : undefined,
17-
graySpan: c => <span className="small color-lightgray">{c}</span>,
1817
},
1918
apiCurrent: {
2019
fullCurrentNodeVersion: current ? current.versionWithPrefix : undefined,
2120
currentNodeVersion: current ? `v${current.major}.x` : undefined,
2221
},
23-
guides: {
24-
graySpan: c => <span className="small color-lightgray">{c}</span>,
25-
},
2622
};
2723

2824
return (

0 commit comments

Comments
 (0)