#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
fix(frontend): improve synonym search (#5639)
Ludy47e0c9cb5104
diff --git a/frontend/src/core/utils/toolSynonyms.ts b/frontend/src/core/utils/toolSynonyms.tsindex e542481b30..31b80fa2c0 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 tagsconst cleanedTags = tags- .split(',')+ .split(",").map((tag: string) => tag.trim()).filter((tag: string) => tag.length > 0);// Log the tags found for this toolif (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 [];- }};--+ }+};