Skip to content

Commit

Permalink
merge messages
Browse files Browse the repository at this point in the history
  • Loading branch information
SKarolFolio committed Nov 11, 2024
1 parent 8b15888 commit ce5fc49
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/common/hooks/useLoadI18nMessages.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { loadI18nMessages } from '@common/helpers/locales.helper';

export const useLoadI18nMessages = (cachedMessages: I18nMessages) => {
export const useLoadI18nMessages = (cachedMessages: I18nMessages, defaultLocale = 'en') => {
const getMessages = (locale: string) => {
if (cachedMessages?.[locale]) {
return cachedMessages?.[locale];
Expand All @@ -13,7 +13,7 @@ export const useLoadI18nMessages = (cachedMessages: I18nMessages) => {
const messages = await loadI18nMessages(locale);

if (messages) {
cachedMessages[locale] = messages;
cachedMessages[locale] = {...cachedMessages[defaultLocale], messages};
}
};

Expand Down
6 changes: 4 additions & 2 deletions src/providers/AsyncIntlProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ type AsyncIntlProviderProps = {
children: React.ReactNode;
};

const DEFAULT_LOCALE = 'en';

export const AsyncIntlProvider: FC<AsyncIntlProviderProps> = ({ cachedMessages, children }) => {
const locale = useRecoilValue(state.config.locale);
const { getMessages } = useLoadI18nMessages(cachedMessages);
const { getMessages } = useLoadI18nMessages(cachedMessages, DEFAULT_LOCALE);

const i18nMessages = getMessages(locale);

return (
<IntlProvider messages={i18nMessages || {}} locale={locale} defaultLocale="en">
<IntlProvider messages={i18nMessages || {}} locale={locale} defaultLocale={DEFAULT_LOCALE}>
{children}
</IntlProvider>
);
Expand Down

0 comments on commit ce5fc49

Please sign in to comment.