diff --git a/frontend/src/core/utils/toolSynonyms.ts b/frontend/src/core/utils/toolSynonyms.ts index e542481b3..31b80fa2c 100644 --- a/frontend/src/core/utils/toolSynonyms.ts +++ b/frontend/src/core/utils/toolSynonyms.ts @@ -1,26 +1,29 @@ -import { TFunction } from 'i18next'; +import { TFunction } from "i18next"; // Helper function to get synonyms for a tool (only from translations) export const getSynonyms = (t: TFunction, toolId: string): string[] => { try { - const tagsKey = `${toolId}.tags`; - const tags = t(tagsKey) as unknown as string; + const candidateKeys = [`home.${toolId}.tags`, `${toolId}.tags`]; + const match = candidateKeys + .map((key) => ({ key, value: t(key) as unknown as string })) + .find(({ key, value }) => value && value !== key); + const tags = match?.value; + const usedKey = match?.key; - // If the translation key doesn't exist or returns the key itself, return empty array - if (!tags || tags === tagsKey) { + if (!tags) { console.warn(`[Tags] Missing tags for tool: ${toolId}`); return []; } // Split by comma and clean up the tags const cleanedTags = tags - .split(',') + .split(",") .map((tag: string) => tag.trim()) .filter((tag: string) => tag.length > 0); // Log the tags found for this tool if (cleanedTags.length > 0) { - console.info(`[Tags] Tool "${toolId}" has ${cleanedTags.length} tags:`, cleanedTags); + console.info(`[Tags] Tool "${toolId}" (${usedKey}) has ${cleanedTags.length} tags:`, cleanedTags); } else { console.warn(`[Tags] Tool "${toolId}" has empty tags value`); } @@ -29,6 +32,5 @@ export const getSynonyms = (t: TFunction, toolId: string): string[] => { } catch (error) { console.error(`[Tags] Failed to get translated synonyms for tool ${toolId}:`, error); return []; - }}; - - + } +};