Skip to content

Commit

Permalink
revert: Revert the deletion of empty lines
Browse files Browse the repository at this point in the history
  • Loading branch information
ichiwa committed Oct 23, 2023
1 parent 1bb5c4f commit 860e13c
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@ import type { Context, ReactNode } from 'react';
import React, { Suspense, use, useMemo } from 'react';
import { flattenLocale } from '../../common/flatten-locale';
import type { LocaleContext } from '../../types';

type I18nProviderProps = Omit<I18nProviderWrapperProps, 'fallback'>;

type I18nProviderWrapperProps = {
locale: string;
fallback?: ReactNode;
children: ReactNode;
};

export const localesCache = new Map<string, Record<string, unknown>>();

export function createI18nProviderClient<Locale extends BaseLocale>(
I18nClientContext: Context<LocaleContext<Locale> | null>,
locales: ImportedLocales,
fallbackLocale?: Record<string, unknown>,
) {
function I18nProvider({ locale, children }: I18nProviderProps) {
let clientLocale: any = localesCache.get(locale);

if (!clientLocale) {
const newLocale = locales[locale as keyof typeof locales];
if (!newLocale) {
Expand All @@ -35,13 +40,15 @@ export function createI18nProviderClient<Locale extends BaseLocale>(
}),
[clientLocale, locale],
);

return <I18nClientContext.Provider value={value}>{children}</I18nClientContext.Provider>;
}

return function I18nProviderWrapper({ locale, fallback, children }: I18nProviderWrapperProps) {
return (
<Suspense fallback={fallback}>
<I18nProvider locale={locale}>{children}</I18nProvider>
</Suspense>
);
};
}
}

0 comments on commit 860e13c

Please sign in to comment.