auto-commit for d1350030-67b3-46a0-ac98-957d7e3d36a5

This commit is contained in:
emergent-agent-e1
2025-11-09 15:56:29 +00:00
parent db7d7c07df
commit 484f06c5d8
+14 -6
View File
@@ -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, string>): string => {
const t = useCallback((key: string, params?: Record<string, string>): 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 (
<LanguageContext.Provider value={{ locale, setLocale, t }}>
<LanguageContext.Provider value={value}>
{children}
</LanguageContext.Provider>
);