Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

1.6 KB
Raw Blame
import { PLUGIN_CONTENT_TRANSLATION } from "metabase/content-translation/plugins";
import { hasPremiumFeature } from "metabase-enterprise/settings";

import { ContentTranslationConfiguration } from "./components";
import {
  contentTranslationEndpoints,
  dictionaryEndpointStore,
} from "./constants";
import { useTranslateContent } from "./use-translate-content";
import {
  translateColumnDisplayName,
  translateDisplayNames,
  useSortByContentTranslation,
  useTranslateFieldValuesInHoveredObject,
  useTranslateSeries,
} from "./utils";

/**
 * Initialize content translation plugin features that depend on hasPremiumFeature.
 */
export function initializePlugin() {
  if (hasPremiumFeature("content_translation")) {
    const getDictionaryBasePath = `/api/ee/content-translation/dictionary`;

    Object.assign(PLUGIN_CONTENT_TRANSLATION, {
      isEnabled: true,
      useSortByContentTranslation,
      useTranslateContent,
      useTranslateFieldValuesInHoveredObject,
      useTranslateSeries,
      getDictionaryBasePath,
      setEndpointsForAuthEmbedding: () => {
        if (contentTranslationEndpoints.getDictionary) {
          return;
        }

        dictionaryEndpointStore.setEndpoint(getDictionaryBasePath);
      },
      setEndpointsForStaticEmbedding: (encodedToken: string) => {
        if (contentTranslationEndpoints.getDictionary) {
          return;
        }

        dictionaryEndpointStore.setEndpoint(
          `${getDictionaryBasePath}/${encodedToken}`,
        );
      },
      translateDisplayNames,
      translateColumnDisplayName,
      ContentTranslationConfiguration,
    });
  }
}