@@ -4,14 +4,15 @@ import i18nConfig from '../i18n/config.json';
44import type { FC , PropsWithChildren } from 'react' ;
55import 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
1012type LocaleProviderProps = PropsWithChildren < {
1113 i18nData : AppProps [ 'i18nData' ] ;
1214} > ;
1315
14- // this is used just as fallback data to prevent issues with react-intl
1516const fallbackData = { currentLocale : { code : 'en' } } as AppProps [ 'i18nData' ] ;
1617
1718export 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