Repository URL to install this package:
|
Version:
5.0.0-rc.11 ▾
|
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var index = require('../../node_modules/@brainly/onesky-utils/index.js');
/**
* Interact with the OneSky API
*
* @module @doodle/i18n/disty/onesky/api
*/
/**
* OneSky credentials
*
* @typedef {object} OneSkyCredentials
* @property {string} secret
* @property {string} apiKey
*/
/**
* OneSky Translation
* @typedef {object} OneSkyTranslationOptions
* @property {string} projectId
* @property {string} language
* @property {string} fileName
*/
/**
* OneSky translation upload options
*
* @typedef {object} OneSkySyncOptions
* @property {string} format
* @property {string} keepStrings
*/
/**
* OneSky Language object
*
* @typedef {object} OneSkyLanguage
* @property {string} code language code, i.e. en-US or de
* @property {string} english_name i.e. English (United States)
* @property {string} local_name i.e. English (United States)
* @property {string} locale i.e. en
* @property {string} region i.e. US
* @property {bool} is_base_language
* @property {bool} is_ready_to_publish
* @property {string} translation_progress i.e. 100%
* @property {string} uploaded_at i.e. 2013-10-07T15:27:10+0000
* @property {number} uploaded_at_timestamp i.e. 1381159630
*/
/**
* Retrieve the defined languages in the OneSky project
*
* @param {string} projectId
* @param {OneSkyCredentials} credentials
* @returns {Promise<OneSkyLanguage>}
* @async
*/
var getProjectLanguages = /*#__PURE__*/function () {
var _ref = _rollupPluginBabelHelpers.asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(projectId, credentials) {
var result, _JSON$parse, data;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return index.default.getLanguages(_rollupPluginBabelHelpers.objectSpread2({
projectId: projectId
}, credentials));
case 2:
result = _context.sent;
if (!result) {
_context.next = 6;
break;
}
_JSON$parse = JSON.parse(result), data = _JSON$parse.data;
return _context.abrupt("return", data);
case 6:
return _context.abrupt("return", []);
case 7:
case "end":
return _context.stop();
}
}
}, _callee);
}));
return function getProjectLanguages(_x, _x2) {
return _ref.apply(this, arguments);
};
}();
/**
* Upload messages to a OneSky project for one language
*
* @param {OneSkyTranslationOptions} projectTranslation
* @param {object} messages
* @param {OneSkyCredentials} credentials
* @param {OneSkySyncOptions} syncOptions
* @returns {Promise}
* @async
*/
var uploadProjectTranslation = /*#__PURE__*/function () {
var _ref2 = _rollupPluginBabelHelpers.asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(projectTranslation, messages, credentials, syncOptions) {
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
return _context2.abrupt("return", index.default.postFile(_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({
language: 'en',
fileName: 'translations.json'
}, projectTranslation), {}, {
format: 'HIERARCHICAL_JSON',
keepStrings: true
}, syncOptions), credentials), {}, {
content: JSON.stringify(messages)
})));
case 1:
case "end":
return _context2.stop();
}
}
}, _callee2);
}));
return function uploadProjectTranslation(_x3, _x4, _x5, _x6) {
return _ref2.apply(this, arguments);
};
}();
/**
* Download messages from a OneSky project by one language
*
* @param {OneSkyTranslationOptions} projectTranslationOptions
* @param {OneSkyCredentials} credentials
* @returns {Promise<object>}
* @async
*/
var getProjectMessagesByLanguage = /*#__PURE__*/function () {
var _ref3 = _rollupPluginBabelHelpers.asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(projectTranslationOptions, credentials) {
var content;
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.next = 2;
return index.default.getFile(_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({
language: 'en',
fileName: 'translations.json'
}, projectTranslationOptions), credentials));
case 2:
content = _context3.sent;
if (!content) {
_context3.next = 5;
break;
}
return _context3.abrupt("return", JSON.parse(content));
case 5:
return _context3.abrupt("return", {});
case 6:
case "end":
return _context3.stop();
}
}
}, _callee3);
}));
return function getProjectMessagesByLanguage(_x7, _x8) {
return _ref3.apply(this, arguments);
};
}();
exports.getProjectLanguages = getProjectLanguages;
exports.getProjectMessagesByLanguage = getProjectMessagesByLanguage;
exports.uploadProjectTranslation = uploadProjectTranslation;
//# sourceMappingURL=api.js.map