Skip to content

#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere

701 B
Raw Blame
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 candidateKeys = [`home.${toolId}.tags`, `${toolId}.tags`];
    const tags = candidateKeys
      .map((key) => ({ key, value: t(key) }))
      .find(({ key, value }) => value && value !== key)?.value;

    if (!tags) return [];

    return tags
      .split(",")
      .map((tag: string) => tag.trim())
      .filter((tag: string) => tag.length > 0);
  } catch (error) {
    console.error(
      `[Tags] Failed to get translated synonyms for tool ${toolId}:`,
      error,
    );
    return [];
  }
};