Skip to content

Commit

Permalink
hotfix: add i18n filter and move filter/map
Browse files Browse the repository at this point in the history
  • Loading branch information
ovflowd committed May 12, 2023
1 parent abf120d commit ff73d8d
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions providers/localeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import i18nConfig from '../i18n/config.json';
import type { FC, PropsWithChildren } from 'react';
import type { AppProps, LocaleContext as LocaleContextType } from '../types';

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

type LocaleProviderProps = PropsWithChildren<{
i18nData: AppProps['i18nData'];
}>;

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

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

const intlProps = { locale: currentLocale.code, messages: localeMessages };

const availableLocales = i18nConfig.map(({ code, localName, name }) => ({
code,
localName,
name,
}));

return (
<LocaleContext.Provider value={{ ...i18nData, availableLocales }}>
<IntlProvider {...intlProps} onError={() => null}>
<IntlProvider
locale={currentLocale.code}
messages={localeMessages}
onError={() => null}
>
{children}
</IntlProvider>
</LocaleContext.Provider>
Expand Down

2 comments on commit ff73d8d

@vercel
Copy link

@vercel vercel bot commented on ff73d8d May 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nodejs-org-stories – ./

nodejs-org-storybook.vercel.app
nodejs-org-stories-openjs.vercel.app
nodejs-org-stories-git-main-openjs.vercel.app

@vercel
Copy link

@vercel vercel bot commented on ff73d8d May 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nodejs-org – ./

nodejs-org-git-main-openjs.vercel.app
nodejs-org-openjs.vercel.app
node-js-org.vercel.app

Please sign in to comment.