Add Chinese translations for medication management and personal settings
- Introduced new translation files for medication, personal, and weight management in Chinese. - Updated the main index file to include the new translation modules. - Enhanced the medication type definitions to include 'ointment'. - Refactored workout type labels to utilize i18n for better localization support. - Improved sleep quality descriptions and recommendations with i18n integration.
This commit is contained in:
182
utils/health.ts
182
utils/health.ts
@@ -1,5 +1,6 @@
|
||||
import dayjs from 'dayjs';
|
||||
import { AppState, AppStateStatus, NativeModules } from 'react-native';
|
||||
import i18n from '../i18n';
|
||||
import { SimpleEventEmitter } from './SimpleEventEmitter';
|
||||
|
||||
type HealthDataOptions = {
|
||||
@@ -1901,102 +1902,9 @@ export function formatWorkoutDistance(distanceInMeters: number): string {
|
||||
}
|
||||
}
|
||||
|
||||
const WORKOUT_TYPE_LABELS: Record<string, string> = {
|
||||
running: '跑步',
|
||||
walking: '步行',
|
||||
cycling: '骑行',
|
||||
swimming: '游泳',
|
||||
yoga: '瑜伽',
|
||||
pilates: '普拉提',
|
||||
functionalstrengthtraining: '功能性力量训练',
|
||||
traditionalstrengthtraining: '传统力量训练',
|
||||
crosstraining: '交叉训练',
|
||||
mixedcardio: '混合有氧',
|
||||
highintensityintervaltraining: '高强度间歇训练',
|
||||
flexibility: '柔韧性训练',
|
||||
cooldown: '放松运动',
|
||||
dance: '舞蹈',
|
||||
danceinspiredtraining: '舞蹈训练',
|
||||
cardiodance: '有氧舞蹈',
|
||||
socialdance: '社交舞',
|
||||
swimbikerun: '铁人三项',
|
||||
transition: '项目转换',
|
||||
underwaterdiving: '水下潜水',
|
||||
pickleball: '匹克球',
|
||||
americanfootball: '美式橄榄球',
|
||||
australianfootball: '澳式橄榄球',
|
||||
archery: '射箭',
|
||||
badminton: '羽毛球',
|
||||
baseball: '棒球',
|
||||
basketball: '篮球',
|
||||
bowling: '保龄球',
|
||||
boxing: '拳击',
|
||||
climbing: '攀岩',
|
||||
cricket: '板球',
|
||||
curling: '冰壶',
|
||||
elliptical: '椭圆机',
|
||||
equestriansports: '马术',
|
||||
fencing: '击剑',
|
||||
fishing: '钓鱼',
|
||||
golf: '高尔夫',
|
||||
gymnastics: '体操',
|
||||
handball: '手球',
|
||||
hiking: '徒步',
|
||||
hockey: '曲棍球',
|
||||
hunting: '狩猎',
|
||||
lacrosse: '长曲棍球',
|
||||
martialarts: '武术',
|
||||
mindandbody: '身心运动',
|
||||
mixedmetaboliccardiotraining: '混合代谢有氧训练',
|
||||
paddlesports: '桨类运动',
|
||||
play: '自由活动',
|
||||
preparationandrecovery: '准备与恢复',
|
||||
racquetball: '壁球',
|
||||
rowing: '划船',
|
||||
rugby: '橄榄球',
|
||||
sailing: '帆船',
|
||||
skatingsports: '滑冰运动',
|
||||
snowsports: '雪上运动',
|
||||
soccer: '足球',
|
||||
softball: '垒球',
|
||||
squash: '壁球',
|
||||
stairclimbing: '爬楼梯',
|
||||
surfing: '冲浪',
|
||||
surfingsports: '冲浪运动',
|
||||
tabletennis: '乒乓球',
|
||||
tennis: '网球',
|
||||
trackandfield: '田径',
|
||||
volleyball: '排球',
|
||||
waterfitness: '水中健身',
|
||||
watersports: '水上运动',
|
||||
weighttraining: '重量训练',
|
||||
wrestling: '摔跤',
|
||||
barre: '芭蕾杆训练',
|
||||
corebTraining: '核心训练',
|
||||
jumprope: '跳绳',
|
||||
kickboxing: '踢拳',
|
||||
taichi: '太极',
|
||||
taichichuan: '太极拳',
|
||||
nordicwalking: '北欧式行走',
|
||||
frisbee: '飞盘',
|
||||
ultimatefrisbee: '极限飞盘',
|
||||
mountainbiking: '山地自行车',
|
||||
roadcycling: '公路骑行',
|
||||
virtualrunning: '虚拟跑步',
|
||||
virtualcycling: '虚拟骑行',
|
||||
trailrunning: '越野跑',
|
||||
treadmillrunning: '跑步机跑步',
|
||||
trackrunning: '场地跑',
|
||||
openwaterswimming: '公开水域游泳',
|
||||
poolswimming: '游泳池游泳',
|
||||
apneadiving: '自由潜',
|
||||
functionalStrengthTraining: '功能性力量训练',
|
||||
other: '其他运动',
|
||||
};
|
||||
|
||||
function humanizeWorkoutTypeKey(raw: string | undefined): string {
|
||||
if (!raw) {
|
||||
return '其他运动';
|
||||
return i18n.t('workoutTypes.other');
|
||||
}
|
||||
|
||||
const cleaned = raw
|
||||
@@ -2005,7 +1913,7 @@ function humanizeWorkoutTypeKey(raw: string | undefined): string {
|
||||
.trim();
|
||||
|
||||
if (!cleaned) {
|
||||
return '其他运动';
|
||||
return i18n.t('workoutTypes.other');
|
||||
}
|
||||
|
||||
const withSpaces = cleaned.replace(/([a-z0-9])([A-Z])/g, '$1 $2');
|
||||
@@ -2021,77 +1929,25 @@ function humanizeWorkoutTypeKey(raw: string | undefined): string {
|
||||
export function getWorkoutTypeDisplayName(workoutType: WorkoutActivityType | string): string {
|
||||
if (typeof workoutType === 'string') {
|
||||
const normalized = workoutType.replace(/\s+/g, '').toLowerCase();
|
||||
return WORKOUT_TYPE_LABELS[normalized] || humanizeWorkoutTypeKey(workoutType);
|
||||
// 尝试从翻译中获取
|
||||
const translationKey = `workoutTypes.${normalized}`;
|
||||
if (i18n.exists(translationKey)) {
|
||||
return i18n.t(translationKey);
|
||||
}
|
||||
return humanizeWorkoutTypeKey(workoutType);
|
||||
}
|
||||
|
||||
switch (workoutType) {
|
||||
case WorkoutActivityType.Running:
|
||||
return '跑步';
|
||||
case WorkoutActivityType.Cycling:
|
||||
return '骑行';
|
||||
case WorkoutActivityType.Walking:
|
||||
return '步行';
|
||||
case WorkoutActivityType.Swimming:
|
||||
return '游泳';
|
||||
case WorkoutActivityType.Yoga:
|
||||
return '瑜伽';
|
||||
case WorkoutActivityType.FunctionalStrengthTraining:
|
||||
return '功能性力量训练';
|
||||
case WorkoutActivityType.TraditionalStrengthTraining:
|
||||
return '传统力量训练';
|
||||
case WorkoutActivityType.CrossTraining:
|
||||
return '交叉训练';
|
||||
case WorkoutActivityType.MixedCardio:
|
||||
return '混合有氧';
|
||||
case WorkoutActivityType.HighIntensityIntervalTraining:
|
||||
return '高强度间歇训练';
|
||||
case WorkoutActivityType.Flexibility:
|
||||
return '柔韧性训练';
|
||||
case WorkoutActivityType.Cooldown:
|
||||
return '放松运动';
|
||||
case WorkoutActivityType.Tennis:
|
||||
return '网球';
|
||||
case WorkoutActivityType.Basketball:
|
||||
return '篮球';
|
||||
case WorkoutActivityType.Soccer:
|
||||
return '足球';
|
||||
case WorkoutActivityType.Baseball:
|
||||
return '棒球';
|
||||
case WorkoutActivityType.Volleyball:
|
||||
return '排球';
|
||||
case WorkoutActivityType.Dance:
|
||||
return '舞蹈';
|
||||
case WorkoutActivityType.DanceInspiredTraining:
|
||||
return '舞蹈训练';
|
||||
case WorkoutActivityType.Elliptical:
|
||||
return '椭圆机';
|
||||
case WorkoutActivityType.Rowing:
|
||||
return '划船';
|
||||
case WorkoutActivityType.StairClimbing:
|
||||
return '爬楼梯';
|
||||
case WorkoutActivityType.Hiking:
|
||||
return '徒步';
|
||||
case WorkoutActivityType.Climbing:
|
||||
return '攀岩';
|
||||
case WorkoutActivityType.MindAndBody:
|
||||
return '身心运动';
|
||||
case WorkoutActivityType.MartialArts:
|
||||
return '武术';
|
||||
case WorkoutActivityType.Golf:
|
||||
return '高尔夫';
|
||||
case WorkoutActivityType.Boxing:
|
||||
return '拳击';
|
||||
case WorkoutActivityType.SnowSports:
|
||||
return '雪上运动';
|
||||
case WorkoutActivityType.SurfingSports:
|
||||
return '冲浪运动';
|
||||
case WorkoutActivityType.WaterFitness:
|
||||
return '水中健身';
|
||||
case WorkoutActivityType.Other:
|
||||
return '其他运动';
|
||||
default:
|
||||
return humanizeWorkoutTypeKey(WorkoutActivityType[workoutType]);
|
||||
// 使用枚举值查找对应的字符串键
|
||||
const enumKey = WorkoutActivityType[workoutType];
|
||||
if (enumKey) {
|
||||
const normalized = enumKey.toLowerCase();
|
||||
const translationKey = `workoutTypes.${normalized}`;
|
||||
if (i18n.exists(translationKey)) {
|
||||
return i18n.t(translationKey);
|
||||
}
|
||||
}
|
||||
|
||||
return humanizeWorkoutTypeKey(WorkoutActivityType[workoutType]);
|
||||
}
|
||||
|
||||
// 测试锻炼记录获取功能
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useI18n } from '@/hooks/useI18n';
|
||||
import dayjs from 'dayjs';
|
||||
import HealthKitManager, { HealthKitUtils } from './healthKit';
|
||||
|
||||
@@ -340,25 +341,27 @@ export const calculateSleepScore = (
|
||||
* 获取睡眠质量描述和建议
|
||||
*/
|
||||
export const getSleepQualityInfo = (sleepScore: number): { description: string; recommendation: string } => {
|
||||
const { t } = useI18n();
|
||||
|
||||
if (sleepScore >= 85) {
|
||||
return {
|
||||
description: '你身心愉悦并且精力充沛',
|
||||
recommendation: '恭喜你获得优质的睡眠!如果你感到精力充沛,可以考虑中等强度的运动,以维持健康的生活方式,并进一步减轻压力,以获得最佳睡眠。'
|
||||
description: t('sleepQuality.excellent.description'),
|
||||
recommendation: t('sleepQuality.excellent.recommendation')
|
||||
};
|
||||
} else if (sleepScore >= 70) {
|
||||
return {
|
||||
description: '睡眠质量良好,精神状态不错',
|
||||
recommendation: '你的睡眠质量还不错,但还有改善空间。建议保持规律的睡眠时间,睡前避免使用电子设备,营造安静舒适的睡眠环境。'
|
||||
description: t('sleepQuality.good.description'),
|
||||
recommendation: t('sleepQuality.good.recommendation')
|
||||
};
|
||||
} else if (sleepScore >= 50) {
|
||||
return {
|
||||
description: '睡眠质量一般,可能影响日间表现',
|
||||
recommendation: '你的睡眠需要改善。建议制定固定的睡前例行程序,限制咖啡因摄入,确保卧室温度适宜,考虑进行轻度运动来改善睡眠质量。'
|
||||
description: t('sleepQuality.fair.description'),
|
||||
recommendation: t('sleepQuality.fair.recommendation')
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
description: '睡眠质量较差,建议重视睡眠健康',
|
||||
recommendation: '你的睡眠质量需要严重关注。建议咨询医生或睡眠专家,检查是否有睡眠障碍,同时改善睡眠环境和习惯,避免睡前刺激性活动。'
|
||||
description: t('sleepQuality.poor.description'),
|
||||
recommendation: t('sleepQuality.poor.recommendation')
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user