Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzod-davlatov committed Sep 1, 2023
1 parent b21f764 commit 87cf695
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
31 changes: 2 additions & 29 deletions frontend/src/application.jsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,17 @@
import { configureStore } from '@reduxjs/toolkit';
import * as Sentry from '@sentry/react';
import i18next from 'i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import { initReactI18next } from 'react-i18next';
import { Provider } from 'react-redux';
import { BrowserRouter } from 'react-router-dom';

import AppRoutes from './AppRoutes.jsx';
import ModalWindow from './components/Modals';
import resources from './locales';
import AuthProvider from './providers/AuthProvider.jsx';
import SnippetsProvider from './providers/SnippetsProvider.jsx';
import { rootReducer } from './slices';
import { initI18next } from './initI18next.js';

export default async () => {
const defaultLanguage = 'ru';
const baseI18NextConfig = { debug: false, resources };

if (process.env.NODE_ENV === 'production') {
await i18next
.use(LanguageDetector)
.use(initReactI18next)
.init({ ...baseI18NextConfig, fallbackLng: defaultLanguage });
}

if (
process.env.NODE_ENV === 'development' &&
!process.env.REACT_APP_NODE_ENV
) {
await i18next
.use(LanguageDetector)
.use(initReactI18next)
.init(baseI18NextConfig);
}

if (process.env.REACT_APP_NODE_ENV === 'test') {
await i18next
.use(initReactI18next)
.init({ ...baseI18NextConfig, lng: defaultLanguage });
}
initI18next();

const store = configureStore({
reducer: rootReducer,
Expand Down
5 changes: 1 addition & 4 deletions frontend/src/hooks/useLanguage.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { useTranslation } from 'react-i18next';
import { useLayoutEffect, useState } from 'react';

const AVAILABLE_LANGUAGES = ['en', 'ru'];
if (process.env.NODE_ENV !== 'production') {
AVAILABLE_LANGUAGES.push('dev');
}
import { AVAILABLE_LANGUAGES } from '../initI18next';

const useLanguage = () => {
const { i18n } = useTranslation();
Expand Down
28 changes: 28 additions & 0 deletions frontend/src/initI18next.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import i18next from 'i18next';
import LanguageDetector from 'i18next-browser-languagedetector';
import { initReactI18next } from 'react-i18next';

import resources from './locales';

const defaultLanguage = 'ru';
const baseI18NextConfig = {
debug: process.env.NODE_ENV === 'development',
resources,
};

export const AVAILABLE_LANGUAGES = ['en', 'ru'];

export const initI18next = async () => {
if (process.env.REACT_APP_NODE_ENV === 'test') {
await i18next
.use(initReactI18next)
.init({ ...baseI18NextConfig, lng: defaultLanguage });

return;
}

await i18next
.use(LanguageDetector)
.use(initReactI18next)
.init({ ...baseI18NextConfig, fallbackLng: defaultLanguage });
};

0 comments on commit 87cf695

Please sign in to comment.