Skip to content

Commit

Permalink
fix: isolate i18next instance (#14)
Browse files Browse the repository at this point in the history
Co-authored-by: Eugene Chybisov <18644653+chybisov@users.noreply.github.com>
  • Loading branch information
StanleyDing and chybisov authored Oct 13, 2022
1 parent 5407a34 commit e2ff741
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
7 changes: 6 additions & 1 deletion packages/widget/src/AppProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import type { QueryClientProviderProps } from '@tanstack/react-query';
import { QueryClientProvider } from '@tanstack/react-query';
import type { FC, PropsWithChildren } from 'react';
import { Fragment } from 'react';
import { I18nextProvider } from 'react-i18next';
import { MemoryRouter, useInRouterContext } from 'react-router-dom';
import { i18n } from './i18n';
import type { WidgetConfig } from '.';
import { queryClient } from './config/queryClient';
import {
SDKProvider,
Expand Down Expand Up @@ -30,7 +33,9 @@ export const AppProvider: React.FC<PropsWithChildren<WidgetProps>> = ({
<SwapFormProvider>
<ThemeProvider>
<WalletProvider>
<AppRouter>{children}</AppRouter>
<I18nextProvider i18n={i18n}>
<AppRouter>{children}</AppRouter>
</I18nextProvider>
</WalletProvider>
</ThemeProvider>
</SwapFormProvider>
Expand Down
13 changes: 7 additions & 6 deletions packages/widget/src/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import i18next from 'i18next';
import translation from './en/translation.json';

export const defaultNS = 'translation';
Expand All @@ -9,14 +8,16 @@ export const resources = {
},
} as const;

export function configureReactI18next() {
i18n.use(initReactI18next).init({
export const i18n = i18next.createInstance(
{
lng: 'en',
fallbackLng: 'en',
lowerCaseLng: true,
interpolation: {
escapeValue: false,
},
resources,
});
}
},
// providing an empty callback here will automatically call init
() => {},
);
2 changes: 0 additions & 2 deletions packages/widget/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { App } from './App';
import { AppDrawer } from './AppDrawer';
import './fonts/inter.css';
import { configureReactI18next } from './i18n';

export type { WidgetDrawer } from './AppDrawer';
export { useWidgetEvents } from './hooks';
export * from './types';

configureReactI18next();
// ClassNameGenerator.configure((componentName) =>
// componentName.replace('Mui', 'LiFi'),
// );
Expand Down

0 comments on commit e2ff741

Please sign in to comment.