fix(embeddings): Translate error messages before sending to UI (#5535)

fix(embeddings): translate error messages before sending to UI

- Import t() function from i18n module
- Wrap error messages with t() translation function in _initializeEmbedder()
- Ensures proper localization of error messages in the UI
- Falls back to original message if no translation exists
This commit is contained in:
Daniel 2025-07-09 18:22:05 -05:00 committed by GitHub
parent be1eaa51eb
commit 45f3d88ddf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -12,6 +12,7 @@ import { CacheManager } from "./cache-manager"
import fs from "fs/promises"
import ignore from "ignore"
import path from "path"
import { t } from "../../i18n"
export class CodeIndexManager {
// --- Singleton Implementation ---
@ -261,12 +262,16 @@ export class CodeIndexManager {
// Validate embedder configuration before proceeding
const validationResult = await this._serviceFactory.validateEmbedder(embedder)
if (!validationResult.valid) {
// Set error state with clear message
this._stateManager.setSystemState(
"Error",
validationResult.error || "Embedder configuration validation failed",
)
throw new Error(validationResult.error || "Invalid embedder configuration")
const errorMessage = validationResult.error || "Embedder configuration validation failed"
// Always attempt translation, use original as fallback
let translatedMessage = t(errorMessage)
// If translation returns a different value (stripped namespace), use original
if (translatedMessage !== errorMessage && !translatedMessage.includes(":")) {
translatedMessage = errorMessage
}
this._stateManager.setSystemState("Error", translatedMessage)
throw new Error(translatedMessage)
}
// (Re)Initialize orchestrator