From ef7ff08f4cd602f950a6eb5013a6952c13b61ee4 Mon Sep 17 00:00:00 2001 From: Xiaohan-Tian <157918347+Xiaohan-Tian@users.noreply.github.com> Date: Fri, 12 Jun 2026 12:03:32 -0700 Subject: [PATCH] fix: added missing i18n labels --- src/components/track/TrackInfoItem.test.tsx | 59 ++++++++++++++++++++- src/components/track/TrackInfoItem.tsx | 6 ++- src/i18n/messages/en_us.ts | 2 + src/i18n/messages/fr_fr.ts | 2 + src/i18n/messages/zh_cn.ts | 2 + src/i18n/messages/zh_hk.ts | 2 + 6 files changed, 69 insertions(+), 4 deletions(-) diff --git a/src/components/track/TrackInfoItem.test.tsx b/src/components/track/TrackInfoItem.test.tsx index d962264..c9a8e54 100644 --- a/src/components/track/TrackInfoItem.test.tsx +++ b/src/components/track/TrackInfoItem.test.tsx @@ -1,8 +1,10 @@ import React from 'react'; import { describe, it, expect, vi, beforeEach } from 'vitest'; -import { render } from '@testing-library/react'; +import { fireEvent, render, screen } from '@testing-library/react'; import TrackInfoItem from './TrackInfoItem'; import { KGAudioTrack } from '../../core/track/KGAudioTrack'; +import { showConfirm } from '../../util/dialogUtil'; +import { translate } from '../../i18n/translate'; const storeState = { selectedTrackId: null as string | null, @@ -24,8 +26,31 @@ vi.mock('../../stores/projectStore', () => ({ ), })); +vi.mock('../../i18n/useI18n', async () => { + const { translate } = await import('../../i18n/translate'); + return { + useI18n: () => ({ + t: (key: string, params?: Record) => translate(key, params, 'zh_cn'), + }), + }; +}); + vi.mock('../common/KGDropdown', () => ({ - default: () => null, + default: ({ options, isOpen, onChange }: { options: Array; isOpen?: boolean; onChange: (value: string) => void }) => ( + isOpen ? ( +
+ {options.map((option) => { + const value = typeof option === 'string' ? option : option.value; + const label = typeof option === 'string' ? option : option.label; + return ( + + ); + })} +
+ ) : null + ), })); vi.mock('../common/FileImportModal', () => ({ @@ -49,6 +74,7 @@ describe('TrackInfoItem audio import', () => { storeState.toggleInstrumentSelectionForTrack.mockReset(); storeState.importAudioToTrack.mockReset(); storeState.setTrackAutomationView.mockReset(); + vi.mocked(showConfirm).mockReset(); }); it('advertises m4a support in the track audio import modal', () => { @@ -72,4 +98,33 @@ describe('TrackInfoItem audio import', () => { expect(fileImportModalProps?.acceptedTypes).toEqual(['.wav', '.mp3', '.ogg', '.flac', '.aac', '.m4a']); }); + + it('uses the localized delete-track confirmation message', () => { + const audioTrack = new KGAudioTrack('钢琴', 1); + audioTrack.setTrackIndex(0); + storeState.tracks = [audioTrack]; + + vi.mocked(showConfirm).mockResolvedValue(false); + + render( + + ); + + fireEvent.click(screen.getByRole('button', { name: '更多操作' })); + fireEvent.click(screen.getByRole('button', { name: '删除轨道' })); + + expect(showConfirm).toHaveBeenCalledWith( + translate('track.controls.settings.deleteTrackConfirm', { name: '钢琴' }, 'zh_cn') + ); + }); }); diff --git a/src/components/track/TrackInfoItem.tsx b/src/components/track/TrackInfoItem.tsx index 0b49058..579aa27 100644 --- a/src/components/track/TrackInfoItem.tsx +++ b/src/components/track/TrackInfoItem.tsx @@ -360,7 +360,9 @@ const TrackInfoItem: React.FC = ({ // Handle settings action const handleSettingsAction = async (action: string) => { if (action === 'Delete Track') { - const confirmed = await showConfirm(`Are you sure you want to delete track "${track.getName()}"?`); + const confirmed = await showConfirm( + t('track.controls.settings.deleteTrackConfirm', { name: track.getName() }) + ); if (confirmed) { try { if (DEBUG_MODE.TRACK_INFO) { @@ -379,7 +381,7 @@ const TrackInfoItem: React.FC = ({ setShowSettingsDropdown(false); } catch (error) { console.error('Failed to delete track:', error); - await showAlert('Failed to delete track. Please try again.'); + await showAlert(t('track.controls.settings.deleteTrackError')); } } } diff --git a/src/i18n/messages/en_us.ts b/src/i18n/messages/en_us.ts index f2597b9..c631f81 100644 --- a/src/i18n/messages/en_us.ts +++ b/src/i18n/messages/en_us.ts @@ -539,6 +539,8 @@ export const enUsMessages: TranslationMessages = { 'track.controls.automation.pan': 'Pan', 'track.controls.moreActions': 'More actions', 'track.controls.settings.deleteTrack': 'Delete Track', + 'track.controls.settings.deleteTrackConfirm': 'Are you sure you want to delete track "{name}"?', + 'track.controls.settings.deleteTrackError': 'Failed to delete track. Please try again.', 'toolbar.keySignatureChooser': 'Choose key signature, current {value}', 'toolbar.export.label': 'Export', 'toolbar.importProject.title': 'Import Project', diff --git a/src/i18n/messages/fr_fr.ts b/src/i18n/messages/fr_fr.ts index 01c0627..c40e5ba 100644 --- a/src/i18n/messages/fr_fr.ts +++ b/src/i18n/messages/fr_fr.ts @@ -423,6 +423,8 @@ export const frFrMessages: TranslationMessages = { 'track.controls.automation.pan': 'Panoramique', 'track.controls.moreActions': 'Autres actions', 'track.controls.settings.deleteTrack': 'Supprimer la piste', + 'track.controls.settings.deleteTrackConfirm': 'Voulez-vous vraiment supprimer la piste « {name} » ?', + 'track.controls.settings.deleteTrackError': 'Impossible de supprimer la piste. Veuillez réessayer.', 'toolbar.keySignatureChooser': 'Choisir l\'armure, actuelle : {value}', 'toolbar.export.label': 'Exporter', 'toolbar.importProject.title': 'Importer un projet', diff --git a/src/i18n/messages/zh_cn.ts b/src/i18n/messages/zh_cn.ts index 7c24976..18244b4 100644 --- a/src/i18n/messages/zh_cn.ts +++ b/src/i18n/messages/zh_cn.ts @@ -537,6 +537,8 @@ export const zhCnMessages: TranslationMessages = { 'track.controls.automation.pan': '声像', 'track.controls.moreActions': '更多操作', 'track.controls.settings.deleteTrack': '删除轨道', + 'track.controls.settings.deleteTrackConfirm': '确定要删除轨道“{name}”吗?', + 'track.controls.settings.deleteTrackError': '删除轨道失败。请重试。', 'toolbar.keySignatureChooser': '选择调号,当前为 {value}', 'toolbar.export.label': '导出', 'toolbar.importProject.title': '导入项目', diff --git a/src/i18n/messages/zh_hk.ts b/src/i18n/messages/zh_hk.ts index 1356242..4b10f37 100644 --- a/src/i18n/messages/zh_hk.ts +++ b/src/i18n/messages/zh_hk.ts @@ -537,6 +537,8 @@ export const zhHkMessages: TranslationMessages = { 'track.controls.automation.pan': '聲像', 'track.controls.moreActions': '更多操作', 'track.controls.settings.deleteTrack': '刪除音軌', + 'track.controls.settings.deleteTrackConfirm': '確定要刪除音軌「{name}」嗎?', + 'track.controls.settings.deleteTrackError': '刪除音軌失敗。請再試一次。', 'toolbar.keySignatureChooser': '選擇調號,當前為 {value}', 'toolbar.export.label': '匯出', 'toolbar.importProject.title': '匯入專案',