@cloudflare/intl-core
Advanced tools
Comparing version 1.0.13 to 1.0.14
@@ -6,3 +6,11 @@ # Change Log | ||
<a name="1.0.13"></a> | ||
<a name="1.0.14"></a> | ||
## [1.0.14](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/intl-core@1.0.13...@cloudflare/intl-core@1.0.14) (2018-10-19) | ||
**Note:** Version bump only for package @cloudflare/intl-core | ||
<a name="1.0.13"></a> | ||
## [1.0.13](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/intl-core@1.0.12...@cloudflare/intl-core@1.0.13) (2018-10-17) | ||
@@ -15,3 +23,3 @@ | ||
<a name="1.0.12"></a> | ||
<a name="1.0.12"></a> | ||
## [1.0.12](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/intl-core@1.0.11...@cloudflare/intl-core@1.0.12) (2018-10-15) | ||
@@ -18,0 +26,0 @@ |
@@ -0,1 +1,13 @@ | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } | ||
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
@@ -5,2 +17,38 @@ | ||
import { ESupportedLocales } from './index'; | ||
var loadLocale = | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee(locales, locale) { | ||
var module; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return locales[locale](); | ||
case 2: | ||
module = _context.sent; | ||
return _context.abrupt("return", module.default ? module.default : module); | ||
case 4: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
return function loadLocale(_x, _x2) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); //returns a function which returns a Promise resolving in phrases for a particular locale. | ||
//loads english catalog by default and overwrites it with catalog in target language. | ||
//so that for any phrases for which target language catalog is missing a value, the english one is used. | ||
var makeLoadPhrases = function loadPhrases(locales) { | ||
@@ -10,36 +58,39 @@ var loadPhrases = | ||
function () { | ||
var _ref = _asyncToGenerator( | ||
var _ref2 = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee(locale) { | ||
var module; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
regeneratorRuntime.mark(function _callee2(locale) { | ||
var _ref3, _ref4, enPhrases, otherPhrases; | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context.next = 2; | ||
return locales[locale](); | ||
case 2: | ||
module = _context.sent; | ||
if (!module.default) { | ||
_context.next = 5; | ||
if (!(locale === ESupportedLocales.en_US)) { | ||
_context2.next = 2; | ||
break; | ||
} | ||
return _context.abrupt("return", module.default); | ||
return _context2.abrupt("return", loadLocale(locales, locale)); | ||
case 5: | ||
return _context.abrupt("return", module); | ||
case 2: | ||
_context2.next = 4; | ||
return Promise.all([loadLocale(locales, ESupportedLocales.en_US), loadLocale(locales, locale)]); | ||
case 6: | ||
case 4: | ||
_ref3 = _context2.sent; | ||
_ref4 = _slicedToArray(_ref3, 2); | ||
enPhrases = _ref4[0]; | ||
otherPhrases = _ref4[1]; | ||
return _context2.abrupt("return", _objectSpread({}, enPhrases, otherPhrases)); | ||
case 9: | ||
case "end": | ||
return _context.stop(); | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
}, _callee2, this); | ||
})); | ||
return function loadPhrases(_x) { | ||
return _ref.apply(this, arguments); | ||
return function loadPhrases(_x3) { | ||
return _ref2.apply(this, arguments); | ||
}; | ||
@@ -46,0 +97,0 @@ }(); |
@@ -70,4 +70,4 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
key: "extend", | ||
value: function extend(phrases) { | ||
var p = this.getInstance(); | ||
value: function extend(phrases, locale) { | ||
var p = this.getInstance(locale); | ||
p.extend(phrases); | ||
@@ -74,0 +74,0 @@ } |
@@ -8,2 +8,16 @@ "use strict"; | ||
var _index = require("./index"); | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } | ||
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
@@ -13,2 +27,36 @@ | ||
var loadLocale = | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee(locales, locale) { | ||
var module; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return locales[locale](); | ||
case 2: | ||
module = _context.sent; | ||
return _context.abrupt("return", module.default ? module.default : module); | ||
case 4: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
return function loadLocale(_x, _x2) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); //returns a function which returns a Promise resolving in phrases for a particular locale. | ||
//loads english catalog by default and overwrites it with catalog in target language. | ||
//so that for any phrases for which target language catalog is missing a value, the english one is used. | ||
var makeLoadPhrases = function loadPhrases(locales) { | ||
@@ -18,36 +66,39 @@ var loadPhrases = | ||
function () { | ||
var _ref = _asyncToGenerator( | ||
var _ref2 = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee(locale) { | ||
var module; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
regeneratorRuntime.mark(function _callee2(locale) { | ||
var _ref3, _ref4, enPhrases, otherPhrases; | ||
return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_context.next = 2; | ||
return locales[locale](); | ||
case 2: | ||
module = _context.sent; | ||
if (!module.default) { | ||
_context.next = 5; | ||
if (!(locale === _index.ESupportedLocales.en_US)) { | ||
_context2.next = 2; | ||
break; | ||
} | ||
return _context.abrupt("return", module.default); | ||
return _context2.abrupt("return", loadLocale(locales, locale)); | ||
case 5: | ||
return _context.abrupt("return", module); | ||
case 2: | ||
_context2.next = 4; | ||
return Promise.all([loadLocale(locales, _index.ESupportedLocales.en_US), loadLocale(locales, locale)]); | ||
case 6: | ||
case 4: | ||
_ref3 = _context2.sent; | ||
_ref4 = _slicedToArray(_ref3, 2); | ||
enPhrases = _ref4[0]; | ||
otherPhrases = _ref4[1]; | ||
return _context2.abrupt("return", _objectSpread({}, enPhrases, otherPhrases)); | ||
case 9: | ||
case "end": | ||
return _context.stop(); | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
}, _callee2, this); | ||
})); | ||
return function loadPhrases(_x) { | ||
return _ref.apply(this, arguments); | ||
return function loadPhrases(_x3) { | ||
return _ref2.apply(this, arguments); | ||
}; | ||
@@ -54,0 +105,0 @@ }(); |
@@ -82,4 +82,4 @@ "use strict"; | ||
key: "extend", | ||
value: function extend(phrases) { | ||
var p = this.getInstance(); | ||
value: function extend(phrases, locale) { | ||
var p = this.getInstance(locale); | ||
p.extend(phrases); | ||
@@ -86,0 +86,0 @@ } |
{ | ||
"name": "@cloudflare/intl-core", | ||
"description": "", | ||
"version": "1.0.13", | ||
"version": "1.0.14", | ||
"types": "./src", | ||
@@ -6,0 +6,0 @@ "main": "lib/index.js", |
@@ -1,2 +0,7 @@ | ||
import { TLoadPhrases, ESupportedLocales, TPhrasesModule } from '../src'; | ||
import { | ||
TLoadPhrases, | ||
ESupportedLocales, | ||
TPhrasesModule, | ||
IPhrases | ||
} from './index'; | ||
@@ -8,15 +13,29 @@ type TLoadLocales = { | ||
type TMakeLoadPhrases = (locales: TLoadLocales) => TLoadPhrases; | ||
type TLoadLocale = ( | ||
locales: TLoadLocales, | ||
locale: ESupportedLocales | ||
) => Promise<IPhrases>; | ||
const loadLocale: TLoadLocale = async (locales, locale: ESupportedLocales) => { | ||
const module: TPhrasesModule = await locales[locale](); | ||
// with weback 4.0 the module is loaded into the default attr | ||
// in older versions it is not | ||
return module.default ? module.default : module; | ||
}; | ||
//returns a function which returns a Promise resolving in phrases for a particular locale. | ||
//loads english catalog by default and overwrites it with catalog in target language. | ||
//so that for any phrases for which target language catalog is missing a value, the english one is used. | ||
const makeLoadPhrases: TMakeLoadPhrases = function loadPhrases(locales) { | ||
const loadPhrases: TLoadPhrases = async (locale: ESupportedLocales) => { | ||
let module: TPhrasesModule; | ||
module = await locales[locale](); | ||
// with weback 4.0 the module is loaded into the default attr | ||
// in older versions it is not | ||
if (module!.default) { | ||
return module!.default; | ||
if (locale === ESupportedLocales.en_US) { | ||
return loadLocale(locales, locale); | ||
} | ||
return module!; | ||
const [enPhrases, otherPhrases] = await Promise.all([ | ||
loadLocale(locales, ESupportedLocales.en_US), | ||
loadLocale(locales, locale) | ||
]); | ||
return { ...enPhrases, ...otherPhrases }; | ||
}; | ||
@@ -23,0 +42,0 @@ |
@@ -60,4 +60,4 @@ import Polyglot from 'node-polyglot'; | ||
extend(phrases: IPhrases) { | ||
const p = this.getInstance(); | ||
extend(phrases: IPhrases, locale?: ESupportedLocales) { | ||
const p = this.getInstance(locale); | ||
p.extend(phrases); | ||
@@ -64,0 +64,0 @@ } |
30747
661