Skip to content

Commit

Permalink
refactor: change i18n exported members
Browse files Browse the repository at this point in the history
  • Loading branch information
brunomous committed Jul 31, 2024
1 parent 00e763f commit c32310e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { render, fireEvent } from '@testing-library/react';

import LanguageSwitcher from '../src/components/LanguageSwitcher';

import { i18n } from '../src/utils/i18n';
import { i18nInstance } from '../src/utils/i18n';

describe('LanguageSwitcher component', () => {
const languages = Object.keys(i18n.store.data);
const languages = Object.keys(i18nInstance.store.data);

const options: string[] = ['en-US', 'pt-BR'];

Expand Down Expand Up @@ -66,6 +66,6 @@ describe('LanguageSwitcher component', () => {

fireEvent.click(option2);

expect(i18n.language).toBe(options[1]);
expect(i18nInstance.language).toBe(options[1]);
});
});
18 changes: 16 additions & 2 deletions packages/react-material-ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,22 @@ export { default as OtpInput } from './components/OtpInput';

export { default as Breadcrumbs } from './components/Breadcrumbs';

import { i18n, useTranslation, setI18n } from './utils/i18n';
export { i18n, useTranslation, setI18n };
import {
useTranslation,
addResource,
addResources,
addResourceBundle,
setI18n,
i18nInstance,
} from './utils/i18n';
export {
useTranslation,
addResource,
addResources,
addResourceBundle,
setI18n,
i18nInstance,
};

import LanguageSwitcher from './components/LanguageSwitcher';
export { LanguageSwitcher };
22 changes: 10 additions & 12 deletions packages/react-material-ui/src/utils/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import type { i18n as I18n } from 'i18next';

import i18n from 'i18next';
import i18next from 'i18next';
import {
initReactI18next,
useTranslation,
setI18n,
getI18n,
setI18n,
} from 'react-i18next';
import LanguageDetector from 'i18next-browser-languagedetector';

import locales from './locales';

i18n
// const DEFAULT_NAMESPACE = 'translation';

i18next
.use(LanguageDetector)
.use(initReactI18next)
.init({
Expand All @@ -26,18 +26,16 @@ i18n
},
});

const addResource = getI18n().addResource;

const addResources = getI18n().addResources;

const addResourceBundle = getI18n().addResourceBundle;
const i18nInstance = getI18n();
const addResource = i18nInstance.addResource;
const addResources = i18nInstance.addResources;
const addResourceBundle = i18nInstance.addResourceBundle;

export {
type I18n,
i18n,
useTranslation,
addResource,
addResources,
addResourceBundle,
setI18n,
i18nInstance,
};

0 comments on commit c32310e

Please sign in to comment.