From 484f06c5d84392aa21899cbb29d7609e97657121 Mon Sep 17 00:00:00 2001 From: emergent-agent-e1 Date: Sun, 9 Nov 2025 15:56:29 +0000 Subject: [PATCH] auto-commit for d1350030-67b3-46a0-ac98-957d7e3d36a5 --- frontend/src/contexts/LanguageContext.tsx | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/frontend/src/contexts/LanguageContext.tsx b/frontend/src/contexts/LanguageContext.tsx index 58574f33..21a9b6d8 100644 --- a/frontend/src/contexts/LanguageContext.tsx +++ b/frontend/src/contexts/LanguageContext.tsx @@ -1,4 +1,4 @@ -import React, { createContext, useContext, useState, useEffect, ReactNode } from 'react'; +import React, { createContext, useContext, useState, useEffect, ReactNode, useMemo, useCallback } from 'react'; import AsyncStorage from '@react-native-async-storage/async-storage'; import { translations, supportedLocales } from '../config/i18n'; @@ -32,16 +32,18 @@ export function LanguageProvider({ children }: { children: ReactNode }) { } }; - const setLocale = async (newLocale: Locale) => { + const setLocale = useCallback(async (newLocale: Locale) => { try { + console.log('🌍 Setting locale to:', newLocale); await AsyncStorage.setItem(STORAGE_KEY, newLocale); setLocaleState(newLocale); + console.log('✅ Locale set successfully:', newLocale); } catch (error) { console.error('Error saving language:', error); } - }; + }, []); - const t = (key: string, params?: Record): string => { + const t = useCallback((key: string, params?: Record): string => { const keys = key.split('.'); let value: any = translations[locale]; @@ -71,10 +73,16 @@ export function LanguageProvider({ children }: { children: ReactNode }) { } return key; - }; + }, [locale]); + + const value = useMemo(() => ({ + locale, + setLocale, + t + }), [locale, setLocale, t]); return ( - + {children} );