feat(i18n): 全面实现应用核心功能模块的国际化支持
- 新增 i18n 翻译资源,覆盖睡眠、饮水、体重、锻炼、用药 AI 识别、步数、健身圆环、基础代谢及设置等核心模块 - 重构相关页面及组件(如 SleepDetail, WaterDetail, WorkoutHistory 等)使用 `useI18n` 钩子替换硬编码文本 - 升级 `utils/date` 工具库与 `DateSelector` 组件,支持基于语言环境的日期格式化与显示 - 完善登录页、注销流程及权限申请弹窗的双语提示信息 - 优化部分页面的 UI 细节与字体样式以适配多语言显示
This commit is contained in:
@@ -5,6 +5,7 @@ import { Alert } from 'react-native';
|
||||
|
||||
import { ROUTES } from '@/constants/Routes';
|
||||
import { useAppDispatch, useAppSelector } from '@/hooks/redux';
|
||||
import { useI18n } from '@/hooks/useI18n';
|
||||
import { STORAGE_KEYS, api } from '@/services/api';
|
||||
import { logout as logoutAction } from '@/store/userSlice';
|
||||
|
||||
@@ -21,6 +22,7 @@ export function useAuthGuard() {
|
||||
const dispatch = useAppDispatch();
|
||||
const currentPath = usePathname();
|
||||
const user = useAppSelector(state => state.user);
|
||||
const { t } = useI18n();
|
||||
|
||||
// 判断登录状态:优先使用 token,因为 token 是登录的根本凭证
|
||||
// profile.id 可能在初始化时还未加载,但 token 已经从 AsyncStorage 恢复
|
||||
@@ -74,28 +76,28 @@ export function useAuthGuard() {
|
||||
router.push('/auth/login');
|
||||
} catch (error) {
|
||||
console.error('退出登录失败:', error);
|
||||
Alert.alert('错误', '退出登录失败,请稍后重试');
|
||||
Alert.alert(t('authGuard.logout.error'), t('authGuard.logout.errorMessage'));
|
||||
}
|
||||
}, [dispatch, router]);
|
||||
}, [dispatch, router, t]);
|
||||
|
||||
// 带确认对话框的退出登录
|
||||
const confirmLogout = useCallback(() => {
|
||||
Alert.alert(
|
||||
'确认退出',
|
||||
'确定要退出当前账号吗?',
|
||||
t('authGuard.confirmLogout.title'),
|
||||
t('authGuard.confirmLogout.message'),
|
||||
[
|
||||
{
|
||||
text: '取消',
|
||||
text: t('authGuard.confirmLogout.cancelButton'),
|
||||
style: 'cancel',
|
||||
},
|
||||
{
|
||||
text: '确定',
|
||||
text: t('authGuard.confirmLogout.confirmButton'),
|
||||
style: 'default',
|
||||
onPress: handleLogout,
|
||||
},
|
||||
]
|
||||
);
|
||||
}, [handleLogout]);
|
||||
}, [handleLogout, t]);
|
||||
|
||||
// 注销账号功能
|
||||
const handleDeleteAccount = useCallback(async () => {
|
||||
@@ -109,38 +111,38 @@ export function useAuthGuard() {
|
||||
// 执行退出登录逻辑
|
||||
await dispatch(logoutAction()).unwrap();
|
||||
|
||||
Alert.alert('账号已注销', '您的账号已成功注销', [
|
||||
Alert.alert(t('authGuard.deleteAccount.successTitle'), t('authGuard.deleteAccount.successMessage'), [
|
||||
{
|
||||
text: '确定',
|
||||
text: t('authGuard.deleteAccount.confirmButton'),
|
||||
onPress: () => router.push('/auth/login'),
|
||||
},
|
||||
]);
|
||||
} catch (error: any) {
|
||||
console.error('注销账号失败:', error);
|
||||
const message = error?.message || '注销失败,请稍后重试';
|
||||
Alert.alert('注销失败', message);
|
||||
const message = error?.message || t('authGuard.deleteAccount.errorMessage');
|
||||
Alert.alert(t('authGuard.deleteAccount.errorTitle'), message);
|
||||
}
|
||||
}, [dispatch, router]);
|
||||
}, [dispatch, router, t]);
|
||||
|
||||
// 带确认对话框的注销账号
|
||||
const confirmDeleteAccount = useCallback(() => {
|
||||
Alert.alert(
|
||||
'确认注销账号',
|
||||
'此操作不可恢复,将删除您的账号及相关数据。确定继续吗?',
|
||||
t('authGuard.confirmDeleteAccount.title'),
|
||||
t('authGuard.confirmDeleteAccount.message'),
|
||||
[
|
||||
{
|
||||
text: '取消',
|
||||
text: t('authGuard.confirmDeleteAccount.cancelButton'),
|
||||
style: 'cancel',
|
||||
},
|
||||
{
|
||||
text: '确认注销',
|
||||
text: t('authGuard.confirmDeleteAccount.confirmButton'),
|
||||
style: 'destructive',
|
||||
onPress: handleDeleteAccount,
|
||||
},
|
||||
],
|
||||
{ cancelable: true }
|
||||
);
|
||||
}, [handleDeleteAccount]);
|
||||
}, [handleDeleteAccount, t]);
|
||||
|
||||
return {
|
||||
isLoggedIn,
|
||||
|
||||
Reference in New Issue
Block a user