feat(localization): enhance toast messages for recipes and example images with improved error handling and success feedback

This commit is contained in:
Will Miao
2025-08-31 13:51:37 +08:00
parent e60a579b85
commit 987b8c8742
11 changed files with 134 additions and 65 deletions

View File

@@ -283,13 +283,13 @@ export class DownloadManager {
async proceedToLocation() {
if (!this.currentVersion) {
showToast('Please select a version', 'error');
showToast('toast.loras.pleaseSelectVersion', {}, 'error');
return;
}
const existsLocally = this.currentVersion.existsLocally;
if (existsLocally) {
showToast('This version already exists in your library', 'info');
showToast('toast.loras.versionExists', {}, 'info');
return;
}
@@ -480,7 +480,7 @@ export class DownloadManager {
downloadId
);
showToast('Download completed successfully', 'success');
showToast('toast.loras.downloadCompleted', {}, 'success');
modalManager.closeModal('downloadModal');
ws.close();
@@ -523,11 +523,11 @@ export class DownloadManager {
await this.folderTreeManager.loadTree(treeData.tree);
} else {
console.error('Failed to fetch folder tree:', treeData.error);
showToast('Failed to load folder tree', 'error');
showToast('toast.import.folderTreeFailed', {}, 'error');
}
} catch (error) {
console.error('Error initializing folder tree:', error);
showToast('Error loading folder tree', 'error');
showToast('toast.import.folderTreeError', {}, 'error');
}
}

View File

@@ -142,7 +142,7 @@ class ExampleImagesManager {
if (!data.success) {
console.error('Failed to update example images path in backend:', data.error);
} else {
showToast('Example images path updated successfully', 'success');
showToast('toast.exampleImages.pathUpdated', {}, 'success');
}
} catch (error) {
console.error('Failed to update example images path:', error);
@@ -187,7 +187,7 @@ class ExampleImagesManager {
this.startDownload();
} else {
// If download is in progress, show info toast
showToast('Download already in progress', 'info');
showToast('toast.exampleImages.downloadInProgress', {}, 'info');
}
}
@@ -243,7 +243,7 @@ class ExampleImagesManager {
async startDownload() {
if (this.isDownloading) {
showToast('Download already in progress', 'warning');
showToast('toast.exampleImages.downloadInProgress', {}, 'warning');
return;
}
@@ -251,7 +251,7 @@ class ExampleImagesManager {
const outputDir = document.getElementById('exampleImagesPath').value || '';
if (!outputDir) {
showToast('Please enter a download location first', 'warning');
showToast('toast.exampleImages.enterLocationFirst', {}, 'warning');
return;
}
@@ -280,7 +280,7 @@ class ExampleImagesManager {
this.showProgressPanel();
this.startProgressUpdates();
this.updateDownloadButtonText();
showToast('Example images download started', 'success');
showToast('toast.exampleImages.downloadStarted', {}, 'success');
// Close settings modal
modalManager.closeModal('settingsModal');
@@ -289,7 +289,7 @@ class ExampleImagesManager {
}
} catch (error) {
console.error('Failed to start download:', error);
showToast('Failed to start download', 'error');
showToast('toast.exampleImages.downloadStartFailed', {}, 'error');
}
}
@@ -319,13 +319,13 @@ class ExampleImagesManager {
}
this.updateDownloadButtonText();
showToast('Download paused', 'info');
showToast('toast.exampleImages.downloadPaused', {}, 'info');
} else {
showToast(data.error || 'Failed to pause download', 'error');
}
} catch (error) {
console.error('Failed to pause download:', error);
showToast('Failed to pause download', 'error');
showToast('toast.exampleImages.pauseFailed', {}, 'error');
}
}
@@ -355,13 +355,13 @@ class ExampleImagesManager {
}
this.updateDownloadButtonText();
showToast('Download resumed', 'success');
showToast('toast.exampleImages.downloadResumed', {}, 'success');
} else {
showToast(data.error || 'Failed to resume download', 'error');
}
} catch (error) {
console.error('Failed to resume download:', error);
showToast('Failed to resume download', 'error');
showToast('toast.exampleImages.resumeFailed', {}, 'error');
}
}

View File

@@ -287,7 +287,7 @@ export class FilterManager {
} else {
this.filterButton.classList.remove('active');
if (showToastNotification) {
showToast('Filters cleared', 'info');
showToast('toast.filters.cleared', {}, 'info');
}
}
}

View File

@@ -13,7 +13,7 @@ export class DownloadManager {
const isDownloadOnly = !!this.importManager.recipeId;
if (!isDownloadOnly && !this.importManager.recipeName) {
showToast('Please enter a recipe name', 'error');
showToast('toast.import.enterRecipeName', {}, 'error');
return;
}
@@ -93,10 +93,10 @@ export class DownloadManager {
// Show success message
if (isDownloadOnly) {
if (failedDownloads === 0) {
showToast('LoRAs downloaded successfully', 'success');
showToast('toast.loras.downloadSuccessful', {}, 'success');
}
} else {
showToast(`Recipe "${this.importManager.recipeName}" saved successfully`, 'success');
showToast('toast.recipes.nameSaved', { name: this.importManager.recipeName }, 'success');
}
// Close modal
@@ -238,15 +238,19 @@ export class DownloadManager {
// Show appropriate completion message based on results
if (failedDownloads === 0) {
showToast(`All ${completedDownloads} LoRAs downloaded successfully`, 'success');
showToast('toast.loras.allDownloadSuccessful', { count: completedDownloads }, 'success');
} else {
if (accessFailures > 0) {
showToast(
`Downloaded ${completedDownloads} of ${this.importManager.downloadableLoRAs.length} LoRAs. ${accessFailures} failed due to access restrictions. Check your API key in settings or early access status.`,
'error'
);
showToast('toast.loras.downloadPartialWithAccess', {
completed: completedDownloads,
total: this.importManager.downloadableLoRAs.length,
accessFailures: accessFailures
}, 'error');
} else {
showToast(`Downloaded ${completedDownloads} of ${this.importManager.downloadableLoRAs.length} LoRAs`, 'error');
showToast('toast.loras.downloadPartialSuccess', {
completed: completedDownloads,
total: this.importManager.downloadableLoRAs.length
}, 'error');
}
}