@commercetools-frontend/i18n 22.2.1 → 22.3.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.
@@ -20,171 +20,131 @@ import { jsx, Fragment } from '@emotion/react/jsx-runtime';
20
20
  import { defineMessages } from 'react-intl';
21
21
 
22
22
  // NOTE: This string will be replaced on build time with the package version.
23
- var version = "22.2.1";
23
+ var version = "22.3.0";
24
24
 
25
25
  // @ts-nocheck
26
-
27
26
  /* THIS IS A GENERATED FILE */
27
+
28
28
  async function loadMomentLocales(locale) {
29
29
  const lowercaseLocale = locale.toLowerCase();
30
-
31
30
  switch (lowercaseLocale) {
32
31
  case 'de':
33
32
  await import('moment/dist/locale/de');
34
33
  break;
35
-
36
34
  case 'de-at':
37
35
  await import('moment/dist/locale/de-at');
38
36
  break;
39
-
40
37
  case 'de-be':
41
38
  await import('moment/dist/locale/de');
42
39
  break;
43
-
44
40
  case 'de-ch':
45
41
  await import('moment/dist/locale/de-ch');
46
42
  break;
47
-
48
43
  case 'de-de':
49
44
  await import('moment/dist/locale/de');
50
45
  break;
51
-
52
46
  case 'de-li':
53
47
  await import('moment/dist/locale/de');
54
48
  break;
55
-
56
49
  case 'de-lu':
57
50
  await import('moment/dist/locale/de');
58
51
  break;
59
-
60
52
  case 'en-au':
61
53
  await import('moment/dist/locale/en-au');
62
54
  break;
63
-
64
55
  case 'en-ca':
65
56
  await import('moment/dist/locale/en-ca');
66
57
  break;
67
-
68
58
  case 'en-gb':
69
59
  await import('moment/dist/locale/en-gb');
70
60
  break;
71
-
72
61
  case 'en-ie':
73
62
  await import('moment/dist/locale/en-ie');
74
63
  break;
75
-
76
64
  case 'en-in':
77
65
  await import('moment/dist/locale/en-in');
78
66
  break;
79
-
80
67
  case 'en-nz':
81
68
  await import('moment/dist/locale/en-nz');
82
69
  break;
83
-
84
70
  case 'en-sg':
85
71
  await import('moment/dist/locale/en-sg');
86
72
  break;
87
-
88
73
  case 'es':
89
74
  await import('moment/dist/locale/es');
90
75
  break;
91
-
92
76
  case 'es-ar':
93
77
  await import('moment/dist/locale/es');
94
78
  break;
95
-
96
79
  case 'es-bo':
97
80
  await import('moment/dist/locale/es');
98
81
  break;
99
-
100
82
  case 'es-cl':
101
83
  await import('moment/dist/locale/es');
102
84
  break;
103
-
104
85
  case 'es-co':
105
86
  await import('moment/dist/locale/es');
106
87
  break;
107
-
108
88
  case 'es-cr':
109
89
  await import('moment/dist/locale/es');
110
90
  break;
111
-
112
91
  case 'es-cu':
113
92
  await import('moment/dist/locale/es');
114
93
  break;
115
-
116
94
  case 'es-do':
117
95
  await import('moment/dist/locale/es-do');
118
96
  break;
119
-
120
97
  case 'es-ea':
121
98
  await import('moment/dist/locale/es');
122
99
  break;
123
-
124
100
  case 'es-ec':
125
101
  await import('moment/dist/locale/es');
126
102
  break;
127
-
128
103
  case 'es-es':
129
104
  await import('moment/dist/locale/es');
130
105
  break;
131
-
132
106
  case 'es-gq':
133
107
  await import('moment/dist/locale/es');
134
108
  break;
135
-
136
109
  case 'es-gt':
137
110
  await import('moment/dist/locale/es');
138
111
  break;
139
-
140
112
  case 'es-hn':
141
113
  await import('moment/dist/locale/es');
142
114
  break;
143
-
144
115
  case 'es-ic':
145
116
  await import('moment/dist/locale/es');
146
117
  break;
147
-
148
118
  case 'es-mx':
149
119
  await import('moment/dist/locale/es-mx');
150
120
  break;
151
-
152
121
  case 'es-ni':
153
122
  await import('moment/dist/locale/es');
154
123
  break;
155
-
156
124
  case 'es-pa':
157
125
  await import('moment/dist/locale/es');
158
126
  break;
159
-
160
127
  case 'es-pe':
161
128
  await import('moment/dist/locale/es');
162
129
  break;
163
-
164
130
  case 'es-pr':
165
131
  await import('moment/dist/locale/es');
166
132
  break;
167
-
168
133
  case 'es-py':
169
134
  await import('moment/dist/locale/es');
170
135
  break;
171
-
172
136
  case 'es-sv':
173
137
  await import('moment/dist/locale/es');
174
138
  break;
175
-
176
139
  case 'es-uy':
177
140
  await import('moment/dist/locale/es');
178
141
  break;
179
-
180
142
  case 'es-ve':
181
143
  await import('moment/dist/locale/es');
182
144
  break;
183
-
184
145
  case 'fr-fr':
185
146
  await import('moment/dist/locale/fr');
186
147
  break;
187
-
188
148
  case 'zh-cn':
189
149
  await import('moment/dist/locale/zh-cn');
190
150
  break;
@@ -192,21 +152,18 @@ async function loadMomentLocales(locale) {
192
152
  }
193
153
 
194
154
  function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
195
-
196
155
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
197
156
  const extractLanguageTagFromLocale = locale => _includesInstanceProperty(locale).call(locale, '-') ? locale.split('-')[0] : locale;
198
157
  const isStructuredJson = message => (message === null || message === void 0 ? void 0 : message.string) !== undefined;
199
158
  const parseChunkImport = chunkImport => {
200
159
  var _context;
201
-
202
160
  // Prefer loading `default` (for ESM bundles) and
203
161
  // fall back to normal import (for CJS bundles).
204
162
  const contents = chunkImport.default || chunkImport;
205
163
  return _reduceInstanceProperty(_context = _Object$entries(contents)).call(_context, (messages, _ref) => {
206
164
  let _ref2 = _slicedToArray(_ref, 2),
207
- messageKey = _ref2[0],
208
- messageValue = _ref2[1];
209
-
165
+ messageKey = _ref2[0],
166
+ messageValue = _ref2[1];
210
167
  const messageAsString = isStructuredJson(messageValue) ? messageValue.string : messageValue;
211
168
  return _objectSpread(_objectSpread({}, messages), {}, {
212
169
  [messageKey]: messageAsString
@@ -217,7 +174,6 @@ const mergeMessages = function () {
217
174
  for (var _len = arguments.length, messages = new Array(_len), _key = 0; _key < _len; _key++) {
218
175
  messages[_key] = arguments[_key];
219
176
  }
220
-
221
177
  return _Object$assign({}, ...messages);
222
178
  };
223
179
  const mapLocaleToIntlLocale = locale => {
@@ -230,110 +186,67 @@ const mapLocaleToIntlLocale = locale => {
230
186
 
231
187
  const getUiKitChunkImport = locale => {
232
188
  const intlLocale = mapLocaleToIntlLocale(locale);
233
-
234
189
  switch (intlLocale) {
235
190
  case 'de':
236
- return import(
237
- /* webpackChunkName: "i18n-ui-kit-locale-de" */
238
- '@commercetools-uikit/i18n/compiled-data/de.json');
239
-
191
+ return import( /* webpackChunkName: "i18n-ui-kit-locale-de" */'@commercetools-uikit/i18n/compiled-data/de.json');
240
192
  case 'es':
241
- return import(
242
- /* webpackChunkName: "i18n-ui-kit-locale-es" */
243
- '@commercetools-uikit/i18n/compiled-data/es.json');
244
-
193
+ return import( /* webpackChunkName: "i18n-ui-kit-locale-es" */'@commercetools-uikit/i18n/compiled-data/es.json');
245
194
  case 'fr-FR':
246
- return import(
247
- /* webpackChunkName: "i18n-ui-kit-locale-fr-FR" */
248
- '@commercetools-uikit/i18n/compiled-data/fr-FR.json');
249
-
195
+ return import( /* webpackChunkName: "i18n-ui-kit-locale-fr-FR" */'@commercetools-uikit/i18n/compiled-data/fr-FR.json');
250
196
  case 'zh-CN':
251
- return import(
252
- /* webpackChunkName: "i18n-ui-kit-locale-zh-CN" */
253
- '@commercetools-uikit/i18n/compiled-data/zh-CN.json');
254
-
197
+ return import( /* webpackChunkName: "i18n-ui-kit-locale-zh-CN" */'@commercetools-uikit/i18n/compiled-data/zh-CN.json');
255
198
  default:
256
- return import(
257
- /* webpackChunkName: "i18n-ui-kit-locale-en" */
258
- '@commercetools-uikit/i18n/compiled-data/en.json');
199
+ return import( /* webpackChunkName: "i18n-ui-kit-locale-en" */'@commercetools-uikit/i18n/compiled-data/en.json');
259
200
  }
260
201
  };
261
-
262
202
  const getAppKitChunkImport = locale => {
263
203
  const intlLocale = mapLocaleToIntlLocale(locale);
264
-
265
204
  switch (intlLocale) {
266
205
  case 'de':
267
- return import(
268
- /* webpackChunkName: "i18n-app-kit-locale-de" */
269
- './de-5a74ebff.esm.js');
270
-
206
+ return import( /* webpackChunkName: "i18n-app-kit-locale-de" */'./de-5a74ebff.esm.js');
271
207
  case 'es':
272
- return import(
273
- /* webpackChunkName: "i18n-app-kit-locale-es" */
274
- './es-425fb967.esm.js');
275
-
208
+ return import( /* webpackChunkName: "i18n-app-kit-locale-es" */'./es-425fb967.esm.js');
276
209
  case 'fr-FR':
277
- return import(
278
- /* webpackChunkName: "i18n-app-kit-locale-fr-FR" */
279
- './fr-FR-f69eb330.esm.js');
280
-
210
+ return import( /* webpackChunkName: "i18n-app-kit-locale-fr-FR" */'./fr-FR-f69eb330.esm.js');
281
211
  case 'zh-CN':
282
- return import(
283
- /* webpackChunkName: "i18n-app-kit-locale-zh-CN" */
284
- './zh-CN-0f904080.esm.js');
285
-
212
+ return import( /* webpackChunkName: "i18n-app-kit-locale-zh-CN" */'./zh-CN-0f904080.esm.js');
286
213
  default:
287
- return import(
288
- /* webpackChunkName: "i18n-app-kit-locale-en" */
289
- './en-4957742d.esm.js');
214
+ return import( /* webpackChunkName: "i18n-app-kit-locale-en" */'./en-4957742d.esm.js');
290
215
  }
291
216
  };
292
-
293
217
  const getCommunityKitChunkImport = async locale => {
294
218
  const intlLocale = mapLocaleToIntlLocale(locale);
295
-
296
219
  switch (intlLocale) {
297
220
  case 'de':
298
- return await import(
299
- /* webpackChunkName: "i18n-community-kit-locale-de" */
300
- '@commercetools-community-kit/i18n/compiled-data/de.json');
301
-
221
+ return await import( /* webpackChunkName: "i18n-community-kit-locale-de" */'@commercetools-community-kit/i18n/compiled-data/de.json');
302
222
  case 'es':
303
- return await import(
304
- /* webpackChunkName: "i18n-community-kit-locale-es" */
305
- '@commercetools-community-kit/i18n/compiled-data/es.json');
306
-
223
+ return await import( /* webpackChunkName: "i18n-community-kit-locale-es" */'@commercetools-community-kit/i18n/compiled-data/es.json');
307
224
  case 'fr-FR':
308
- return await import(
309
- /* webpackChunkName: "i18n-community-kit-locale-fr-FR" */
310
- '@commercetools-community-kit/i18n/compiled-data/fr-FR.json');
311
-
225
+ return await import( /* webpackChunkName: "i18n-community-kit-locale-fr-FR" */'@commercetools-community-kit/i18n/compiled-data/fr-FR.json');
312
226
  case 'zh-CN':
313
- return await import(
314
- /* webpackChunkName: "i18n-community-kit-locale-zh-CN" */
315
- '@commercetools-community-kit/i18n/compiled-data/zh-CN.json');
316
-
227
+ return await import( /* webpackChunkName: "i18n-community-kit-locale-zh-CN" */'@commercetools-community-kit/i18n/compiled-data/zh-CN.json');
317
228
  default:
318
- return await import(
319
- /* webpackChunkName: "i18n-community-kit-locale-en" */
320
- '@commercetools-community-kit/i18n/compiled-data/en.json');
229
+ return await import( /* webpackChunkName: "i18n-community-kit-locale-en" */'@commercetools-community-kit/i18n/compiled-data/en.json');
321
230
  }
322
- }; // Use default (lazy) so that we will receive one chunk per
323
- // locale. https://webpack.js.org/api/module-methods/#import-
324
-
231
+ };
325
232
 
233
+ // Use default (lazy) so that we will receive one chunk per
234
+ // locale. https://webpack.js.org/api/module-methods/#import-
326
235
  async function loadI18n(locale) {
327
236
  // Load moment localizations
328
- await loadMomentLocales(locale); // Load ui-kit translations
237
+ await loadMomentLocales(locale);
329
238
 
330
- const uiKitChunkImport = await getUiKitChunkImport(locale); // Load app-kit translations
239
+ // Load ui-kit translations
240
+ const uiKitChunkImport = await getUiKitChunkImport(locale);
331
241
 
332
- const appKitChunkImport = await getAppKitChunkImport(locale); // Load community-kit translations
242
+ // Load app-kit translations
243
+ const appKitChunkImport = await getAppKitChunkImport(locale);
333
244
 
334
- const communityKitChunkImport = await getCommunityKitChunkImport(locale); // Prefer loading `default` (for ESM bundles) and
335
- // fall back to normal import (for CJS bundles).
245
+ // Load community-kit translations
246
+ const communityKitChunkImport = await getCommunityKitChunkImport(locale);
336
247
 
248
+ // Prefer loading `default` (for ESM bundles) and
249
+ // fall back to normal import (for CJS bundles).
337
250
  return mergeMessages(parseChunkImport(uiKitChunkImport), parseChunkImport(appKitChunkImport), parseChunkImport(communityKitChunkImport));
338
251
  }
339
252
 
@@ -341,21 +254,19 @@ const initialState = {
341
254
  isLoading: true,
342
255
  messages: undefined,
343
256
  error: undefined
344
- }; // Low level hook to load messages for a specific locale. The loading is async
345
- // because it's assumed that the translation files are dynamically imported (code splitted).
257
+ };
346
258
 
259
+ // Low level hook to load messages for a specific locale. The loading is async
260
+ // because it's assumed that the translation files are dynamically imported (code splitted).
347
261
  const useAsyncIntlMessages = _ref => {
348
262
  let locale = _ref.locale,
349
- loader = _ref.loader;
350
-
263
+ loader = _ref.loader;
351
264
  const _useState = useState(initialState),
352
- _useState2 = _slicedToArray(_useState, 2),
353
- state = _useState2[0],
354
- setState = _useState2[1];
355
-
265
+ _useState2 = _slicedToArray(_useState, 2),
266
+ state = _useState2[0],
267
+ setState = _useState2[1];
356
268
  useEffect(() => {
357
269
  let _isUnmounting = false;
358
-
359
270
  async function load(_locale) {
360
271
  try {
361
272
  if (!_isUnmounting) {
@@ -374,7 +285,6 @@ const useAsyncIntlMessages = _ref => {
374
285
  }
375
286
  }
376
287
  }
377
-
378
288
  if (locale) load(locale);
379
289
  return () => {
380
290
  _isUnmounting = true;
@@ -389,19 +299,17 @@ const getMessagesForLocale = (data, locale) => {
389
299
  const fallbackLanguage = extractLanguageTagFromLocale(locale);
390
300
  return data[fallbackLanguage];
391
301
  };
392
-
393
302
  const useAsyncLocaleData = _ref => {
394
303
  var _messagesFromKitResul, _applicationMessagesR, _messagesFromKitResul2;
395
-
396
304
  let locale = _ref.locale,
397
- applicationMessages = _ref.applicationMessages;
305
+ applicationMessages = _ref.applicationMessages;
398
306
  const loadApplicationMessages = useCallback(async locale => {
399
307
  if (typeof applicationMessages === 'function') {
400
308
  return await applicationMessages(locale);
401
309
  }
402
-
403
310
  return getMessagesForLocale(applicationMessages, locale);
404
- }, // NOTE: we assume that the `applicationMessages` argument never changes.
311
+ },
312
+ // NOTE: we assume that the `applicationMessages` argument never changes.
405
313
  // Therefore, we disable the dependency array to not depend on that argument.
406
314
  // This is important, to avoid potential infinite loops.
407
315
  // eslint-disable-next-line react-hooks/exhaustive-deps
@@ -413,21 +321,20 @@ const useAsyncLocaleData = _ref => {
413
321
  const applicationMessagesResult = useAsyncIntlMessages({
414
322
  locale,
415
323
  loader: loadApplicationMessages
416
- }); // Merge the loaded messages into one
324
+ });
417
325
 
326
+ // Merge the loaded messages into one
418
327
  return {
419
328
  isLoading: messagesFromKitResult.isLoading || applicationMessagesResult.isLoading,
420
329
  messages: mergeMessages((_messagesFromKitResul = messagesFromKitResult.messages) !== null && _messagesFromKitResul !== void 0 ? _messagesFromKitResul : {}, (_applicationMessagesR = applicationMessagesResult.messages) !== null && _applicationMessagesR !== void 0 ? _applicationMessagesR : {}),
421
330
  error: (_messagesFromKitResul2 = messagesFromKitResult.error) !== null && _messagesFromKitResul2 !== void 0 ? _messagesFromKitResul2 : applicationMessagesResult.error
422
331
  };
423
332
  };
424
-
425
333
  const AsyncLocaleData = props => {
426
334
  const _useAsyncLocaleData = useAsyncLocaleData(props),
427
- isLoading = _useAsyncLocaleData.isLoading,
428
- messages = _useAsyncLocaleData.messages,
429
- error = _useAsyncLocaleData.error;
430
-
335
+ isLoading = _useAsyncLocaleData.isLoading,
336
+ messages = _useAsyncLocaleData.messages,
337
+ error = _useAsyncLocaleData.error;
431
338
  useEffect(() => {
432
339
  if (error) reportErrorToSentry(error, {});
433
340
  }, [error]);
@@ -439,16 +346,16 @@ const AsyncLocaleData = props => {
439
346
  })
440
347
  });
441
348
  };
442
-
443
349
  AsyncLocaleData.propTypes = {
444
350
  locale: _pt.string,
445
351
  applicationMessages: _pt.oneOfType([_pt.objectOf(_pt.any), _pt.func]).isRequired,
446
352
  children: _pt.func.isRequired
447
353
  };
448
354
 
355
+ // TODO: move it to its own package, so that other people can also use it?
356
+
449
357
  // Selection of shared messages, to avoid duplicating translations.
450
358
  // Avoid changing the message id, otherwise you need to translate them again in Transifex.
451
-
452
359
  const messages = defineMessages({
453
360
  cancel: {
454
361
  id: 'AppKit.Shared.cancel',
@@ -18,5 +18,5 @@ declare const useAsyncLocaleData: ({ locale, applicationMessages, }: Pick<Props,
18
18
  messages: TMessageTranslations;
19
19
  error: Error | undefined;
20
20
  };
21
- declare const AsyncLocaleData: (props: Props) => import("@emotion/react/jsx-runtime").JSX.Element;
21
+ declare const AsyncLocaleData: (props: Props) => import("@emotion/react/types/jsx-namespace").EmotionJSX.Element;
22
22
  export { AsyncLocaleData, useAsyncLocaleData };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools-frontend/i18n",
3
- "version": "22.2.1",
3
+ "version": "22.3.0",
4
4
  "description": "MC i18n messages",
5
5
  "bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
6
6
  "repository": {
@@ -28,29 +28,31 @@
28
28
  "LICENSE",
29
29
  "README.md"
30
30
  ],
31
- "scripts": {
32
- "compile-data": "./scripts/compile_data.sh"
33
- },
34
31
  "dependencies": {
35
32
  "@babel/runtime": "^7.20.13",
36
33
  "@babel/runtime-corejs3": "^7.20.13",
37
34
  "@commercetools-community-kit/i18n": "^0.3.0",
38
- "@commercetools-frontend/sentry": "22.2.1",
35
+ "@commercetools-frontend/sentry": "22.3.0",
39
36
  "@commercetools-uikit/i18n": "^16.0.0",
40
- "@emotion/react": "11.10.6",
41
- "@formatjs/icu-messageformat-parser": "2.3.1",
37
+ "@emotion/react": "11.11.0",
38
+ "@formatjs/icu-messageformat-parser": "2.4.0",
42
39
  "@types/prop-types": "^15.7.5",
43
40
  "@types/react": "^17.0.53",
44
41
  "moment": "^2.29.4",
45
42
  "prop-types": "15.8.1"
46
43
  },
47
44
  "devDependencies": {
48
- "@formatjs/cli": "6.1.0",
45
+ "@formatjs/cli": "6.1.1",
46
+ "@types/jest": "^29.5.1",
47
+ "jest-mock": "29.5.0",
49
48
  "react": "17.0.2",
50
- "react-intl": "^6.3.2"
49
+ "react-intl": "^6.4.2"
51
50
  },
52
51
  "peerDependencies": {
53
52
  "react": "17.x",
54
53
  "react-intl": "6.x"
54
+ },
55
+ "scripts": {
56
+ "compile-data": "./scripts/compile_data.sh"
55
57
  }
56
- }
58
+ }