async translate (options) {
    const reqBody = {
      source: options.srcLang,
      target: options.tgtLang,
      format: options.format || 'text',
      model: 'nmt',
      q: [],
      key: options.apiKey
    }

    const batchSize = 10 // max number of elements in q array
    let translations = []
    for (const srcString of options.srcStrings) {
      reqBody.q.push(srcString)
      if (reqBody.q.length === batchSize) {
        // Cap the length of q at 10 per request
        const batchTranslations = await this._translate(reqBody)
          .catch(error => {
            throw error
          })
        if (batchTranslations.length) {
          translations.push(...batchTranslations)
          reqBody.q.length = 0
        }
      }
    }
    // If q contains any strings left untranslated, send one more request.
    if (reqBody.q.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 "text" (default) or "html"
   */
Translates an array of strings.
Translates an array of strings .
async translate (options) {
    const reqBody = {
      source: options.srcLang,
      target: options.tgtLang,
      format: options.format || 'text',
      model: 'nmt',
      q: [],
      key: options.apiKey
    }
    const batchSize = 10 
    let translations = []
    for (const srcString of options.srcStrings) {
      reqBody.q.push(srcString)
      if (reqBody.q.length === batchSize) {
        const batchTranslations = await this._translate(reqBody)
          .catch(error => {
            throw error
          })
        if (batchTranslations.length) {
          translations.push(...batchTranslations)
          reqBody.q.length = 0
        }
      }
    }
    if (reqBody.q.length) {
      const batchTranslations = await this._translate(reqBody)
        .catch(error => {
          throw error
        })
      if (batchTranslations.length) {
        translations.push(...batchTranslations)
      }
    }
    return translations
  }
async translate ( options ) { const reqBody = { source : options . srcLang , target : options . tgtLang , format : options . format || 'text' , model : 'nmt' , q : [ ] , key : options . apiKey } const batchSize = 10 let translations = [ ] for ( const srcString of options . srcStrings ) { reqBody . q . push ( srcString ) if ( reqBody . q . length === batchSize ) { const batchTranslations = await this . _translate ( reqBody ) . catch ( error => { throw error } ) if ( batchTranslations . length ) { translations . push ( ... batchTranslations ) reqBody . q . length = 0 } } } if ( reqBody . q . 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 q array // Cap the length of q at 10 per request // If q contains any strings left untranslated, send one more request.