dist/functions.js
/**
 * Translate a Term using Microsoft Translate.
 * @customfunction translate
 * @param term Term to be translated
 * @param from original language of the Term
 * @param to language to which the Term is translated to
 * @returns Translated Term
 */
Translate a Term using Microsoft Translate.
Translate a Term using Microsoft Translate .
function translate(term, from, to) {
  return __awaiter(this, void 0, void 0, function () {
    var url, body, res, data, error_3, errorT;
    return __generator(this, function (_a) {
      switch (_a.label) {
        case 0:
          url = endpoint + "translate?api-version=3.0&to=" + to + "&from=" + from;
          body = JSON.stringify([{
            text: term
          }]);
          _a.label = 1;
        case 1:
          _a.trys.push([1, 4,, 5]);
          return [4
          , fetch(url, {
            method: 'POST',
            body: body,
            headers: {
              "Content-Type": "application/json",
              "Ocp-Apim-Subscription-Key": apikey,
              "X-ClientTraceId": uuid_1.v4().toString(),
              "Ocp-Apim-Subscription-Region": "westeurope"
            }
          })];
        case 2:
          res = _a.sent();
          return [4
          , res.json()];
        case 3:
          data = _a.sent();
          console.log(data);
          if (data.error) {
            throw data.error.message;
          }
          return [2
          , data[0].translations[0].text];
        case 4:
          error_3 = _a.sent();
          console.log(error_3);
          errorT = typeof error_3;
          throw error_3;
        case 5:
          return [2
          ];
      }
    });
  });
}
function translate ( term , from , to ) { return __awaiter ( this , void 0 , void 0 , function ( ) { var url , body , res , data , error_3 , errorT ; return __generator ( this , function ( _a ) { switch ( _a . label ) { case 0 : url = endpoint + "translate?api-version=3.0&to=" + to + "&from=" + from ; body = JSON . stringify ( [ { text : term } ] ) ; _a . label = 1 ; case 1 : _a . trys . push ( [ 1 , 4 , , 5 ] ) ; return [ 4 , fetch ( url , { method : 'POST' , body : body , headers : { "Content-Type" : "application/json" , "Ocp-Apim-Subscription-Key" : apikey , "X-ClientTraceId" : uuid_1 . v4 ( ) . toString ( ) , "Ocp-Apim-Subscription-Region" : "westeurope" } } ) ] ; case 2 : res = _a . sent ( ) ; return [ 4 , res . json ( ) ] ; case 3 : data = _a . sent ( ) ; console . log ( data ) ; if ( data . error ) { throw data . error . message ; } return [ 2 , data [ 0 ] . translations [ 0 ] . text ] ; case 4 : error_3 = _a . sent ( ) ; console . log ( error_3 ) ; errorT = typeof error_3 ; throw error_3 ; case 5 : return [ 2 ] ; } } ) ; } ) ; }
Translate a Term using Microsoft Translate.
Translate a Term using Microsoft Translate .
/*yield*/ /*yield*/ /*return*/ /*return*/