MCPcopy
hub / github.com/ilyhalight/voice-over-translation / getTranslatedErrorMessage

Method getTranslatedErrorMessage

src/index.ts:1304–1335  ·  view source on GitHub ↗
(
    errorMessage: any,
    lang: string,
    signal?: AbortSignal,
  )

Source from the content-addressed store, hash-verified

1302 }
1303
1304 private async getTranslatedErrorMessage(
1305 errorMessage: any,
1306 lang: string,
1307 signal?: AbortSignal,
1308 ): Promise<string | null> {
1309 const overlayView = this.uiManager.votOverlayView;
1310 if (!overlayView?.votButton) {
1311 return null;
1312 }
1313
1314 const messageStr = Array.isArray(errorMessage)
1315 ? errorMessage.join(" ")
1316 : String(errorMessage);
1317 const cacheKey = `${lang}:${messageStr}`;
1318 const cached = this.errorTranslationCache.get(cacheKey);
1319 if (cached) {
1320 return cached;
1321 }
1322
1323 overlayView.votButton.loading = true;
1324 const translatedMessage = await translate(messageStr, "ru", lang);
1325 if (signal?.aborted) {
1326 return null;
1327 }
1328
1329 const translatedText = Array.isArray(translatedMessage)
1330 ? translatedMessage.join("\n")
1331 : String(translatedMessage);
1332 this.errorTranslationCache.set(cacheKey, translatedText);
1333 this.trimErrorTranslationCache();
1334 return translatedText;
1335 }
1336
1337 private trimErrorTranslationCache(): void {
1338 if (this.errorTranslationCache.size <= 50) {

Calls 4

translateFunction · 0.90
setMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected