Skip to content

Commit

Permalink
i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieljablonski committed May 13, 2022
1 parent 45b3f29 commit 2a22597
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
3 changes: 3 additions & 0 deletions public/locales/en/general.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"home": "Home"
}
3 changes: 3 additions & 0 deletions public/locales/pt/general.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"home": "Página inicial"
}
6 changes: 5 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import React from 'react';
import ReactDOM from 'react-dom';

import 'services/i18n';
import App from './App';
import * as serviceWorker from './serviceWorker';

ReactDOM.render(
<React.StrictMode>
<App />
<React.Suspense fallback={<div />}>
<App />
</React.Suspense>
</React.StrictMode>,
document.getElementById('root'),
);
Expand Down
24 changes: 24 additions & 0 deletions src/services/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import i18next from 'i18next';
import { initReactI18next } from 'react-i18next';
import HttpApi from 'i18next-http-backend';
import LanguageDetector from 'i18next-browser-languagedetector';

i18next
.use(initReactI18next)
.use(HttpApi)
.use(LanguageDetector)
.init({
supportedLngs: ['en', 'pt', 'es'],
fallbackLng: 'pt',
nonExplicitSupportedLngs: true,
ns: ['general'],
defaultNS: 'general',
interpolation: {
escapeValue: false,
},
backend: {
loadPath: `${process.env.PUBLIC_URL}/locales/{{lng}}/{{ns}}.json`,
},
});

export default i18next;
5 changes: 4 additions & 1 deletion src/services/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export { };
import i18next from './i18n';

// eslint-disable-next-line import/prefer-default-export
export { i18next };

0 comments on commit 2a22597

Please sign in to comment.