async translate (options) {
    const reqBody = {
      from: options.srcLang,
      to: options.tgtLang,
      textType: options.format || 'plain',
      category: options.category || 'general',
      srcStrings: [],
      apiKey: options.apiKey
    }

    const batchSize = 5 // max number of elements in srcStrings array
    let translations = []
    for (const srcString of options.srcStrings) {
      reqBody.srcStrings.push({Text: srcString})
      if (reqBody.srcStrings.length === batchSize) {
        // Cap the length of srcStrings at 5 per request
        const batchTranslations = await this._translate(reqBody)
          .catch(error => {
            throw error
          })
        if (batchTranslations.length) {
          translations.push(...batchTranslations)
          reqBody.srcStrings.length = 0
        }
      }
    }
    // If srcStrings contains any strings left untranslated, send one more request.
    if (reqBody.srcStrings.length) {
      const batchTranslations = await this._translate(reqBody)
        .catch(error => {
          throw error
        })
      if (batchTranslations.length) {
        translations.push(...batchTranslations)
      }
    }

    return translations
  }
/**
   * Translates an array of strings.
   * @param {Object} options - Includes the following properties:
   *    apiKey: API key,
   *    srcStrings: An array of string to translate
   *    srcLang: Language code from which srcStrings will be translated
   *    tgtLang: Language code into which srcStrings will be translated
   *    format: Format of srcStrings, either "plain" (default) or "html"
   *    category: Category ID or "general" (default)
   */
Translates an array of strings.
Translates an array of strings .
async translate (options) {
    const reqBody = {
      from: options.srcLang,
      to: options.tgtLang,
      textType: options.format || 'plain',
      category: options.category || 'general',
      srcStrings: [],
      apiKey: options.apiKey
    }
    const batchSize = 5 
    let translations = []
    for (const srcString of options.srcStrings) {
      reqBody.srcStrings.push({Text: srcString})
      if (reqBody.srcStrings.length === batchSize) {
        const batchTranslations = await this._translate(reqBody)
          .catch(error => {
            throw error
          })
        if (batchTranslations.length) {
          translations.push(...batchTranslations)
          reqBody.srcStrings.length = 0
        }
      }
    }
    if (reqBody.srcStrings.length) {
      const batchTranslations = await this._translate(reqBody)
        .catch(error => {
          throw error
        })
      if (batchTranslations.length) {
        translations.push(...batchTranslations)
      }
    }
    return translations
  }
async translate ( options ) { const reqBody = { from : options . srcLang , to : options . tgtLang , textType : options . format || 'plain' , category : options . category || 'general' , srcStrings : [ ] , apiKey : options . apiKey } const batchSize = 5 let translations = [ ] for ( const srcString of options . srcStrings ) { reqBody . srcStrings . push ( { Text : srcString } ) if ( reqBody . srcStrings . length === batchSize ) { const batchTranslations = await this . _translate ( reqBody ) . catch ( error => { throw error } ) if ( batchTranslations . length ) { translations . push ( ... batchTranslations ) reqBody . srcStrings . length = 0 } } } if ( reqBody . srcStrings . length ) { const batchTranslations = await this . _translate ( reqBody ) . catch ( error => { throw error } ) if ( batchTranslations . length ) { translations . push ( ... batchTranslations ) } } return translations }
Translates an array of strings.
Translates an array of strings .
// max number of elements in srcStrings array // Cap the length of srcStrings at 5 per request // If srcStrings contains any strings left untranslated, send one more request.