From 3375798b6635ba7e57ea65fa398dc64fd29a5c19 Mon Sep 17 00:00:00 2001 From: lxm <1274844347@qq.com> Date: Tue, 8 Jul 2025 12:49:01 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=9B=BD=E9=99=85=E5=8C=96):=20=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E6=9D=83=E9=99=90=E7=AE=A1=E7=90=86=E5=92=8C=E4=B8=AA?= =?UTF-8?q?=E4=BA=BA=E8=B5=84=E6=96=99=E9=A1=B5=E9=9D=A2=E7=9A=84=E7=BF=BB?= =?UTF-8?q?=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将权限管理页面中的硬编码文本替换为国际化翻译 - 在个人资料页面更新翻译文本和注释 - 在翻译文件中添加缺失的权限管理相关翻译项 - 重构权限管理页面的翻译获取逻辑 --- lib/core/translations/language/en_us.dart | 55 ++++++++++- lib/core/translations/language/zh_cn.dart | 45 ++++++++- lib/modules/profile/views/profile_view.dart | 5 +- .../settings/views/permissions_view.dart | 91 ++++++++++--------- 4 files changed, 143 insertions(+), 53 deletions(-) diff --git a/lib/core/translations/language/en_us.dart b/lib/core/translations/language/en_us.dart index f4a8d48d0..cace100bf 100644 --- a/lib/core/translations/language/en_us.dart +++ b/lib/core/translations/language/en_us.dart @@ -213,8 +213,6 @@ const Map enUS = { "privacySettingsInfo": "Manage data collection and permissions", "permissionManagement": "Permission Management", // 权限管理 "permissionManagementInfo": "Manage app permission settings", // 管理应用权限设置 - "logout": "Log Out", - "logoutTips": "Are you sure you want to log out of the current account?", "aboutApplication": "About", "versions": "Version", "checkUpdates": "Check Updates", @@ -237,9 +235,6 @@ const Map enUS = { 'selecttimbre': 'Select Timbre', 'pleaseRead': 'Please Read', 'completeRecording': 'Complete Recording', - 'deleteAccount': 'Delete Account', - 'deleteAccountTips': - 'Are you sure you want to permanently delete your account? This action cannot be undone.', "firmwareUpgrade": "Firmware Upgrade", // 固件升级 "bleHeadsetFirmwareUpgrade": "BLE Headset Firmware Upgrade", // BLE耳机固件版本升级 "deviceManagement": "Device Management", // 设备管理 @@ -260,8 +255,58 @@ const Map enUS = { // 编辑个人信息页 "editProfile": "Edit Profile", + "avatar": "Avatar", "nickname": "Nickname", "save": "Save", + "about": "About", + "enterNickname": "Please enter your nickname", + "notSet": "Not Set", + "accountSetting": "Account Setting", + "logout": "Log Out", + "logoutTips": "Are you sure you want to log out of the current account?", + 'deleteAccount': 'Delete Account', + 'deleteAccountTips': + 'Are you sure you want to permanently delete your account? This action cannot be undone.', + + // 权限管理页面 + 'getPermissionStatusFailed': 'Failed to get permission status', + 'communicationPermissions': 'Communication Permissions', + 'calendarPermissions': 'Calendar Permissions', + 'locationPermissions': 'Location Permissions', + 'phone': 'Phone', + 'sms': 'SMS', + 'calendarWrite': 'Calendar Write', + 'calendarFullAccess': 'Calendar Full Access', + 'locationInfo': 'Location Info', + 'phonePermissionDesc': 'Used for phone call functionality', + 'smsPermissionDesc': 'Used for SMS functionality', + 'calendarWritePermissionDesc': + 'Used for creating calendar events and reminders', + 'calendarFullAccessPermissionDesc': + 'Used for reading and managing calendar events and reminders', + 'locationPermissionDesc': 'Used for getting current location information', + 'appFunctionNeeds': 'App function needs', + 'authorized': 'Authorized', + 'unauthorized': 'Unauthorized', + 'needOpenInSystemSettings': 'Need to enable in system settings', + 'partialAuthorization': 'Partial Authorization', + 'unknownStatus': 'Unknown Status', + 'permissionGranted': 'Permission granted', + 'permissionRequestError': 'Error requesting permission', + 'phonePermissionDetailDesc': + 'Phone call functionality requires phone permission', + 'smsPermissionDetailDesc': 'SMS functionality requires SMS permission', + 'calendarWritePermissionDetailDesc': + 'Creating calendar events requires calendar write permission', + 'calendarFullAccessPermissionDetailDesc': + 'Managing calendar events requires full calendar permission', + 'locationPermissionDetailDesc': + 'Getting location information requires location permission', + 'appNeedsPermissionForFullFunction': + 'App needs this permission to provide full functionality', + 'permanentDenialText': + 'You have permanently denied {permission} permission, please go to app settings to enable it', + 'goToSettings': 'Go to Settings', // 国家列表 "邮箱": "Email", diff --git a/lib/core/translations/language/zh_cn.dart b/lib/core/translations/language/zh_cn.dart index 610df2165..daa683b41 100644 --- a/lib/core/translations/language/zh_cn.dart +++ b/lib/core/translations/language/zh_cn.dart @@ -208,8 +208,6 @@ const Map zhCN = { "privacySettingsInfo": "管理数据收集和权限", "permissionManagement": "权限管理", // 权限管理 "permissionManagementInfo": "管理应用权限设置", // 管理应用权限设置 - "logout": "退出登录", - "logoutTips": "确定要退出当前账号吗?", "aboutApplication": "关于应用", "versions": "版本", "checkUpdates": "检查更新", @@ -230,8 +228,6 @@ const Map zhCN = { 'selecttimbre': '选择音色', 'pleaseRead': '请朗读', 'completeRecording': '完成录制', - 'deleteAccount': '注销账号', - 'deleteAccountTips': '确定要永久删除您的账号吗?此操作不可撤销', "firmwareUpgrade": "固件升级", "bleHeadsetFirmwareUpgrade": "BLE耳机固件版本升级", "deviceManagement": "设备管理", @@ -251,8 +247,49 @@ const Map zhCN = { //编辑个人信息页 "editProfile": "编辑个人信息", + "avatar": "头像", "nickname": "昵称", "save": "保存", + "about": "关于", + "enterNickname": "请输入昵称", + "notSet": "未设置", + "accountSetting": "账号设置", + "logout": "退出登录", + "logoutTips": "确定要退出当前账号吗?", + 'deleteAccount': '注销账号', + 'deleteAccountTips': '确定要永久删除您的账号吗?此操作不可撤销', + + // 权限管理页面 + 'getPermissionStatusFailed': '获取权限状态失败', + 'communicationPermissions': '通讯权限', + 'calendarPermissions': '日历权限', + 'locationPermissions': '位置权限', + 'phone': '电话', + 'sms': '短信', + 'calendarWrite': '日历写入', + 'calendarFullAccess': '日历完整访问', + 'locationInfo': '位置信息', + 'phonePermissionDesc': '用于拨打电话功能', + 'smsPermissionDesc': '用于发送短信功能', + 'calendarWritePermissionDesc': '用于创建日历事件和提醒', + 'calendarFullAccessPermissionDesc': '用于读取和管理日历事件及提醒', + 'locationPermissionDesc': '用于获取当前位置信息', + 'appFunctionNeeds': '应用功能需要', + 'authorized': '已授权', + 'unauthorized': '未授权', + 'needOpenInSystemSettings': '需要在系统设置中开启', + 'partialAuthorization': '部分授权', + 'unknownStatus': '未知状态', + 'permissionGranted': '权限已授予', + 'permissionRequestError': '请求权限时出错', + 'phonePermissionDetailDesc': '拨打电话功能需要电话权限', + 'smsPermissionDetailDesc': '发送短信功能需要短信权限', + 'calendarWritePermissionDetailDesc': '创建日历事件需要日历写入权限', + 'calendarFullAccessPermissionDetailDesc': '管理日历事件需要完整日历权限', + 'locationPermissionDetailDesc': '获取位置信息需要位置权限', + 'appNeedsPermissionForFullFunction': '应用需要此权限以提供完整功能', + 'permanentDenialText': '您已永久拒绝{permission}权限,请前往应用设置开启', + 'goToSettings': '去设置', //国家列表 "邮箱": "邮箱", diff --git a/lib/modules/profile/views/profile_view.dart b/lib/modules/profile/views/profile_view.dart index 41666b35c..2876733c5 100644 --- a/lib/modules/profile/views/profile_view.dart +++ b/lib/modules/profile/views/profile_view.dart @@ -233,7 +233,7 @@ class EditProfileView extends GetView { Padding( padding: EdgeInsets.only(left: 4.w, bottom: 8.h), child: Text( - 'editProfile'.tr, // 编辑资料 + 'editProfile'.tr, // 编辑个人信息 style: TextStyle( fontSize: 12.sp, fontWeight: FontWeight.w500, @@ -461,7 +461,8 @@ class EditProfileView extends GetView { Widget _buildNicknameEditingMode(BuildContext context, bool isDarkMode, TextEditingController nameController) { return Padding( - padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 16.h), // 与显示模式保持一致的padding + padding: EdgeInsets.symmetric( + horizontal: 16.w, vertical: 16.h), // 与显示模式保持一致的padding child: Row( children: [ // 图标 - 保持与显示模式相同的绿色主题 diff --git a/lib/modules/settings/views/permissions_view.dart b/lib/modules/settings/views/permissions_view.dart index ee0d27311..97d98dd20 100644 --- a/lib/modules/settings/views/permissions_view.dart +++ b/lib/modules/settings/views/permissions_view.dart @@ -27,7 +27,7 @@ class PermissionsView extends GetView { onPressed: () => Get.back(), ), title: Text( - '权限管理'.tr, + 'permissionManagement'.tr, // 权限管理 style: TextStyle( fontSize: 17.sp, fontWeight: FontWeight.w600, @@ -44,7 +44,9 @@ class PermissionsView extends GetView { } if (snapshot.hasError) { - return Center(child: Text('获取权限状态失败: ${snapshot.error}'.tr)); + return Center( + child: Text('getPermissionStatusFailed'.tr + + ': ${snapshot.error}')); // 获取权限状态失败 } final permissionStatuses = snapshot.data ?? {}; @@ -54,7 +56,7 @@ class PermissionsView extends GetView { children: [ // 通讯权限组 _buildPermissionSection( - '通讯权限', + 'communicationPermissions'.tr, // 通讯权限 Icons.phone_android, [Permission.phone, Permission.sms], permissionStatuses, @@ -64,7 +66,7 @@ class PermissionsView extends GetView { // 日历权限组 _buildPermissionSection( - '日历权限', + 'calendarPermissions'.tr, // 日历权限 Icons.calendar_today, [Permission.calendarFullAccess], permissionStatuses, @@ -73,8 +75,12 @@ class PermissionsView extends GetView { SizedBox(height: 20.h), // 位置权限组 - _buildPermissionSection('位置权限', Icons.location_on, - [Permission.location], permissionStatuses, isDarkMode), + _buildPermissionSection( + 'locationPermissions'.tr, // 位置权限 + Icons.location_on, + [Permission.location], + permissionStatuses, + isDarkMode), ], ); }, @@ -147,15 +153,15 @@ class PermissionsView extends GetView { String getName(Permission permission) { switch (permission) { case Permission.phone: - return '电话'; + return 'phone'.tr; // 电话 case Permission.sms: - return '短信'; + return 'sms'.tr; // 短信 case Permission.calendarFullAccess: - return '日历写入'; + return 'calendarWrite'.tr; // 日历写入 case Permission.calendarFullAccess: - return '日历完整访问'; + return 'calendarFullAccess'.tr; // 日历完整访问 case Permission.location: - return '位置信息'; + return 'locationInfo'.tr; // 位置信息 default: return permission.toString(); } @@ -165,17 +171,17 @@ class PermissionsView extends GetView { String getDescription(Permission permission) { switch (permission) { case Permission.phone: - return '用于拨打电话功能'; + return 'phonePermissionDesc'.tr; // 用于拨打电话功能 case Permission.sms: - return '用于发送短信功能'; + return 'smsPermissionDesc'.tr; // 用于发送短信功能 case Permission.calendarFullAccess: - return '用于创建日历事件和提醒'; + return 'calendarWritePermissionDesc'.tr; // 用于创建日历事件和提醒 case Permission.calendarFullAccess: - return '用于读取和管理日历事件及提醒'; + return 'calendarFullAccessPermissionDesc'.tr; // 用于读取和管理日历事件及提醒 case Permission.location: - return '用于获取当前位置信息'; + return 'locationPermissionDesc'.tr; // 用于获取当前位置信息 default: - return '应用功能需要'; + return 'appFunctionNeeds'.tr; // 应用功能需要 } } @@ -265,19 +271,19 @@ class PermissionsView extends GetView { Color color; if (status.isGranted) { - text = '已授权'.tr; + text = 'authorized'.tr; // 已授权 color = Colors.green; } else if (status.isDenied) { - text = '未授权'.tr; + text = 'unauthorized'.tr; // 未授权 color = Colors.red; } else if (status.isPermanentlyDenied) { - text = '需要在系统设置中开启'.tr; + text = 'needOpenInSystemSettings'.tr; // 需要在系统设置中开启 color = Colors.orange; } else if (status.isLimited) { - text = '部分授权'.tr; + text = 'partialAuthorization'.tr; // 部分授权 color = Colors.orange; } else { - text = '未知状态'.tr; + text = 'unknownStatus'.tr; // 未知状态 color = Colors.grey; } @@ -299,7 +305,7 @@ class PermissionsView extends GetView { // if (context == null) return; final permissionName = _getPermissionName(permission); - final explanationText = _getExplanationText(permission); + final explanationText = getDetailedDescription(permission); // 使用 PermissionUtil 请求权限 final hasPermission = await PermissionUtil.instance.requestPermission( @@ -307,15 +313,16 @@ class PermissionsView extends GetView { permissionType: permission, permissionName: permissionName, explanationText: explanationText, - permanentDenialText: '您已永久拒绝$permissionName权限,请前往应用设置开启', - settingsButtonText: '去设置', - cancelButtonText: '取消', + permanentDenialText: 'permanentDenialText'.tr.replaceAll( + '{permission}', permissionName), // 您已永久拒绝{permission}权限,请前往应用设置开启 + settingsButtonText: 'goToSettings'.tr, // 去设置 + cancelButtonText: 'cancel'.tr, // 取消 ); if (hasPermission) { Get.snackbar( - '成功'.tr, - '$permissionName权限已授予'.tr, + 'success'.tr, // 成功 + 'permissionGranted'.tr, // 权限已授予 snackPosition: SnackPosition.BOTTOM, backgroundColor: Colors.green, colorText: Colors.white, @@ -326,8 +333,8 @@ class PermissionsView extends GetView { Get.forceAppUpdate(); } catch (e) { Get.snackbar( - '错误'.tr, - '请求权限时出错: $e'.tr, + 'error'.tr, // 错误 + 'permissionRequestError'.tr, // 请求权限时出错 snackPosition: SnackPosition.BOTTOM, backgroundColor: Colors.red, colorText: Colors.white, @@ -339,35 +346,35 @@ class PermissionsView extends GetView { String _getPermissionName(Permission permission) { switch (permission) { case Permission.phone: - return '电话'; + return 'phone'.tr; // 电话 case Permission.sms: - return '短信'; + return 'sms'.tr; // 短信 case Permission.calendarFullAccess: - return '日历写入'; + return 'calendarWrite'.tr; // 日历写入 case Permission.calendarFullAccess: - return '日历完整访问'; + return 'calendarFullAccess'.tr; // 日历完整访问 case Permission.location: - return '位置信息'; + return 'locationInfo'.tr; // 位置信息 default: return permission.toString(); } } // 获取权限说明文本 - String _getExplanationText(Permission permission) { + String getDetailedDescription(Permission permission) { switch (permission) { case Permission.phone: - return '拨打电话功能需要电话权限'; + return 'phonePermissionDetailDesc'.tr; // 拨打电话功能需要电话权限 case Permission.sms: - return '发送短信功能需要短信权限'; + return 'smsPermissionDetailDesc'.tr; // 发送短信功能需要短信权限 case Permission.calendarFullAccess: - return '创建日历事件需要日历写入权限'; + return 'calendarWritePermissionDetailDesc'.tr; // 创建日历事件需要日历写入权限 case Permission.calendarFullAccess: - return '管理日历事件需要完整日历权限'; + return 'calendarFullAccessPermissionDetailDesc'.tr; // 管理日历事件需要完整日历权限 case Permission.location: - return '获取位置信息需要位置权限'; + return 'locationPermissionDetailDesc'.tr; // 获取位置信息需要位置权限 default: - return '应用需要此权限以提供完整功能'; + return 'appNeedsPermissionForFullFunction'.tr; // 应用需要此权限以提供完整功能 } } }