mirror of
https://github.com/pezkuwichain/pezkuwi-mobile-app.git
synced 2026-05-31 01:01:00 +00:00
auto-commit for 4b34bc9d-cd30-4d24-924a-46c6cece2da1
This commit is contained in:
@@ -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;
|
||||
@@ -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<ThemeContextType | undefined>(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 (
|
||||
<ThemeContext.Provider value={{ isDarkMode, toggleTheme, colors }}>
|
||||
{children}
|
||||
</ThemeContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useTheme() {
|
||||
const context = useContext(ThemeContext);
|
||||
if (context === undefined) {
|
||||
throw new Error('useTheme must be used within a ThemeProvider');
|
||||
}
|
||||
return context;
|
||||
}
|
||||
Reference in New Issue
Block a user