@commercetools-frontend/l10n 21.23.10 → 21.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,8 +6,6 @@ var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable
|
|
|
6
6
|
var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
|
|
7
7
|
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
8
8
|
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
9
|
-
var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
|
|
10
|
-
var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
|
|
11
9
|
var PropTypes = require('prop-types');
|
|
12
10
|
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
13
11
|
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
@@ -27,7 +25,6 @@ var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instan
|
|
|
27
25
|
var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries');
|
|
28
26
|
var _parseFloat = require('@babel/runtime-corejs3/core-js-stable/parse-float');
|
|
29
27
|
var moment = require('moment-timezone');
|
|
30
|
-
var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArray');
|
|
31
28
|
var omit = require('lodash/omit');
|
|
32
29
|
|
|
33
30
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
@@ -36,7 +33,6 @@ var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsW
|
|
|
36
33
|
var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
|
|
37
34
|
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
38
35
|
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
|
|
39
|
-
var _regeneratorRuntime__default = /*#__PURE__*/_interopDefault(_regeneratorRuntime);
|
|
40
36
|
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
|
|
41
37
|
var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
|
|
42
38
|
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
@@ -54,29 +50,27 @@ var moment__default = /*#__PURE__*/_interopDefault(moment);
|
|
|
54
50
|
var omit__default = /*#__PURE__*/_interopDefault(omit);
|
|
55
51
|
|
|
56
52
|
// NOTE: This string will be replaced on build time with the package version.
|
|
57
|
-
var version = "21.
|
|
53
|
+
var version = "21.24.0";
|
|
58
54
|
|
|
59
|
-
|
|
55
|
+
const mapLocaleToIntlLocale = locale => {
|
|
60
56
|
if (_startsWithInstanceProperty__default["default"](locale).call(locale, 'de')) return 'de';
|
|
61
57
|
if (_startsWithInstanceProperty__default["default"](locale).call(locale, 'es')) return 'es';
|
|
62
58
|
if (_startsWithInstanceProperty__default["default"](locale).call(locale, 'fr')) return 'fr-FR';
|
|
63
59
|
if (locale === 'zh-CN') return 'zh-CN';
|
|
64
60
|
return 'en';
|
|
65
61
|
};
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
const supportedLocales = ['en', 'de', 'es', 'fr-FR', 'zh-CN'];
|
|
63
|
+
const defaultLocale = 'en'; // Given a locale, return the locale only if it's supported.
|
|
68
64
|
// If not, return a default locale.
|
|
69
65
|
|
|
70
66
|
function getSupportedLocale(locale) {
|
|
71
|
-
|
|
72
|
-
return _startsWithInstanceProperty__default["default"](locale).call(locale, supportedLocale);
|
|
73
|
-
});
|
|
67
|
+
const isSupported = _findInstanceProperty__default["default"](supportedLocales).call(supportedLocales, supportedLocale => _startsWithInstanceProperty__default["default"](locale).call(locale, supportedLocale));
|
|
74
68
|
|
|
75
69
|
return isSupported ? locale : defaultLocale;
|
|
76
70
|
} // given a currenyCode and a list of currencies with the following shape
|
|
77
71
|
// [{ label, symbol }], we return the symbol.
|
|
78
72
|
|
|
79
|
-
|
|
73
|
+
const getSymbolFromCurrency = (currencyCode, currencies) => {
|
|
80
74
|
if (currencies[currencyCode] && currencies[currencyCode].symbol) {
|
|
81
75
|
return currencies[currencyCode].symbol;
|
|
82
76
|
}
|
|
@@ -84,7 +78,7 @@ var getSymbolFromCurrency = function getSymbolFromCurrency(currencyCode, currenc
|
|
|
84
78
|
return '';
|
|
85
79
|
}; // From https://github.com/acdlite/recompose/blob/master/src/packages/recompose/getDisplayName.js
|
|
86
80
|
|
|
87
|
-
|
|
81
|
+
const getDisplayName = Component => {
|
|
88
82
|
if (typeof Component === 'string') {
|
|
89
83
|
return Component;
|
|
90
84
|
}
|
|
@@ -95,34 +89,30 @@ var getDisplayName = function getDisplayName(Component) {
|
|
|
95
89
|
|
|
96
90
|
return Component.displayName || Component.name || 'Component';
|
|
97
91
|
};
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
};
|
|
101
|
-
var formatLocalizedFallbackHint = function formatLocalizedFallbackHint(value, locale) {
|
|
92
|
+
const getPrimaryLocale = locale => locale.split('-')[0];
|
|
93
|
+
const formatLocalizedFallbackHint = (value, locale) => {
|
|
102
94
|
var _context;
|
|
103
95
|
|
|
104
96
|
return _concatInstanceProperty__default["default"](_context = "".concat(value, " (")).call(_context, locale.toUpperCase(), ")");
|
|
105
97
|
};
|
|
106
|
-
|
|
98
|
+
const findFallbackLocale = (localizedString, fallbackOrder) => {
|
|
107
99
|
var _context2;
|
|
108
100
|
|
|
109
|
-
return _findInstanceProperty__default["default"](_context2 = _concatInstanceProperty__default["default"](fallbackOrder).call(fallbackOrder, _Object$keys__default["default"](localizedString))).call(_context2,
|
|
110
|
-
return Boolean(localizedString[lang]);
|
|
111
|
-
});
|
|
101
|
+
return _findInstanceProperty__default["default"](_context2 = _concatInstanceProperty__default["default"](fallbackOrder).call(fallbackOrder, _Object$keys__default["default"](localizedString))).call(_context2, lang => Boolean(localizedString[lang]));
|
|
112
102
|
};
|
|
113
103
|
|
|
114
104
|
function ownKeys$2(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
115
105
|
|
|
116
|
-
function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var
|
|
117
|
-
|
|
106
|
+
function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context2 = ownKeys$2(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context3 = ownKeys$2(Object(source))).call(_context3, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
107
|
+
const initialState = {
|
|
118
108
|
isLoading: true,
|
|
119
109
|
// Keep it as an empty object, for backwards compatibility
|
|
120
110
|
data: {}
|
|
121
111
|
};
|
|
122
112
|
|
|
123
113
|
function reducer() {
|
|
124
|
-
|
|
125
|
-
|
|
114
|
+
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState;
|
|
115
|
+
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
126
116
|
|
|
127
117
|
switch (action.type) {
|
|
128
118
|
case 'loading':
|
|
@@ -149,74 +139,44 @@ function reducer() {
|
|
|
149
139
|
}
|
|
150
140
|
|
|
151
141
|
function createL10NHook(loadLocale) {
|
|
152
|
-
return
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
react.useEffect(
|
|
159
|
-
|
|
142
|
+
return locale => {
|
|
143
|
+
const _useReducer = react.useReducer(reducer, initialState),
|
|
144
|
+
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
145
|
+
data = _useReducer2[0],
|
|
146
|
+
dispatch = _useReducer2[1];
|
|
147
|
+
|
|
148
|
+
react.useEffect(() => {
|
|
149
|
+
let cleaning = false;
|
|
160
150
|
dispatch({
|
|
161
151
|
type: 'loading'
|
|
162
152
|
});
|
|
163
153
|
|
|
164
|
-
function run() {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (!cleaning) {
|
|
184
|
-
dispatch({
|
|
185
|
-
type: 'ok',
|
|
186
|
-
data: _data
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
_context.next = 10;
|
|
191
|
-
break;
|
|
192
|
-
|
|
193
|
-
case 7:
|
|
194
|
-
_context.prev = 7;
|
|
195
|
-
_context.t0 = _context["catch"](0);
|
|
196
|
-
|
|
197
|
-
if (_context.t0 instanceof Error) {
|
|
198
|
-
sentry.reportErrorToSentry(_context.t0);
|
|
199
|
-
|
|
200
|
-
if (!cleaning) {
|
|
201
|
-
dispatch({
|
|
202
|
-
type: 'error',
|
|
203
|
-
error: _context.t0
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
case 10:
|
|
209
|
-
case "end":
|
|
210
|
-
return _context.stop();
|
|
211
|
-
}
|
|
154
|
+
async function run() {
|
|
155
|
+
try {
|
|
156
|
+
const data = await loadLocale(locale);
|
|
157
|
+
|
|
158
|
+
if (!cleaning) {
|
|
159
|
+
dispatch({
|
|
160
|
+
type: 'ok',
|
|
161
|
+
data
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
} catch (error) {
|
|
165
|
+
if (error instanceof Error) {
|
|
166
|
+
sentry.reportErrorToSentry(error);
|
|
167
|
+
|
|
168
|
+
if (!cleaning) {
|
|
169
|
+
dispatch({
|
|
170
|
+
type: 'error',
|
|
171
|
+
error
|
|
172
|
+
});
|
|
212
173
|
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return _run.apply(this, arguments);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
216
176
|
}
|
|
217
177
|
|
|
218
178
|
run();
|
|
219
|
-
return
|
|
179
|
+
return () => {
|
|
220
180
|
cleaning = true;
|
|
221
181
|
};
|
|
222
182
|
}, [locale]);
|
|
@@ -224,30 +184,31 @@ function createL10NHook(loadLocale) {
|
|
|
224
184
|
};
|
|
225
185
|
}
|
|
226
186
|
function createL10NInjector(_ref) {
|
|
227
|
-
|
|
187
|
+
let displayName = _ref.displayName,
|
|
228
188
|
propKey = _ref.propKey,
|
|
229
189
|
propLoadingKey = _ref.propLoadingKey,
|
|
230
190
|
loadLocale = _ref.loadLocale;
|
|
231
191
|
return function createHOC(mapPropsToLocale) {
|
|
232
|
-
|
|
233
|
-
return
|
|
234
|
-
var
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
192
|
+
const useL10n = createL10NHook(loadLocale);
|
|
193
|
+
return WrappedComponent => {
|
|
194
|
+
var _context;
|
|
195
|
+
|
|
196
|
+
const L10NComponent = props => {
|
|
197
|
+
const state = useL10n(mapPropsToLocale(props));
|
|
198
|
+
return jsxRuntime.jsx(WrappedComponent, _objectSpread$2(_objectSpread$2({}, props), {}, {
|
|
199
|
+
[propLoadingKey]: state.isLoading,
|
|
200
|
+
[propKey]: state.data
|
|
201
|
+
}));
|
|
241
202
|
};
|
|
242
203
|
|
|
243
|
-
L10NComponent.displayName = _concatInstanceProperty__default["default"](
|
|
204
|
+
L10NComponent.displayName = _concatInstanceProperty__default["default"](_context = "".concat(displayName, "(")).call(_context, getDisplayName(WrappedComponent), ")");
|
|
244
205
|
return L10NComponent;
|
|
245
206
|
};
|
|
246
207
|
};
|
|
247
208
|
}
|
|
248
209
|
|
|
249
|
-
|
|
250
|
-
|
|
210
|
+
const getImportChunk$3 = locale => {
|
|
211
|
+
const intlLocale = mapLocaleToIntlLocale(locale);
|
|
251
212
|
|
|
252
213
|
switch (intlLocale) {
|
|
253
214
|
case 'de':
|
|
@@ -277,53 +238,33 @@ var getImportChunk$3 = function getImportChunk(locale) {
|
|
|
277
238
|
}
|
|
278
239
|
};
|
|
279
240
|
|
|
280
|
-
|
|
241
|
+
const countriesShape = PropTypes__default["default"].objectOf(PropTypes__default["default"].string);
|
|
281
242
|
/**
|
|
282
243
|
* If running through webpack, code splitting makes `getCountriesForLocale`
|
|
283
244
|
* a function that asynchronously loads the country data.
|
|
284
245
|
*/
|
|
285
246
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
while (1) {
|
|
291
|
-
switch (_context.prev = _context.next) {
|
|
292
|
-
case 0:
|
|
293
|
-
supportedLocale = getSupportedLocale(locale); // Use default webpackMode (lazy) so that we generate one file per locale.
|
|
294
|
-
// The files are named like "country-data-en-json.chunk.js" after compilation
|
|
295
|
-
// https://webpack.js.org/api/module-methods/#import-
|
|
296
|
-
|
|
297
|
-
_context.next = 3;
|
|
298
|
-
return getImportChunk$3(supportedLocale);
|
|
299
|
-
|
|
300
|
-
case 3:
|
|
301
|
-
countries = _context.sent;
|
|
302
|
-
return _context.abrupt("return", countries.default || countries);
|
|
303
|
-
|
|
304
|
-
case 5:
|
|
305
|
-
case "end":
|
|
306
|
-
return _context.stop();
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}, _callee);
|
|
310
|
-
}));
|
|
247
|
+
const getCountriesForLocale = async locale => {
|
|
248
|
+
const supportedLocale = getSupportedLocale(locale); // Use default webpackMode (lazy) so that we generate one file per locale.
|
|
249
|
+
// The files are named like "country-data-en-json.chunk.js" after compilation
|
|
250
|
+
// https://webpack.js.org/api/module-methods/#import-
|
|
311
251
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
};
|
|
315
|
-
}();
|
|
252
|
+
const countries = await getImportChunk$3(supportedLocale); // Prefer loading `default` (for ESM bundles) and
|
|
253
|
+
// fall back to normal import (for CJS bundles).
|
|
316
254
|
|
|
317
|
-
|
|
255
|
+
return countries.default || countries;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
const withCountries = createL10NInjector({
|
|
318
259
|
displayName: 'withCountries',
|
|
319
260
|
propKey: 'countries',
|
|
320
261
|
propLoadingKey: 'isLoadingCountries',
|
|
321
262
|
loadLocale: getCountriesForLocale
|
|
322
263
|
});
|
|
323
|
-
|
|
264
|
+
const useCountries = createL10NHook(getCountriesForLocale);
|
|
324
265
|
|
|
325
|
-
|
|
326
|
-
|
|
266
|
+
const getImportChunk$2 = locale => {
|
|
267
|
+
const intlLocale = mapLocaleToIntlLocale(locale);
|
|
327
268
|
|
|
328
269
|
switch (intlLocale) {
|
|
329
270
|
case 'de':
|
|
@@ -362,47 +303,27 @@ PropTypes__default["default"].objectOf(PropTypes__default["default"].shape({
|
|
|
362
303
|
* a function that asynchronously loads the country data.
|
|
363
304
|
*/
|
|
364
305
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
while (1) {
|
|
370
|
-
switch (_context.prev = _context.next) {
|
|
371
|
-
case 0:
|
|
372
|
-
supportedLocale = getSupportedLocale(locale); // Use default webpackMode (lazy) so that we generate one file per locale.
|
|
373
|
-
// The files are named like "currency-data-en-json.chunk.js" after compilation
|
|
374
|
-
// https://webpack.js.org/api/module-methods/#import-
|
|
375
|
-
|
|
376
|
-
_context.next = 3;
|
|
377
|
-
return getImportChunk$2(supportedLocale);
|
|
378
|
-
|
|
379
|
-
case 3:
|
|
380
|
-
currencies = _context.sent;
|
|
381
|
-
return _context.abrupt("return", currencies.default || currencies);
|
|
382
|
-
|
|
383
|
-
case 5:
|
|
384
|
-
case "end":
|
|
385
|
-
return _context.stop();
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
}, _callee);
|
|
389
|
-
}));
|
|
306
|
+
const getCurrenciesForLocale = async locale => {
|
|
307
|
+
const supportedLocale = getSupportedLocale(locale); // Use default webpackMode (lazy) so that we generate one file per locale.
|
|
308
|
+
// The files are named like "currency-data-en-json.chunk.js" after compilation
|
|
309
|
+
// https://webpack.js.org/api/module-methods/#import-
|
|
390
310
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
};
|
|
394
|
-
}();
|
|
311
|
+
const currencies = await getImportChunk$2(supportedLocale); // Prefer loading `default` (for ESM bundles) and
|
|
312
|
+
// fall back to normal import (for CJS bundles).
|
|
395
313
|
|
|
396
|
-
|
|
314
|
+
return currencies.default || currencies;
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
const withCurrencies = createL10NInjector({
|
|
397
318
|
displayName: 'withCurrencies',
|
|
398
319
|
propKey: 'currencies',
|
|
399
320
|
propLoadingKey: 'isLoadingCurrencies',
|
|
400
321
|
loadLocale: getCurrenciesForLocale
|
|
401
322
|
});
|
|
402
|
-
|
|
323
|
+
const useCurrencies = createL10NHook(getCurrenciesForLocale);
|
|
403
324
|
|
|
404
|
-
|
|
405
|
-
|
|
325
|
+
const getImportChunk$1 = locale => {
|
|
326
|
+
const intlLocale = mapLocaleToIntlLocale(locale);
|
|
406
327
|
|
|
407
328
|
switch (intlLocale) {
|
|
408
329
|
case 'de':
|
|
@@ -432,7 +353,7 @@ var getImportChunk$1 = function getImportChunk(locale) {
|
|
|
432
353
|
}
|
|
433
354
|
};
|
|
434
355
|
|
|
435
|
-
|
|
356
|
+
const languagesShape = PropTypes__default["default"].objectOf(PropTypes__default["default"].shape({
|
|
436
357
|
country: PropTypes__default["default"].string,
|
|
437
358
|
language: PropTypes__default["default"].string.isRequired
|
|
438
359
|
}));
|
|
@@ -441,130 +362,66 @@ var languagesShape = PropTypes__default["default"].objectOf(PropTypes__default["
|
|
|
441
362
|
* a function that asynchronously loads the country data.
|
|
442
363
|
*/
|
|
443
364
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
while (1) {
|
|
449
|
-
switch (_context.prev = _context.next) {
|
|
450
|
-
case 0:
|
|
451
|
-
supportedLocale = getSupportedLocale(locale); // Use default webpackMode (lazy) so that we generate one file per locale.
|
|
452
|
-
// The files are named like "language-data-en-json.chunk.js" after compilation
|
|
453
|
-
// https://webpack.js.org/api/module-methods/#import-
|
|
454
|
-
|
|
455
|
-
_context.next = 3;
|
|
456
|
-
return getImportChunk$1(supportedLocale);
|
|
457
|
-
|
|
458
|
-
case 3:
|
|
459
|
-
languages = _context.sent;
|
|
460
|
-
return _context.abrupt("return", languages.default || languages);
|
|
461
|
-
|
|
462
|
-
case 5:
|
|
463
|
-
case "end":
|
|
464
|
-
return _context.stop();
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
}, _callee);
|
|
468
|
-
}));
|
|
365
|
+
const getLanguagesForLocale = async locale => {
|
|
366
|
+
const supportedLocale = getSupportedLocale(locale); // Use default webpackMode (lazy) so that we generate one file per locale.
|
|
367
|
+
// The files are named like "language-data-en-json.chunk.js" after compilation
|
|
368
|
+
// https://webpack.js.org/api/module-methods/#import-
|
|
469
369
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
};
|
|
473
|
-
}();
|
|
370
|
+
const languages = await getImportChunk$1(supportedLocale); // Prefer loading `default` (for ESM bundles) and
|
|
371
|
+
// fall back to normal import (for CJS bundles).
|
|
474
372
|
|
|
475
|
-
|
|
373
|
+
return languages.default || languages;
|
|
374
|
+
};
|
|
375
|
+
|
|
376
|
+
const withLanguages = createL10NInjector({
|
|
476
377
|
displayName: 'withLanguages',
|
|
477
378
|
propKey: 'languages',
|
|
478
379
|
propLoadingKey: 'isLoadingLanguages',
|
|
479
380
|
loadLocale: getLanguagesForLocale
|
|
480
381
|
});
|
|
481
|
-
|
|
382
|
+
const useLanguages = createL10NHook(getLanguagesForLocale);
|
|
482
383
|
|
|
483
384
|
function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
484
385
|
|
|
485
|
-
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var
|
|
486
|
-
|
|
487
|
-
var getTranslationsMapChunk = /*#__PURE__*/function () {
|
|
488
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
|
|
489
|
-
var translationsMapChunk;
|
|
490
|
-
return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
|
|
491
|
-
while (1) {
|
|
492
|
-
switch (_context.prev = _context.next) {
|
|
493
|
-
case 0:
|
|
494
|
-
_context.next = 2;
|
|
495
|
-
return Promise.resolve().then(function () { return require(
|
|
496
|
-
/* webpackChunkName: "time-zone-translations-map" */
|
|
497
|
-
'./translations-map-0e2bd91e.cjs.dev.js'); });
|
|
498
|
-
|
|
499
|
-
case 2:
|
|
500
|
-
translationsMapChunk = _context.sent;
|
|
501
|
-
return _context.abrupt("return", translationsMapChunk.default || translationsMapChunk);
|
|
502
|
-
|
|
503
|
-
case 4:
|
|
504
|
-
case "end":
|
|
505
|
-
return _context.stop();
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
}, _callee);
|
|
509
|
-
}));
|
|
386
|
+
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context4, _context5; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context4 = ownKeys$1(Object(source), !0)).call(_context4, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context5 = ownKeys$1(Object(source))).call(_context5, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
510
387
|
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
}()
|
|
388
|
+
const getTranslationsMapChunk = async () => {
|
|
389
|
+
const translationsMapChunk = await Promise.resolve().then(function () { return require(
|
|
390
|
+
/* webpackChunkName: "time-zone-translations-map" */
|
|
391
|
+
'./translations-map-0e2bd91e.cjs.dev.js'); }); // Prefer loading `default` (for ESM bundles) and
|
|
392
|
+
// fall back to normal import (for CJS bundles).
|
|
393
|
+
|
|
394
|
+
return translationsMapChunk.default || translationsMapChunk;
|
|
395
|
+
};
|
|
515
396
|
/**
|
|
516
397
|
* Build offset and abbreviation data for each timezone at runtime from moment-timezone
|
|
517
398
|
* in order to return accurate offset values for timezones that have daylight time.
|
|
518
399
|
*/
|
|
519
400
|
|
|
520
401
|
|
|
521
|
-
|
|
522
|
-
var
|
|
523
|
-
var _context2, _context3, _context4;
|
|
524
|
-
|
|
525
|
-
var translationsMap;
|
|
526
|
-
return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context5) {
|
|
527
|
-
while (1) {
|
|
528
|
-
switch (_context5.prev = _context5.next) {
|
|
529
|
-
case 0:
|
|
530
|
-
_context5.next = 2;
|
|
531
|
-
return getTranslationsMapChunk();
|
|
532
|
-
|
|
533
|
-
case 2:
|
|
534
|
-
translationsMap = _context5.sent;
|
|
535
|
-
return _context5.abrupt("return", _reduceInstanceProperty__default["default"](_context2 = _sortInstanceProperty__default["default"](_context3 = _mapInstanceProperty__default["default"](_context4 = _Object$entries__default["default"](timeZones)).call(_context4, function (_ref3) {
|
|
536
|
-
var _ref4 = _slicedToArray(_ref3, 2),
|
|
537
|
-
id = _ref4[0],
|
|
538
|
-
name = _ref4[1];
|
|
539
|
-
|
|
540
|
-
return {
|
|
541
|
-
id: id,
|
|
542
|
-
name: name,
|
|
543
|
-
abbr: moment__default["default"]().tz(id).zoneAbbr(),
|
|
544
|
-
offset: moment__default["default"]().tz(id).format('Z'),
|
|
545
|
-
translationFor: translationsMap[id]
|
|
546
|
-
};
|
|
547
|
-
})).call(_context3, function (a, b) {
|
|
548
|
-
return _parseFloat__default["default"](a.offset.replace(':', '.')) - _parseFloat__default["default"](b.offset.replace(':', '.'));
|
|
549
|
-
})).call(_context2, function (previousTimeZones, timeZone) {
|
|
550
|
-
return _objectSpread$1(_objectSpread$1({}, previousTimeZones), {}, _defineProperty({}, timeZone.id, timeZone));
|
|
551
|
-
}, {}));
|
|
552
|
-
|
|
553
|
-
case 4:
|
|
554
|
-
case "end":
|
|
555
|
-
return _context5.stop();
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
}, _callee2);
|
|
559
|
-
}));
|
|
402
|
+
const augmentTimeZoneData = async timeZones => {
|
|
403
|
+
var _context, _context2, _context3;
|
|
560
404
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
405
|
+
const translationsMap = await getTranslationsMapChunk();
|
|
406
|
+
return _reduceInstanceProperty__default["default"](_context = _sortInstanceProperty__default["default"](_context2 = _mapInstanceProperty__default["default"](_context3 = _Object$entries__default["default"](timeZones)).call(_context3, _ref => {
|
|
407
|
+
let _ref2 = _slicedToArray(_ref, 2),
|
|
408
|
+
id = _ref2[0],
|
|
409
|
+
name = _ref2[1];
|
|
565
410
|
|
|
566
|
-
|
|
567
|
-
|
|
411
|
+
return {
|
|
412
|
+
id,
|
|
413
|
+
name,
|
|
414
|
+
abbr: moment__default["default"]().tz(id).zoneAbbr(),
|
|
415
|
+
offset: moment__default["default"]().tz(id).format('Z'),
|
|
416
|
+
translationFor: translationsMap[id]
|
|
417
|
+
};
|
|
418
|
+
})).call(_context2, (a, b) => _parseFloat__default["default"](a.offset.replace(':', '.')) - _parseFloat__default["default"](b.offset.replace(':', '.')))).call(_context, (previousTimeZones, timeZone) => _objectSpread$1(_objectSpread$1({}, previousTimeZones), {}, {
|
|
419
|
+
[timeZone.id]: timeZone
|
|
420
|
+
}), {});
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
const getImportChunk = locale => {
|
|
424
|
+
const intlLocale = mapLocaleToIntlLocale(locale);
|
|
568
425
|
|
|
569
426
|
switch (intlLocale) {
|
|
570
427
|
case 'de':
|
|
@@ -594,7 +451,7 @@ var getImportChunk = function getImportChunk(locale) {
|
|
|
594
451
|
}
|
|
595
452
|
};
|
|
596
453
|
|
|
597
|
-
|
|
454
|
+
const timeZonesShape = PropTypes__default["default"].objectOf(PropTypes__default["default"].shape({
|
|
598
455
|
label: PropTypes__default["default"].string,
|
|
599
456
|
abbr: PropTypes__default["default"].string,
|
|
600
457
|
offset: PropTypes__default["default"].string,
|
|
@@ -605,67 +462,41 @@ var timeZonesShape = PropTypes__default["default"].objectOf(PropTypes__default["
|
|
|
605
462
|
* a function that asynchronously loads the country data.
|
|
606
463
|
*/
|
|
607
464
|
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
while (1) {
|
|
613
|
-
switch (_context6.prev = _context6.next) {
|
|
614
|
-
case 0:
|
|
615
|
-
supportedLocale = getSupportedLocale(locale); // Use default webpackMode (lazy) so that we generate one file per locale.
|
|
616
|
-
// The files are named like "time-zone-data-en-json.chunk.js" after compilation
|
|
617
|
-
// https://webpack.js.org/api/module-methods/#import-
|
|
618
|
-
|
|
619
|
-
_context6.next = 3;
|
|
620
|
-
return getImportChunk(supportedLocale);
|
|
621
|
-
|
|
622
|
-
case 3:
|
|
623
|
-
timeZonesChunk = _context6.sent;
|
|
624
|
-
// Prefer loading `default` (for ESM bundles) and
|
|
625
|
-
// fall back to normal import (for CJS bundles).
|
|
626
|
-
timeZones = timeZonesChunk.default || timeZonesChunk; // create time zone object with abbreviations and offsets
|
|
627
|
-
|
|
628
|
-
_context6.next = 7;
|
|
629
|
-
return augmentTimeZoneData(timeZones);
|
|
630
|
-
|
|
631
|
-
case 7:
|
|
632
|
-
timeZoneData = _context6.sent;
|
|
633
|
-
return _context6.abrupt("return", timeZoneData);
|
|
634
|
-
|
|
635
|
-
case 9:
|
|
636
|
-
case "end":
|
|
637
|
-
return _context6.stop();
|
|
638
|
-
}
|
|
639
|
-
}
|
|
640
|
-
}, _callee3);
|
|
641
|
-
}));
|
|
465
|
+
const getTimeZonesForLocale = async locale => {
|
|
466
|
+
const supportedLocale = getSupportedLocale(locale); // Use default webpackMode (lazy) so that we generate one file per locale.
|
|
467
|
+
// The files are named like "time-zone-data-en-json.chunk.js" after compilation
|
|
468
|
+
// https://webpack.js.org/api/module-methods/#import-
|
|
642
469
|
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
470
|
+
const timeZonesChunk = await getImportChunk(supportedLocale); // Prefer loading `default` (for ESM bundles) and
|
|
471
|
+
// fall back to normal import (for CJS bundles).
|
|
472
|
+
|
|
473
|
+
const timeZones = timeZonesChunk.default || timeZonesChunk; // create time zone object with abbreviations and offsets
|
|
647
474
|
|
|
648
|
-
|
|
475
|
+
const timeZoneData = await augmentTimeZoneData(timeZones);
|
|
476
|
+
return timeZoneData;
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
const withTimeZones = createL10NInjector({
|
|
649
480
|
displayName: 'withTimeZones',
|
|
650
481
|
propKey: 'timeZones',
|
|
651
482
|
propLoadingKey: 'isLoadingTimeZones',
|
|
652
483
|
loadLocale: getTimeZonesForLocale
|
|
653
484
|
});
|
|
654
|
-
|
|
485
|
+
const useTimeZones = createL10NHook(getTimeZonesForLocale);
|
|
655
486
|
|
|
656
487
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
657
488
|
|
|
658
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var
|
|
489
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
659
490
|
/**
|
|
660
491
|
* Transforms a list of `LocalizedField` into a `LocalizedString` object
|
|
661
492
|
* [{ locale: 'sv', value: 'Hej' }] -> { sv: 'Hej' }
|
|
662
493
|
*/
|
|
663
494
|
|
|
664
|
-
|
|
495
|
+
const transformLocalizedFieldToLocalizedString = localizedFields => {
|
|
665
496
|
if (!localizedFields || localizedFields.length === 0) return null;
|
|
666
|
-
return _reduceInstanceProperty__default["default"](localizedFields).call(localizedFields,
|
|
667
|
-
|
|
668
|
-
}, {});
|
|
497
|
+
return _reduceInstanceProperty__default["default"](localizedFields).call(localizedFields, (nexLocalizedString, field) => _objectSpread(_objectSpread({}, nexLocalizedString), {}, {
|
|
498
|
+
[field.locale]: field.value
|
|
499
|
+
}), {});
|
|
669
500
|
};
|
|
670
501
|
/**
|
|
671
502
|
* Transforms a `LocalizedString` object into a list of `LocalizedField`
|
|
@@ -673,21 +504,17 @@ var transformLocalizedFieldToLocalizedString = function transformLocalizedFieldT
|
|
|
673
504
|
* { sv: 'Hej' } -> [{ locale: 'sv', value: 'Hej' }]
|
|
674
505
|
*/
|
|
675
506
|
|
|
676
|
-
|
|
507
|
+
const transformLocalizedStringToLocalizedField = localizedString => {
|
|
677
508
|
var _context;
|
|
678
509
|
|
|
679
510
|
if (!localizedString || _Object$keys__default["default"](localizedString).length === 0) return [];
|
|
680
511
|
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
return _reduceInstanceProperty__default["default"](sorted).call(sorted, function (updatedLocalizedField, locale) {
|
|
684
|
-
var _context2;
|
|
512
|
+
const sorted = _sortInstanceProperty__default["default"](_context = _Object$keys__default["default"](localizedString)).call(_context);
|
|
685
513
|
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
}, []);
|
|
514
|
+
return _reduceInstanceProperty__default["default"](sorted).call(sorted, (updatedLocalizedField, locale) => [...updatedLocalizedField, {
|
|
515
|
+
locale,
|
|
516
|
+
value: localizedString[locale]
|
|
517
|
+
}], []);
|
|
691
518
|
};
|
|
692
519
|
/**
|
|
693
520
|
* Given a list of localized field names to map, replace the fields in the
|
|
@@ -703,16 +530,14 @@ var transformLocalizedStringToLocalizedField = function transformLocalizedString
|
|
|
703
530
|
* * `to`: the target field to write the transformed shape
|
|
704
531
|
*/
|
|
705
532
|
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
}, {});
|
|
533
|
+
const applyTransformedLocalizedFields = (objectWithLocalizedFields, fieldNames) => {
|
|
534
|
+
const transformedFieldDefinitions = _reduceInstanceProperty__default["default"](fieldNames).call(fieldNames, (nextTransformed, fieldName) => _objectSpread(_objectSpread({}, nextTransformed), {}, {
|
|
535
|
+
[fieldName.to]: transformLocalizedFieldToLocalizedString(objectWithLocalizedFields[fieldName.from])
|
|
536
|
+
}), {});
|
|
710
537
|
|
|
711
|
-
|
|
712
|
-
return fieldName.from;
|
|
713
|
-
});
|
|
538
|
+
const namesToOmit = _mapInstanceProperty__default["default"](fieldNames).call(fieldNames, fieldName => fieldName.from);
|
|
714
539
|
|
|
715
|
-
|
|
540
|
+
const objectWithouLocalizedFields = omit__default["default"](objectWithLocalizedFields, namesToOmit);
|
|
716
541
|
return _objectSpread(_objectSpread({}, objectWithouLocalizedFields), transformedFieldDefinitions);
|
|
717
542
|
};
|
|
718
543
|
/**
|
|
@@ -729,16 +554,14 @@ var applyTransformedLocalizedFields = function applyTransformedLocalizedFields(o
|
|
|
729
554
|
* * `to`: the target field to write the transformed shape
|
|
730
555
|
*/
|
|
731
556
|
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
}, {});
|
|
557
|
+
const applyTransformedLocalizedStrings = (objectWithLocalizedStrings, fieldNames) => {
|
|
558
|
+
const transformedFieldDefinitions = _reduceInstanceProperty__default["default"](fieldNames).call(fieldNames, (nextTransformed, fieldName) => _objectSpread(_objectSpread({}, nextTransformed), {}, {
|
|
559
|
+
[fieldName.to]: transformLocalizedStringToLocalizedField(objectWithLocalizedStrings[fieldName.from])
|
|
560
|
+
}), {});
|
|
736
561
|
|
|
737
|
-
|
|
738
|
-
return fieldName.from;
|
|
739
|
-
});
|
|
562
|
+
const namesToOmit = _mapInstanceProperty__default["default"](fieldNames).call(fieldNames, fieldName => fieldName.from);
|
|
740
563
|
|
|
741
|
-
|
|
564
|
+
const objectWithouLocalizedFields = omit__default["default"](objectWithLocalizedStrings, namesToOmit);
|
|
742
565
|
return _objectSpread(_objectSpread({}, objectWithouLocalizedFields), transformedFieldDefinitions);
|
|
743
566
|
};
|
|
744
567
|
/**
|
|
@@ -775,8 +598,8 @@ var applyTransformedLocalizedStrings = function applyTransformedLocalizedStrings
|
|
|
775
598
|
* a === b && a === c -> true
|
|
776
599
|
*/
|
|
777
600
|
|
|
778
|
-
|
|
779
|
-
|
|
601
|
+
const formatLocalizedString = (entity, _ref) => {
|
|
602
|
+
let _ref$key = _ref.key,
|
|
780
603
|
key = _ref$key === void 0 ? '' : _ref$key,
|
|
781
604
|
locale = _ref.locale,
|
|
782
605
|
_ref$fallbackOrder = _ref.fallbackOrder,
|
|
@@ -784,9 +607,9 @@ var formatLocalizedString = function formatLocalizedString(entity, _ref) {
|
|
|
784
607
|
_ref$fallback = _ref.fallback,
|
|
785
608
|
fallback = _ref$fallback === void 0 ? '' : _ref$fallback;
|
|
786
609
|
if (!entity || !entity[key]) return fallback;
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
610
|
+
const localizedString = entity[key];
|
|
611
|
+
const fallbackLocale = findFallbackLocale(localizedString, fallbackOrder);
|
|
612
|
+
const formattedLocalizedFallback = fallbackLocale ? formatLocalizedFallbackHint(localizedString[fallbackLocale], fallbackLocale) : fallback; // GIVEN no `locale`
|
|
790
613
|
// THEN return formattedFallback by fallbackOrder
|
|
791
614
|
|
|
792
615
|
if (!locale) return formattedLocalizedFallback; // GIVEN locale
|
|
@@ -797,7 +620,7 @@ var formatLocalizedString = function formatLocalizedString(entity, _ref) {
|
|
|
797
620
|
// AND there is a value on primary locale
|
|
798
621
|
// THEN return value on primary locale
|
|
799
622
|
|
|
800
|
-
|
|
623
|
+
const primaryLocale = locale && getPrimaryLocale(locale);
|
|
801
624
|
if (localizedString[primaryLocale]) return localizedString[primaryLocale]; // use formattedFallback by fallbackOrder as last resort
|
|
802
625
|
|
|
803
626
|
return formattedLocalizedFallback;
|