Skip to content

Commit ff73d8d

Browse files
committed
hotfix: add i18n filter and move filter/map
1 parent abf120d commit ff73d8d

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

providers/localeProvider.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import i18nConfig from '../i18n/config.json';
44
import type { FC, PropsWithChildren } from 'react';
55
import type { AppProps, LocaleContext as LocaleContextType } from '../types';
66

7-
// TODO: We already import on the `getStaticProps` side, but some routes do not get the `getStaticProps` hence we need to fallback data here
8-
// might be a good opportunity to once we change to the code from `nodejs/nodejs.dev` to have an unified place for i18n stuff.
7+
// Retrieves all the Available Languages
8+
const availableLocales = i18nConfig
9+
.filter(({ enabled }) => enabled)
10+
.map(({ code, localName, name }) => ({ code, localName, name }));
911

1012
type LocaleProviderProps = PropsWithChildren<{
1113
i18nData: AppProps['i18nData'];
1214
}>;
1315

14-
// this is used just as fallback data to prevent issues with react-intl
1516
const fallbackData = { currentLocale: { code: 'en' } } as AppProps['i18nData'];
1617

1718
export const LocaleContext = createContext<LocaleContextType>(undefined as any);
@@ -22,17 +23,13 @@ export const LocaleProvider: FC<LocaleProviderProps> = ({
2223
}) => {
2324
const { currentLocale, localeMessages } = i18nData || fallbackData;
2425

25-
const intlProps = { locale: currentLocale.code, messages: localeMessages };
26-
27-
const availableLocales = i18nConfig.map(({ code, localName, name }) => ({
28-
code,
29-
localName,
30-
name,
31-
}));
32-
3326
return (
3427
<LocaleContext.Provider value={{ ...i18nData, availableLocales }}>
35-
<IntlProvider {...intlProps} onError={() => null}>
28+
<IntlProvider
29+
locale={currentLocale.code}
30+
messages={localeMessages}
31+
onError={() => null}
32+
>
3633
{children}
3734
</IntlProvider>
3835
</LocaleContext.Provider>

0 commit comments

Comments
 (0)