feat(localization): enhance toast messages for context menu actions, model tags, and download management with improved error handling and user feedback

This commit is contained in:
Will Miao
2025-08-31 14:27:33 +08:00
parent 987b8c8742
commit 8303196b57
14 changed files with 142 additions and 64 deletions

View File

@@ -143,16 +143,13 @@ async function toggleFavorite(card) {
});
if (newFavoriteState) {
const addedText = translate('modelCard.favorites.added', {}, 'Added to favorites');
showToast(addedText, 'success');
showToast('modelCard.favorites.added', {}, 'success');
} else {
const removedText = translate('modelCard.favorites.removed', {}, 'Removed from favorites');
showToast(removedText, 'success');
showToast('modelCard.favorites.removed', {}, 'success');
}
} catch (error) {
console.error('Failed to update favorite status:', error);
const errorText = translate('modelCard.favorites.updateFailed', {}, 'Failed to update favorite status');
showToast(errorText, 'error');
showToast('modelCard.favorites.updateFailed', {}, 'error');
}
}
@@ -164,8 +161,7 @@ function handleSendToWorkflow(card, replaceMode, modelType) {
sendLoraToWorkflow(loraSyntax, replaceMode, 'lora');
} else {
// Checkpoint send functionality - to be implemented
const text = translate('modelCard.sendToWorkflow.checkpointNotImplemented', {}, 'Send checkpoint to workflow - feature to be implemented');
showToast(text, 'info');
showToast('modelCard.sendToWorkflow.checkpointNotImplemented', {}, 'info');
}
}
@@ -201,8 +197,7 @@ async function handleExampleImagesAccess(card, modelType) {
}
} catch (error) {
console.error('Error checking for example images:', error);
const text = translate('modelCard.exampleImages.checkError', {}, 'Error checking for example images');
showToast(text, 'error');
showToast('modelCard.exampleImages.checkError', {}, 'error');
}
}
@@ -284,8 +279,7 @@ function showExampleAccessModal(card, modelType) {
// Get the model hash
const modelHash = card.dataset.sha256;
if (!modelHash) {
const text = translate('modelCard.exampleImages.missingHash', {}, 'Missing model hash information.');
showToast(text, 'error');
showToast('modelCard.exampleImages.missingHash', {}, 'error');
return;
}

View File

@@ -154,8 +154,7 @@ export async function setupModelDescriptionEditing(filePath) {
}
if (!newValue) {
this.innerHTML = originalValue;
const emptyErrorText = translate('modals.model.description.validation.cannotBeEmpty', {}, 'Description cannot be empty');
showToast(emptyErrorText, 'error');
showToast('modals.model.description.validation.cannotBeEmpty', {}, 'error');
exitEditMode();
return;
}
@@ -163,12 +162,10 @@ export async function setupModelDescriptionEditing(filePath) {
// Save to backend
const { getModelApiClient } = await import('../../api/modelApiFactory.js');
await getModelApiClient().saveModelMetadata(filePath, { modelDescription: newValue });
const successText = translate('modals.model.description.messages.updated', {}, 'Model description updated');
showToast(successText, 'success');
showToast('modals.model.description.messages.updated', {}, 'success');
} catch (err) {
this.innerHTML = originalValue;
const errorText = translate('modals.model.description.messages.updateFailed', {}, 'Failed to update model description');
showToast(errorText, 'error');
showToast('modals.model.description.messages.updateFailed', {}, 'error');
} finally {
exitEditMode();
}

View File

@@ -438,11 +438,9 @@ async function saveNotes(filePath) {
try {
await getModelApiClient().saveModelMetadata(filePath, { notes: content });
const successMessage = translate('modals.model.notes.saved', {}, 'Notes saved successfully');
showToast(successMessage, 'success');
showToast('modals.model.notes.saved', {}, 'success');
} catch (error) {
const errorMessage = translate('modals.model.notes.saveFailed', {}, 'Failed to save notes');
showToast(errorMessage, 'error');
showToast('modals.model.notes.saveFailed', {}, 'error');
}
}

View File

@@ -217,10 +217,10 @@ async function saveTags() {
// Exit edit mode
editBtn.click();
showToast(translate('modelTags.messages.updated', {}, 'Tags updated successfully'), 'success');
showToast('modelTags.messages.updated', {}, 'success');
} catch (error) {
console.error('Error saving tags:', error);
showToast(translate('modelTags.messages.updateFailed', {}, 'Failed to update tags'), 'error');
showToast('modelTags.messages.updateFailed', {}, 'error');
}
}
@@ -362,24 +362,21 @@ function addNewTag(tag) {
// Validation: Check length
if (tag.length > 30) {
const text = translate('modelTags.validation.maxLength', {}, 'Tag should not exceed 30 characters');
showToast(text, 'error');
showToast('modelTags.validation.maxLength', {}, 'error');
return;
}
// Validation: Check total number
const currentTags = tagsContainer.querySelectorAll('.metadata-item');
if (currentTags.length >= 30) {
const text = translate('modelTags.validation.maxCount', {}, 'Maximum 30 tags allowed');
showToast(text, 'error');
showToast('modelTags.validation.maxCount', {}, 'error');
return;
}
// Validation: Check for duplicates
const existingTags = Array.from(currentTags).map(tag => tag.dataset.tag);
if (existingTags.includes(tag)) {
const text = translate('modelTags.validation.duplicate', {}, 'This tag already exists');
showToast(text, 'error');
showToast('modelTags.validation.duplicate', {}, 'error');
return;
}

View File

@@ -445,7 +445,7 @@ export function initMediaControlHandlers(container) {
state.virtualScroller.updateSingleItem(result.model_file_path, updateData);
} else {
// Show error message
showToast(result.error || 'Failed to delete example image', 'error');
showToast('showcase.exampleImages.deleteFailed', { error: result.error }, 'error');
// Reset button state
this.disabled = false;