The Translate class allows you to interact with the translation API. You can translate individual text, batch translate multiple texts, and detect the language of a given text.

Constructors

  • Parameters

    • apiKey: string

      User's API key required for accessing the translation service

    Returns default

Methods

  • Translates multiple texts in batch.

    Parameters

    • texts: string[]

      Array of texts to translate

    • options: TranslateOptions

      Object containing source and target languages

    Returns Promise<null | BatchTranslationResponse>

    A promise that resolves to an array of translated texts or null in case of an error

  • Detects the language of a given text.

    Parameters

    • text: string

      The text whose language needs to be detected

    Returns Promise<null | DetectTranslationResponse>

    A promise that resolves to the detected language or null in case of an error

  • Translates a single piece of text to the target language.

    Parameters

    • text: string

      The text to translate

    • options: TranslateOptions

      Object containing source and target languages

    Returns Promise<null | TranslationResponse>

    A promise that resolves to the translated text or null in case of an error

  • Quick translation for a single piece of text. This method does not require an instance of the class.

    Parameters

    Returns Promise<undefined | string>

    The translated text or undefined if an error occurs