Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@filerobot/utils / lib / i18n.client.js
Size: Mime:
import RequestError from '@filerobot/utils/lib/RequestError';
import { I18N_GRID_UUID } from '@filerobot/utils/lib/constants';
var hardcodedErrorMsg = 'Error while loading languages.';
export var getBackendTranslations = function getBackendTranslations(_ref) {
  var i18nFetchApiEndpoint = _ref.i18nFetchApiEndpoint;
  return new Promise(function (resolve, reject) {
    var xhr = new XMLHttpRequest();
    xhr.responseType = 'json';
    xhr.onload = function () {
      if (xhr.status >= 200 && xhr.status < 300) {
        resolve(xhr.response);
      } else {
        var _xhr$response, _xhr$response2, _xhr$response3, _xhr$response4;
        reject(new RequestError({
          code: xhr.status,
          message: ((_xhr$response = xhr.response) === null || _xhr$response === void 0 ? void 0 : _xhr$response.msg) || "Error code ".concat(xhr.status),
          details: ((_xhr$response2 = xhr.response) === null || _xhr$response2 === void 0 ? void 0 : _xhr$response2.hint) || ((_xhr$response3 = xhr.response) === null || _xhr$response3 === void 0 ? void 0 : _xhr$response3.msg) || ((_xhr$response4 = xhr.response) === null || _xhr$response4 === void 0 ? void 0 : _xhr$response4.detail) || hardcodedErrorMsg
        }));
      }
    };
    xhr.onerror = function () {
      reject(new RequestError({
        code: xhr.status,
        message: hardcodedErrorMsg
      }));
    };
    xhr.open('GET', "".concat(i18nFetchApiEndpoint, "/export?grid=").concat(I18N_GRID_UUID));
    xhr.send();
  });
};
export var sendMissingTranslationToBackend = function sendMissingTranslationToBackend(missingTranslation) {
  return new Promise(function (resolve, reject) {
    var xhr = new XMLHttpRequest();
    xhr.responseType = 'json';
    xhr.onload = function () {
      if (xhr.status >= 200 && xhr.status < 300) {
        resolve(xhr.response);
      } else {
        var _xhr$response5;
        console.warn("Error in sending translation key to backend ".concat((_xhr$response5 = xhr.response) === null || _xhr$response5 === void 0 ? void 0 : _xhr$response5.hint, ", ").concat(xhr.status));
      }
    };
    xhr.onerror = function () {
      var _xhr$response6;
      console.warn("Error in sending translation key to backend ".concat((_xhr$response6 = xhr.response) === null || _xhr$response6 === void 0 ? void 0 : _xhr$response6.hint, ", ").concat(xhr.status));
    };
    var payload = {
      grid_uuid: I18N_GRID_UUID,
      translations_requests: [missingTranslation]
    };
    xhr.open('POST', "https://neo.wordplex.io/api/import/request-translations?grid_uuid=".concat(I18N_GRID_UUID));
    xhr.send(JSON.stringify(payload));
  });
};