Skip to content

Commit

Permalink
refactor: separate local and locize i18n inits (#7)
Browse files Browse the repository at this point in the history
* refactor: separate local and locize i18n inits
  • Loading branch information
ahmedcognite authored Jan 1, 2024
1 parent 465c771 commit cfa65a5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
7 changes: 3 additions & 4 deletions apps/asdf/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ export function App() {
return (
<div>
<Button
onClick={() => {
console.log(language);
language === 'en' ? changeLanguage('nb') : changeLanguage('en');
}}
onClick={() =>
language === 'en' ? changeLanguage('nb') : changeLanguage('en')
}
>
{t('generic_button_text')}
</Button>
Expand Down
5 changes: 4 additions & 1 deletion apps/asdf/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import * as ReactDOM from 'react-dom/client';

import App from './app';

import './translations/i18n';
import './translations/i18nWithLocize';
// uncomment if you want to use local translation files
// and comment the above import
// import './translations/i18nLocal';

const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement
Expand Down
19 changes: 19 additions & 0 deletions apps/asdf/src/translations/i18nLocal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';

import enJSON from './locale/en.json';
import nbJSON from './locale/nb.json';

export const initI18n = () => {
i18n.use(initReactI18next).init({
resources: {
// Where we're gonna put translations' files
en: { ...enJSON },
nb: { ...nbJSON },
},
lng: 'en', // Set the initial language of the App
fallbackLng: 'en', // Set the initial language of the App
});
};

initI18n();
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,10 @@ import { initReactI18next } from 'react-i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import LocizeBackend from 'i18next-locize-backend';

// import enJSON from './locale/en.json';
// import nbJSON from './locale/nb.json';

const LOCIZE_PROJECT_ID = process.env.LOCIZE_PROJECT_ID;
const LOCIZE_API_KEY = process.env.LOCIZE_API_KEY;

export const initI18n = () => {
// i18n.use(initReactI18next).init({
// resources: {
// // Where we're gonna put translations' files
// en: { ...enJSON },
// nb: { ...nbJSON },
// },
// lng: 'en', // Set the initial language of the App
// fallbackLng: 'en', // Set the initial language of the App
// });

// taken from:
// https://github.com/locize/react-tutorial/blob/main/step_2/src/i18n.js
i18n
Expand Down

0 comments on commit cfa65a5

Please sign in to comment.