diff --git a/frontend/src/config/i18n.ts b/frontend/src/config/i18n.ts new file mode 100644 index 00000000..f6e709f0 --- /dev/null +++ b/frontend/src/config/i18n.ts @@ -0,0 +1,124 @@ +import { I18n } from 'i18n-js'; +import * as Localization from 'expo-localization'; +import AsyncStorage from '@react-native-async-storage/async-storage'; + +const i18n = new I18n({ + en: { + welcome: 'Welcome', + home: 'Home', + wallet: 'Wallet', + citizens: 'Citizens', + referral: 'Referral', + profile: 'Profile', + settings: 'Settings', + notifications: 'Notifications', + editProfile: 'Edit Profile', + changePassword: 'Change Password', + signOut: 'Sign Out', + language: 'Language', + darkMode: 'Dark Mode', + // Add more translations + }, + 'ku-sorani': { + welcome: 'بەخێربێیت', + home: 'سەرەکی', + wallet: 'جزدان', + citizens: 'هاوڵاتیان', + referral: 'ئاماژە', + profile: 'پرۆفایل', + settings: 'ڕێکخستنەکان', + notifications: 'ئاگادارکردنەوەکان', + editProfile: 'دەستکاری پرۆفایل', + changePassword: 'گۆڕینی وشەی نهێنی', + signOut: 'چوونەدەرەوە', + language: 'زمان', + darkMode: 'دۆخی تاریک', + }, + 'ku-kurmanji': { + welcome: 'Bi xêr hatî', + home: 'Malper', + wallet: 'Berîk', + citizens: 'Hemwelatî', + referral: 'Referans', + profile: 'Profîl', + settings: 'Mîhengên', + notifications: 'Agahdarî', + editProfile: 'Profîlê Biguherîne', + changePassword: 'Şîfreyê Biguherîne', + signOut: 'Derkeve', + language: 'Ziman', + darkMode: 'Moda Tarî', + }, + ar: { + welcome: 'مرحبا', + home: 'الرئيسية', + wallet: 'المحفظة', + citizens: 'المواطنون', + referral: 'الإحالة', + profile: 'الملف الشخصي', + settings: 'الإعدادات', + notifications: 'الإشعارات', + editProfile: 'تعديل الملف الشخصي', + changePassword: 'تغيير كلمة المرور', + signOut: 'تسجيل الخروج', + language: 'اللغة', + darkMode: 'الوضع الداكن', + }, + tr: { + welcome: 'Hoş geldiniz', + home: 'Ana Sayfa', + wallet: 'Cüzdan', + citizens: 'Vatandaşlar', + referral: 'Yönlendirme', + profile: 'Profil', + settings: 'Ayarlar', + notifications: 'Bildirimler', + editProfile: 'Profili Düzenle', + changePassword: 'Şifre Değiştir', + signOut: 'Çıkış Yap', + language: 'Dil', + darkMode: 'Karanlık Mod', + }, + fa: { + welcome: 'خوش آمدید', + home: 'خانه', + wallet: 'کیف پول', + citizens: 'شهروندان', + referral: 'ارجاع', + profile: 'پروفایل', + settings: 'تنظیمات', + notifications: 'اطلاعیه‌ها', + editProfile: 'ویرایش پروفایل', + changePassword: 'تغییر رمز عبور', + signOut: 'خروج', + language: 'زبان', + darkMode: 'حالت تاریک', + }, +}); + +// Set default locale +i18n.locale = Localization.locale; +i18n.enableFallback = true; +i18n.defaultLocale = 'en'; + +export const loadSavedLanguage = async () => { + try { + const savedLang = await AsyncStorage.getItem('appLanguage'); + if (savedLang) { + i18n.locale = savedLang; + } + } catch (error) { + console.error('Error loading language:', error); + } +}; + +export const saveLanguage = async (languageCode: string) => { + try { + await AsyncStorage.setItem('appLanguage', languageCode); + i18n.locale = languageCode; + } catch (error) { + console.error('Error saving language:', error); + } +}; + +export default i18n; \ No newline at end of file diff --git a/frontend/src/contexts/ThemeContext.tsx b/frontend/src/contexts/ThemeContext.tsx new file mode 100644 index 00000000..fb96d76b --- /dev/null +++ b/frontend/src/contexts/ThemeContext.tsx @@ -0,0 +1,83 @@ +import React, { createContext, useState, useContext, useEffect } from 'react'; +import AsyncStorage from '@react-native-async-storage/async-storage'; + +interface ThemeContextType { + isDarkMode: boolean; + toggleTheme: () => void; + colors: { + background: string; + card: string; + text: string; + textSecondary: string; + primary: string; + border: string; + error: string; + }; +} + +const lightColors = { + background: '#F8F9FA', + card: '#FFFFFF', + text: '#1F2937', + textSecondary: '#6B7280', + primary: '#EE2A35', + border: '#E5E7EB', + error: '#EF4444', +}; + +const darkColors = { + background: '#111827', + card: '#1F2937', + text: '#F9FAFB', + textSecondary: '#9CA3AF', + primary: '#EE2A35', + border: '#374151', + error: '#F87171', +}; + +const ThemeContext = createContext(undefined); + +export function ThemeProvider({ children }: { children: React.ReactNode }) { + const [isDarkMode, setIsDarkMode] = useState(false); + + useEffect(() => { + loadTheme(); + }, []); + + const loadTheme = async () => { + try { + const savedTheme = await AsyncStorage.getItem('appTheme'); + if (savedTheme === 'dark') { + setIsDarkMode(true); + } + } catch (error) { + console.error('Error loading theme:', error); + } + }; + + const toggleTheme = async () => { + const newMode = !isDarkMode; + setIsDarkMode(newMode); + try { + await AsyncStorage.setItem('appTheme', newMode ? 'dark' : 'light'); + } catch (error) { + console.error('Error saving theme:', error); + } + }; + + const colors = isDarkMode ? darkColors : lightColors; + + return ( + + {children} + + ); +} + +export function useTheme() { + const context = useContext(ThemeContext); + if (context === undefined) { + throw new Error('useTheme must be used within a ThemeProvider'); + } + return context; +} \ No newline at end of file