feat(localization): enhance toast messages for API actions and model management with i18n support

refactor(localization): update toast messages in various components and managers for better user feedback
This commit is contained in:
Will Miao
2025-08-31 12:25:08 +08:00
parent be8edafed0
commit e60a579b85
17 changed files with 216 additions and 101 deletions

View File

@@ -83,8 +83,7 @@ export function setupModelNameEditing(filePath) {
sel.removeAllRanges();
sel.addRange(range);
const text = translate('modelMetadata.validation.nameTooLong', {}, 'Model name is limited to 100 characters');
showToast(text, 'warning');
showToast('toast.models.nameTooLong', {}, 'warning');
}
});
@@ -99,7 +98,7 @@ export function setupModelNameEditing(filePath) {
if (!newModelName) {
// Restore original value if empty
this.textContent = originalValue;
showToast('Model name cannot be empty', 'error');
showToast('toast.models.nameCannotBeEmpty', {}, 'error');
exitEditMode();
return;
}
@@ -116,11 +115,11 @@ export function setupModelNameEditing(filePath) {
await getModelApiClient().saveModelMetadata(filePath, { model_name: newModelName });
showToast('Model name updated successfully', 'success');
showToast('toast.models.nameUpdatedSuccessfully', {}, 'success');
} catch (error) {
console.error('Error updating model name:', error);
this.textContent = originalValue; // Restore original model name
showToast('Failed to update model name', 'error');
showToast('toast.models.nameUpdateFailed', {}, 'error');
} finally {
exitEditMode();
}
@@ -302,9 +301,9 @@ async function saveBaseModel(filePath, originalValue) {
try {
await getModelApiClient().saveModelMetadata(filePath, { base_model: newBaseModel });
showToast('Base model updated successfully', 'success');
showToast('toast.models.baseModelUpdated', {}, 'success');
} catch (error) {
showToast('Failed to update base model', 'error');
showToast('toast.models.baseModelUpdateFailed', {}, 'error');
}
}
@@ -390,7 +389,7 @@ export function setupFileNameEditing(filePath) {
sel.addRange(range);
}
showToast('Invalid characters removed from filename', 'warning');
showToast('toast.models.invalidCharactersRemoved', {}, 'warning');
}
});
@@ -405,7 +404,7 @@ export function setupFileNameEditing(filePath) {
if (!newFileName) {
// Restore original value if empty
this.textContent = originalValue;
showToast('File name cannot be empty', 'error');
showToast('toast.models.filenameCannotBeEmpty', {}, 'error');
exitEditMode();
return;
}
@@ -424,7 +423,7 @@ export function setupFileNameEditing(filePath) {
} catch (error) {
console.error('Error renaming file:', error);
this.textContent = originalValue; // Restore original file name
showToast(`Failed to rename file: ${error.message}`, 'error');
showToast('toast.models.renameFailed', { message: error.message }, 'error');
} finally {
exitEditMode();
}

View File

@@ -26,7 +26,7 @@ async function fetchTrainedWords(filePath) {
}
} catch (error) {
console.error('Error fetching trained words:', error);
showToast('Could not load trained words', 'error');
showToast('toast.triggerWords.loadFailed', {}, 'error');
return { trainedWords: [], classTokens: null };
}
}
@@ -499,21 +499,21 @@ function addNewTriggerWord(word) {
// Validation: Check length
if (word.split(/\s+/).length > 30) {
showToast('Trigger word should not exceed 30 words', 'error');
showToast('toast.triggerWords.tooLong', {}, 'error');
return;
}
// Validation: Check total number
const currentTags = tagsContainer.querySelectorAll('.trigger-word-tag');
if (currentTags.length >= 30) {
showToast('Maximum 30 trigger words allowed', 'error');
showToast('toast.triggerWords.tooMany', {}, 'error');
return;
}
// Validation: Check for duplicates
const existingWords = Array.from(currentTags).map(tag => tag.dataset.word);
if (existingWords.includes(word)) {
showToast('This trigger word already exists', 'error');
showToast('toast.triggerWords.alreadyExists', {}, 'error');
return;
}
@@ -628,10 +628,10 @@ async function saveTriggerWords() {
if (tagsContainer) tagsContainer.style.display = 'none';
}
showToast('Trigger words updated successfully', 'success');
showToast('toast.triggerWords.updateSuccess', {}, 'success');
} catch (error) {
console.error('Error saving trigger words:', error);
showToast('Failed to update trigger words', 'error');
showToast('toast.triggerWords.updateFailed', {}, 'error');
}
}
@@ -644,6 +644,6 @@ window.copyTriggerWord = async function(word) {
await copyToClipboard(word, 'Trigger word copied');
} catch (err) {
console.error('Copy failed:', err);
showToast('Copy failed', 'error');
showToast('toast.triggerWords.copyFailed', {}, 'error');
}
};