chore: t function removed from context and i18n config moved to a seperated file
This commit is contained in:
@@ -4,12 +4,10 @@ import { createContext } from 'react';
|
|||||||
export interface LangaugeContextModel {
|
export interface LangaugeContextModel {
|
||||||
language: Language;
|
language: Language;
|
||||||
changeLanguage: (langauge: Language) => void;
|
changeLanguage: (langauge: Language) => void;
|
||||||
t: (key: string) => string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The context is used by the LangaugeProvider
|
// The context is used by the LangaugeProvider
|
||||||
export const LangaugeContext = createContext<LangaugeContextModel>({
|
export const LangaugeContext = createContext<LangaugeContextModel>({
|
||||||
language: 'fa',
|
language: 'fa',
|
||||||
changeLanguage: () => {},
|
changeLanguage: () => {},
|
||||||
t: () => '',
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { StrictMode } from 'react';
|
import { StrictMode } from 'react';
|
||||||
import { createRoot } from 'react-dom/client';
|
import { createRoot } from 'react-dom/client';
|
||||||
import './index.css';
|
import './index.css';
|
||||||
import './i18n';
|
import './lib/i18n';
|
||||||
import App from './App';
|
import App from './App';
|
||||||
import { LanguageProvider } from './providers/LanguageProvider';
|
import { LanguageProvider } from './providers/LanguageProvider';
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import type { Language } from '@/types/language';
|
import type { Language } from '@/types/language';
|
||||||
import { changeLanguage } from 'i18next';
|
import { changeLanguage } from 'i18next';
|
||||||
import { useLayoutEffect, type JSX, type PropsWithChildren } from 'react';
|
import { useLayoutEffect, type JSX, type PropsWithChildren } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
import { useLocalStorage } from '@/hooks/useLocalStorage';
|
import { useLocalStorage } from '@/hooks/useLocalStorage';
|
||||||
import { LangaugeContext } from '@/contexts/LangaugeContext';
|
import { LangaugeContext } from '@/contexts/LangaugeContext';
|
||||||
|
|
||||||
@@ -10,7 +9,6 @@ export const LanguageProvider = (props: PropsWithChildren): JSX.Element => {
|
|||||||
'language',
|
'language',
|
||||||
'fa',
|
'fa',
|
||||||
);
|
);
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
changeLanguage(currentLanguage);
|
changeLanguage(currentLanguage);
|
||||||
@@ -23,7 +21,6 @@ export const LanguageProvider = (props: PropsWithChildren): JSX.Element => {
|
|||||||
value={{
|
value={{
|
||||||
language: currentLanguage,
|
language: currentLanguage,
|
||||||
changeLanguage: setCurrentLangauge,
|
changeLanguage: setCurrentLangauge,
|
||||||
t: t,
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{props.children}
|
{props.children}
|
||||||
|
|||||||
Reference in New Issue
Block a user