feat(i18n): 增强生理周期模块的国际化支持,添加多语言格式和翻译

This commit is contained in:
richarjiang
2025-12-18 09:36:08 +08:00
parent 4836058d56
commit feb5052fcd
11 changed files with 192 additions and 52 deletions

View File

@@ -271,6 +271,9 @@ class HealthPermissionManager extends SimpleEventEmitter {
// 全局权限管理实例
export const healthPermissionManager = new HealthPermissionManager();
// 全局健康数据事件发射器
export const healthDataEvents = new SimpleEventEmitter();
// Interface for activity summary data from HealthKit
export interface HealthActivitySummary {
activeEnergyBurned: number;
@@ -1632,6 +1635,8 @@ export async function saveMenstrualFlow(
const result = await HealthKitManager.saveMenstrualFlow(options);
if (result && result.success) {
console.log('经期数据保存成功');
// 触发数据变更事件
healthDataEvents.emit('menstrualDataChanged');
return true;
}
console.error('经期数据保存失败');
@@ -1655,6 +1660,8 @@ export async function deleteMenstrualFlow(
const result = await HealthKitManager.deleteMenstrualFlow(options);
if (result && result.success) {
console.log(`经期数据删除成功,数量: ${result.count}`);
// 触发数据变更事件
healthDataEvents.emit('menstrualDataChanged');
return true;
}
console.error('经期数据删除失败');

View File

@@ -1,4 +1,6 @@
import dayjs, { Dayjs } from 'dayjs';
import 'dayjs/locale/en';
import 'dayjs/locale/zh-cn';
import { MenstrualFlowSample } from './health';
export type MenstrualDayStatus = 'period' | 'predicted-period' | 'fertile' | 'ovulation-day';
@@ -153,6 +155,9 @@ export const buildMenstrualTimeline = (options?: {
monthsAfter?: number;
defaultCycleLength?: number;
defaultPeriodLength?: number;
locale?: 'zh' | 'en';
monthTitleFormat?: string;
monthSubtitleFormat?: string;
}): MenstrualTimeline => {
const today = dayjs();
const monthsBefore = options?.monthsBefore ?? 2;
@@ -267,6 +272,11 @@ export const buildMenstrualTimeline = (options?: {
const months: MenstrualMonth[] = [];
let monthCursor = startMonth.startOf('month');
const locale = options?.locale ?? 'zh';
const localeKey = locale === 'en' ? 'en' : 'zh-cn';
const monthTitleFormat = options?.monthTitleFormat ?? (locale === 'en' ? 'MMM' : 'M月');
const monthSubtitleFormat = options?.monthSubtitleFormat ?? (locale === 'en' ? 'YYYY' : 'YYYY年');
while (monthCursor.isBefore(endMonth) || monthCursor.isSame(endMonth, 'month')) {
const firstDay = monthCursor.startOf('month');
const daysInMonth = firstDay.daysInMonth();
@@ -298,10 +308,12 @@ export const buildMenstrualTimeline = (options?: {
});
}
const formattedMonth = firstDay.locale(localeKey);
months.push({
id: firstDay.format('YYYY-MM'),
title: firstDay.format('M月'),
subtitle: firstDay.format('YYYY年'),
title: formattedMonth.format(monthTitleFormat),
subtitle: formattedMonth.format(monthSubtitleFormat),
cells,
});