@lingui/core 3.14.0 → 3.16.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.
Files changed (69) hide show
  1. package/CHANGELOG.md +384 -0
  2. package/build/LICENSE +21 -0
  3. package/build/cjs/compile.js +68 -0
  4. package/build/cjs/compile.js.map +1 -0
  5. package/{esm/core.development.js → build/cjs/index.js} +46 -87
  6. package/build/cjs/index.js.map +1 -0
  7. package/build/compile.d.ts +2 -0
  8. package/build/compile.js +1 -0
  9. package/build/esm/compile.js +66 -0
  10. package/build/esm/compile.js.map +1 -0
  11. package/{esm/dev.development.js → build/esm/index.js} +33 -79
  12. package/build/esm/index.js.map +1 -0
  13. package/{esm → build/esm}/package.json +0 -0
  14. package/build/index.d.ts +94 -0
  15. package/build/index.js +1 -0
  16. package/package.json +16 -13
  17. package/cjs/context.d.ts +0 -4
  18. package/cjs/context.d.ts.map +0 -1
  19. package/cjs/core.development.js +0 -542
  20. package/cjs/core.development.js.map +0 -1
  21. package/cjs/core.production.min.js +0 -2
  22. package/cjs/core.production.min.js.map +0 -1
  23. package/cjs/dev/compile.d.ts +0 -3
  24. package/cjs/dev/compile.d.ts.map +0 -1
  25. package/cjs/dev/index.d.ts +0 -4
  26. package/cjs/dev/index.d.ts.map +0 -1
  27. package/cjs/dev/loadLocaleData.d.ts +0 -5
  28. package/cjs/dev/loadLocaleData.d.ts.map +0 -1
  29. package/cjs/dev.development.js +0 -542
  30. package/cjs/dev.development.js.map +0 -1
  31. package/cjs/dev.production.min.js +0 -2
  32. package/cjs/dev.production.min.js.map +0 -1
  33. package/cjs/essentials.d.ts +0 -4
  34. package/cjs/essentials.d.ts.map +0 -1
  35. package/cjs/eventEmitter.d.ts +0 -10
  36. package/cjs/eventEmitter.d.ts.map +0 -1
  37. package/cjs/formats.d.ts +0 -4
  38. package/cjs/formats.d.ts.map +0 -1
  39. package/cjs/i18n.d.ts +0 -63
  40. package/cjs/i18n.d.ts.map +0 -1
  41. package/cjs/index.d.ts +0 -5
  42. package/cjs/index.d.ts.map +0 -1
  43. package/esm/context.d.ts +0 -4
  44. package/esm/context.d.ts.map +0 -1
  45. package/esm/core.development.js.map +0 -1
  46. package/esm/core.production.min.js +0 -2
  47. package/esm/core.production.min.js.map +0 -1
  48. package/esm/dev/compile.d.ts +0 -3
  49. package/esm/dev/compile.d.ts.map +0 -1
  50. package/esm/dev/index.d.ts +0 -4
  51. package/esm/dev/index.d.ts.map +0 -1
  52. package/esm/dev/loadLocaleData.d.ts +0 -5
  53. package/esm/dev/loadLocaleData.d.ts.map +0 -1
  54. package/esm/dev.development.js.map +0 -1
  55. package/esm/dev.js +0 -18
  56. package/esm/dev.production.min.js +0 -2
  57. package/esm/dev.production.min.js.map +0 -1
  58. package/esm/essentials.d.ts +0 -4
  59. package/esm/essentials.d.ts.map +0 -1
  60. package/esm/eventEmitter.d.ts +0 -10
  61. package/esm/eventEmitter.d.ts.map +0 -1
  62. package/esm/formats.d.ts +0 -4
  63. package/esm/formats.d.ts.map +0 -1
  64. package/esm/i18n.d.ts +0 -63
  65. package/esm/i18n.d.ts.map +0 -1
  66. package/esm/index.d.ts +0 -5
  67. package/esm/index.d.ts.map +0 -1
  68. package/esm/index.js +0 -18
  69. package/index.js +0 -5
package/CHANGELOG.md ADDED
@@ -0,0 +1,384 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [3.16.0](https://github.com/lingui/js-lingui/compare/v3.15.0...v3.16.0) (2023-01-18)
7
+
8
+ **Note:** Version bump only for package @lingui/core
9
+
10
+
11
+
12
+
13
+
14
+ # [3.15.0](https://github.com/lingui/js-lingui/compare/v3.14.0...v3.15.0) (2022-11-07)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * Pass formatter to pluralization function ([#1294](https://github.com/lingui/js-lingui/issues/1294)) ([33af3ba](https://github.com/lingui/js-lingui/commit/33af3ba3dc22bd4128d98e061cb9d97f75c6503a))
20
+
21
+
22
+
23
+
24
+
25
+ # [3.14.0](https://github.com/lingui/js-lingui/compare/v3.13.3...v3.14.0) (2022-06-22)
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * Add extra package.json under `/esm` ([#1258](https://github.com/lingui/js-lingui/issues/1258)) ([80cd337](https://github.com/lingui/js-lingui/commit/80cd3378ceb5677bfa50b14f67e4e31703392298))
31
+
32
+
33
+
34
+
35
+
36
+ ## [3.13.3](https://github.com/lingui/js-lingui/compare/v3.13.2...v3.13.3) (2022-04-24)
37
+
38
+ **Note:** Version bump only for package @lingui/core
39
+
40
+
41
+
42
+
43
+
44
+ ## [3.13.2](https://github.com/lingui/js-lingui/compare/v3.13.1...v3.13.2) (2022-01-24)
45
+
46
+
47
+ ### Bug Fixes
48
+
49
+ * localeData interpolation broken ([457735b](https://github.com/lingui/js-lingui/commit/457735bb61f0a75d0ce176874b1c67a65c4b3084))
50
+
51
+
52
+
53
+
54
+
55
+ ## [3.13.1](https://github.com/lingui/js-lingui/compare/v3.13.0...v3.13.1) (2022-01-21)
56
+
57
+
58
+ ### Bug Fixes
59
+
60
+ * i18n.activate should load instantly new messages ([#1182](https://github.com/lingui/js-lingui/issues/1182)) ([f8f47a2](https://github.com/lingui/js-lingui/commit/f8f47a2385fe3d8dd3395c493027de2492509325))
61
+
62
+
63
+
64
+
65
+
66
+ # [3.13.0](https://github.com/lingui/js-lingui/compare/v3.12.1...v3.13.0) (2021-11-26)
67
+
68
+
69
+ ### Features
70
+
71
+ * msgctxt support ([#1094](https://github.com/lingui/js-lingui/issues/1094)) ([8ee42cb](https://github.com/lingui/js-lingui/commit/8ee42cbfe26bc6d055748dcf2713ab8ade7ec827))
72
+
73
+
74
+
75
+
76
+
77
+ ## [3.12.1](https://github.com/lingui/js-lingui/compare/v3.12.0...v3.12.1) (2021-09-28)
78
+
79
+ **Note:** Version bump only for package @lingui/core
80
+
81
+
82
+
83
+
84
+
85
+ # [3.12.0](https://github.com/lingui/js-lingui/compare/v3.11.1...v3.12.0) (2021-09-28)
86
+
87
+ **Note:** Version bump only for package @lingui/core
88
+
89
+
90
+
91
+
92
+
93
+ ## [3.11.1](https://github.com/lingui/js-lingui/compare/v3.11.0...v3.11.1) (2021-09-07)
94
+
95
+ **Note:** Version bump only for package @lingui/core
96
+
97
+
98
+
99
+
100
+
101
+ # [3.11.0](https://github.com/lingui/js-lingui/compare/v3.10.4...v3.11.0) (2021-09-07)
102
+
103
+
104
+ ### Bug Fixes
105
+
106
+ * sideEffects to false for shrinking bundle size ([#1129](https://github.com/lingui/js-lingui/issues/1129)) ([57cd2e5](https://github.com/lingui/js-lingui/commit/57cd2e576945ba30aea30d5cf5bcb27d1f77fe4c))
107
+ * unicode chars were removed from .po files when extracting ([#1125](https://github.com/lingui/js-lingui/issues/1125)) ([d688329](https://github.com/lingui/js-lingui/commit/d688329c0457a080d5cd485a95e94ffa5e00c5ae))
108
+
109
+
110
+
111
+
112
+
113
+ ## [3.10.4](https://github.com/lingui/js-lingui/compare/v3.10.3...v3.10.4) (2021-06-16)
114
+
115
+ **Note:** Version bump only for package @lingui/core
116
+
117
+
118
+
119
+
120
+
121
+ ## [3.10.3](https://github.com/lingui/js-lingui/compare/v3.10.2...v3.10.3) (2021-06-14)
122
+
123
+
124
+ ### Bug Fixes
125
+
126
+ * add string return type to i18n._ ([#1081](https://github.com/lingui/js-lingui/issues/1081)) ([68d32d6](https://github.com/lingui/js-lingui/commit/68d32d63899c9a0b2c66891070831c6488a7d013))
127
+
128
+
129
+
130
+
131
+
132
+ ## [3.10.2](https://github.com/lingui/js-lingui/compare/v3.10.1...v3.10.2) (2021-06-08)
133
+
134
+ **Note:** Version bump only for package @lingui/core
135
+
136
+
137
+
138
+
139
+
140
+ ## [3.10.1](https://github.com/lingui/js-lingui/compare/v3.10.0...v3.10.1) (2021-06-08)
141
+
142
+
143
+ ### Bug Fixes
144
+
145
+ * reverts reduce size of ESM packages ([#1066](https://github.com/lingui/js-lingui/issues/1066)) ([3a057e0](https://github.com/lingui/js-lingui/commit/3a057e0c61224b98c93203e0d88136fa48f309ba))
146
+
147
+
148
+
149
+
150
+
151
+ # [3.10.0](https://github.com/lingui/js-lingui/compare/v3.9.0...v3.10.0) (2021-06-08)
152
+
153
+
154
+ ### Bug Fixes
155
+
156
+ * reduce size of ESM packages ([#1066](https://github.com/lingui/js-lingui/issues/1066)) ([9990eba](https://github.com/lingui/js-lingui/commit/9990ebaa9d30f7e218c106a2abfd7ddbcf0e0170))
157
+
158
+
159
+
160
+
161
+
162
+ # [3.9.0](https://github.com/lingui/js-lingui/compare/v3.8.10...v3.9.0) (2021-05-18)
163
+
164
+
165
+ ### Bug Fixes
166
+
167
+ * ESM dev entrypoint was causing unexpected behaviors ([#1059](https://github.com/lingui/js-lingui/issues/1059)) ([2b8d70b](https://github.com/lingui/js-lingui/commit/2b8d70b35ed103d94a2f88ea7c6813a29a1d5635))
168
+
169
+
170
+
171
+
172
+
173
+ ## [3.8.10](https://github.com/lingui/js-lingui/compare/v3.8.9...v3.8.10) (2021-04-19)
174
+
175
+ **Note:** Version bump only for package @lingui/core
176
+
177
+
178
+
179
+
180
+
181
+ ## [3.8.9](https://github.com/lingui/js-lingui/compare/v3.8.8...v3.8.9) (2021-04-09)
182
+
183
+
184
+ ### Bug Fixes
185
+
186
+ * event emitter refactor (reverted) ([#1038](https://github.com/lingui/js-lingui/issues/1038)) ([f299493](https://github.com/lingui/js-lingui/commit/f299493999299fe9a7d0e01b9045e7f0a9813c6a))
187
+
188
+
189
+
190
+
191
+
192
+ ## [3.8.8](https://github.com/lingui/js-lingui/compare/v3.8.7...v3.8.8) (2021-04-09)
193
+
194
+ **Note:** Version bump only for package @lingui/core
195
+
196
+
197
+
198
+
199
+
200
+ ## [3.8.7](https://github.com/lingui/js-lingui/compare/v3.8.6...v3.8.7) (2021-04-09)
201
+
202
+
203
+ ### Bug Fixes
204
+
205
+ * unicode chars in native environments + event emitter refactor ([#1036](https://github.com/lingui/js-lingui/issues/1036)) ([39fa90d](https://github.com/lingui/js-lingui/commit/39fa90d95c08f105f3f7feb17b65d9b8f916b73a))
206
+
207
+
208
+
209
+
210
+
211
+ ## [3.8.6](https://github.com/lingui/js-lingui/compare/v3.8.5...v3.8.6) (2021-04-08)
212
+
213
+ **Note:** Version bump only for package @lingui/core
214
+
215
+
216
+
217
+
218
+
219
+ ## [3.8.5](https://github.com/lingui/js-lingui/compare/v3.8.4...v3.8.5) (2021-04-08)
220
+
221
+ **Note:** Version bump only for package @lingui/core
222
+
223
+
224
+
225
+
226
+
227
+ ## [3.8.4](https://github.com/lingui/js-lingui/compare/v3.8.3...v3.8.4) (2021-04-08)
228
+
229
+
230
+ ### Bug Fixes
231
+
232
+ * undefined interpolation on t macro ([#1030](https://github.com/lingui/js-lingui/issues/1030)) ([194f9b3](https://github.com/lingui/js-lingui/commit/194f9b318434bcaf4b68af549a6ed246fed2be02))
233
+
234
+
235
+
236
+
237
+
238
+ ## [3.8.3](https://github.com/lingui/js-lingui/compare/v3.8.2...v3.8.3) (2021-04-05)
239
+
240
+ **Note:** Version bump only for package @lingui/core
241
+
242
+
243
+
244
+
245
+
246
+ ## [3.8.2](https://github.com/lingui/js-lingui/compare/v3.8.1...v3.8.2) (2021-03-31)
247
+
248
+ **Note:** Version bump only for package @lingui/core
249
+
250
+
251
+
252
+
253
+
254
+ ## [3.8.1](https://github.com/lingui/js-lingui/compare/v3.8.0...v3.8.1) (2021-03-23)
255
+
256
+ **Note:** Version bump only for package @lingui/core
257
+
258
+
259
+
260
+
261
+
262
+ # [3.8.0](https://github.com/lingui/js-lingui/compare/v3.7.2...v3.8.0) (2021-03-23)
263
+
264
+ **Note:** Version bump only for package @lingui/core
265
+
266
+
267
+
268
+
269
+
270
+ ## [3.7.2](https://github.com/lingui/js-lingui/compare/v3.7.1...v3.7.2) (2021-03-14)
271
+
272
+ **Note:** Version bump only for package @lingui/core
273
+
274
+
275
+
276
+
277
+
278
+ ## [3.7.1](https://github.com/lingui/js-lingui/compare/v3.7.0...v3.7.1) (2021-03-07)
279
+
280
+
281
+ ### Bug Fixes
282
+
283
+ * exports attribute on package.json, expo compat ([#997](https://github.com/lingui/js-lingui/issues/997)) ([79aa509](https://github.com/lingui/js-lingui/commit/79aa50998185847064d80f2a38be0ebcb64424f9))
284
+
285
+
286
+
287
+
288
+
289
+ # [3.7.0](https://github.com/lingui/js-lingui/compare/v3.6.0...v3.7.0) (2021-03-04)
290
+
291
+
292
+ ### Features
293
+
294
+ * raise event on missing translation ([#993](https://github.com/lingui/js-lingui/issues/993)) ([ecf83c3](https://github.com/lingui/js-lingui/commit/ecf83c37e177cb10f157fb8913d73e18662e3ca4))
295
+
296
+
297
+
298
+
299
+
300
+ # [3.6.0](https://github.com/lingui/js-lingui/compare/v3.5.1...v3.6.0) (2021-02-23)
301
+
302
+
303
+ ### Features
304
+
305
+ * ship universal modules with ESM ([#979](https://github.com/lingui/js-lingui/issues/979)) ([6cd5fe0](https://github.com/lingui/js-lingui/commit/6cd5fe0a71dd5cf7e0832bd3e9902a2f6ba789f6))
306
+
307
+
308
+
309
+
310
+
311
+ ## [3.5.1](https://github.com/lingui/js-lingui/compare/v3.5.0...v3.5.1) (2021-02-09)
312
+
313
+ **Note:** Version bump only for package @lingui/core
314
+
315
+
316
+
317
+
318
+
319
+ # [3.5.0](https://github.com/lingui/js-lingui/compare/v3.4.0...v3.5.0) (2021-02-02)
320
+
321
+ **Note:** Version bump only for package @lingui/core
322
+
323
+
324
+
325
+
326
+
327
+ # [3.4.0](https://github.com/lingui/js-lingui/compare/v3.3.0...v3.4.0) (2021-01-13)
328
+
329
+
330
+ ### Bug Fixes
331
+
332
+ * added return type to i18n._ ([#922](https://github.com/lingui/js-lingui/issues/922)) ([249c486](https://github.com/lingui/js-lingui/commit/249c486d258a4fb44bae1e3da1765e00003429a7))
333
+
334
+
335
+
336
+
337
+
338
+ # [3.3.0](https://github.com/lingui/js-lingui/compare/v3.2.3...v3.3.0) (2020-12-08)
339
+
340
+ **Note:** Version bump only for package @lingui/core
341
+
342
+
343
+
344
+
345
+
346
+ ## [3.2.3](https://github.com/lingui/js-lingui/compare/v3.2.2...v3.2.3) (2020-11-22)
347
+
348
+ **Note:** Version bump only for package @lingui/core
349
+
350
+
351
+
352
+
353
+
354
+ ## [3.2.2](https://github.com/lingui/js-lingui/compare/v3.2.1...v3.2.2) (2020-11-20)
355
+
356
+ **Note:** Version bump only for package @lingui/core
357
+
358
+
359
+
360
+
361
+
362
+ # [3.2.0](https://github.com/lingui/js-lingui/compare/v3.1.0...v3.2.0) (2020-11-12)
363
+
364
+
365
+ ### Bug Fixes
366
+
367
+ * MessageDescriptor values type ([#848](https://github.com/lingui/js-lingui/issues/848)) ([9712d94](https://github.com/lingui/js-lingui/commit/9712d94d043c8d40cbc5d017474b5938eb02f8d6))
368
+
369
+
370
+
371
+
372
+
373
+ # [3.1.0](https://github.com/lingui/js-lingui/compare/v3.0.3...v3.1.0) (2020-11-10)
374
+
375
+
376
+ ### Bug Fixes
377
+
378
+ * improved performance of formatters ([#818](https://github.com/lingui/js-lingui/issues/818)) ([22667ad](https://github.com/lingui/js-lingui/commit/22667adba5b07cc94abacff8e8b5f5b19202576c))
379
+ * show error when plurals aren't loaded ([#824](https://github.com/lingui/js-lingui/issues/824)) ([296b6a1](https://github.com/lingui/js-lingui/commit/296b6a1a1f332064f040cc987c4359411d307258))
380
+
381
+
382
+ ### Features
383
+
384
+ * use fallback locales from cldr ([#820](https://github.com/lingui/js-lingui/issues/820)) ([2d9e124](https://github.com/lingui/js-lingui/commit/2d9e124b91f1ba7a65e9f997a3ba952679c6c23a))
package/build/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Tomáš Ehrlich
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,68 @@
1
+ 'use strict';
2
+
3
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
+ var parser = require('@messageformat/parser');
5
+
6
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
7
+
8
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
9
+
10
+ // [Tokens] -> (CTX -> String)
11
+ function processTokens(tokens, mapText) {
12
+ if (!tokens.filter(function (token) {
13
+ return token.type !== "content";
14
+ }).length) {
15
+ return tokens.map(function (token) {
16
+ return mapText(token.value);
17
+ }).join("");
18
+ }
19
+
20
+ return tokens.map(function (token) {
21
+ if (token.type === 'content') {
22
+ return mapText(token.value); // # in plural case
23
+ } else if (token.type === "octothorpe") {
24
+ return "#"; // simple argument
25
+ } else if (token.type === "argument") {
26
+ return [token.arg]; // argument with custom format (date, number)
27
+ } else if (token.type === "function") {
28
+ var _token$param;
29
+
30
+ var _param = token === null || token === void 0 ? void 0 : (_token$param = token.param) === null || _token$param === void 0 ? void 0 : _token$param[0];
31
+
32
+ if (_param) {
33
+ return [token.arg, token.key, _param.value.trim()];
34
+ } else {
35
+ return [token.arg, token.key];
36
+ }
37
+ }
38
+
39
+ var offset = token.pluralOffset; // complex argument with cases
40
+
41
+ var formatProps = {};
42
+ token.cases.forEach(function (item) {
43
+ formatProps[item.key.replace(/^=(.)+/, "$1")] = processTokens(item.tokens, mapText);
44
+ });
45
+ return [token.arg, token.type, _objectSpread({
46
+ offset: offset
47
+ }, formatProps)];
48
+ });
49
+ } // Message -> (Params -> String)
50
+
51
+ /** @internal */
52
+
53
+
54
+ function compileMessage(message) {
55
+ var mapText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (v) {
56
+ return v;
57
+ };
58
+
59
+ try {
60
+ return processTokens(parser.parse(message), mapText);
61
+ } catch (e) {
62
+ console.error("".concat(e.message, " \n\nMessage: ").concat(message));
63
+ return message;
64
+ }
65
+ }
66
+
67
+ exports.compileMessage = compileMessage;
68
+ //# sourceMappingURL=compile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compile.js","sources":["../../src/compile/compileMessage.ts"],"sourcesContent":["import {Content, parse, Token} from \"@messageformat/parser\"\nimport {CompiledMessage, CompiledMessageToken} from \"../i18n\"\n\ntype MapTextFn = (value: string) => string;\n\n// [Tokens] -> (CTX -> String)\nfunction processTokens(tokens: Array<Token>, mapText?: MapTextFn): CompiledMessage {\n if (!tokens.filter((token) => token.type !== \"content\").length) {\n return tokens.map(token => mapText((token as Content).value)).join(\"\")\n }\n\n return tokens.map<CompiledMessageToken>((token) => {\n if (token.type === 'content') {\n return mapText(token.value)\n\n // # in plural case\n } else if (token.type === \"octothorpe\") {\n return \"#\"\n\n // simple argument\n } else if (token.type === \"argument\") {\n return [token.arg]\n\n // argument with custom format (date, number)\n } else if (token.type === \"function\") {\n const _param = token?.param?.[0] as Content\n\n if (_param) {\n return [token.arg, token.key, _param.value.trim()]\n } else {\n return [token.arg, token.key]\n }\n }\n\n const offset = token.pluralOffset\n\n // complex argument with cases\n const formatProps = {}\n token.cases.forEach((item) => {\n formatProps[item.key.replace(/^=(.)+/, \"$1\")] = processTokens(item.tokens, mapText)\n })\n\n return [\n token.arg,\n token.type,\n {\n offset,\n ...formatProps,\n } as any,\n ] as CompiledMessageToken\n })\n}\n\n// Message -> (Params -> String)\n/** @internal */\nexport function compileMessage(\n message: string,\n mapText: MapTextFn = (v) => v,\n): CompiledMessage {\n try {\n return processTokens(parse(message), mapText)\n } catch (e) {\n console.error(`${e.message} \\n\\nMessage: ${message}`)\n return message\n }\n}\n"],"names":["processTokens","tokens","mapText","filter","token","type","length","map","value","join","arg","_param","param","key","trim","offset","pluralOffset","formatProps","cases","forEach","item","replace","compileMessage","message","v","parse","e","console","error"],"mappings":"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"}
@@ -1,12 +1,15 @@
1
- import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
2
- import _createClass from '@babel/runtime/helpers/createClass';
3
- import _inherits from '@babel/runtime/helpers/inherits';
4
- import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstructorReturn';
5
- import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
6
- import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
7
- import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
8
- import _defineProperty from '@babel/runtime/helpers/defineProperty';
9
- import { parse } from 'messageformat-parser';
1
+ 'use strict';
2
+
3
+ var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
4
+ var _createClass = require('@babel/runtime/helpers/createClass');
5
+ var _assertThisInitialized = require('@babel/runtime/helpers/assertThisInitialized');
6
+ var _inherits = require('@babel/runtime/helpers/inherits');
7
+ var _possibleConstructorReturn = require('@babel/runtime/helpers/possibleConstructorReturn');
8
+ var _getPrototypeOf = require('@babel/runtime/helpers/getPrototypeOf');
9
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
10
+ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
11
+ var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
12
+ var compile = require('@lingui/core/compile');
10
13
 
11
14
  var isString = function isString(s) {
12
15
  return typeof s === "string";
@@ -16,7 +19,6 @@ var isFunction = function isFunction(f) {
16
19
  };
17
20
 
18
21
  /** Memoized cache */
19
-
20
22
  var numberFormats = new Map();
21
23
  var dateFormats = new Map();
22
24
  function date(locales) {
@@ -99,8 +101,9 @@ var defaultFormats = function defaultFormats(locale, locales) {
99
101
  return function (ctx) {
100
102
  var msg = isFunction(message) ? message(ctx) : message;
101
103
  var norm = Array.isArray(msg) ? msg : [msg];
104
+ var numberFormat = Object.keys(formats).length ? style('number') : {};
102
105
 
103
- var valueStr = number(locales)(value);
106
+ var valueStr = number(locales, numberFormat)(value);
104
107
 
105
108
  return norm.map(function (m) {
106
109
  return isString(m) ? m.replace("#", valueStr) : m;
@@ -144,25 +147,20 @@ var defaultFormats = function defaultFormats(locale, locales) {
144
147
  };
145
148
  }; // Params -> CTX
146
149
 
147
- /**
148
- * Creates a context object, which formats ICU MessageFormat arguments based on
149
- * argument type.
150
- *
151
- * @param locale - Locale of message
152
- * @param locales - Locales to be used when formatting the numbers or dates
153
- * @param values - Parameters for variable interpolation
154
- * @param localeData - Locale data (e.g: plurals)
155
- * @param formats - Custom format styles
156
- * @returns {function(string, string, any)}
150
+ /**
151
+ * Creates a context object, which formats ICU MessageFormat arguments based on
152
+ * argument type.
153
+ *
154
+ * @param locale - Locale of message
155
+ * @param locales - Locales to be used when formatting the numbers or dates
156
+ * @param values - Parameters for variable interpolation
157
+ * @param localeData - Locale data (e.g: plurals)
158
+ * @param formats - Custom format styles
159
+ * @returns {function(string, string, any)}
157
160
  */
158
161
 
159
162
 
160
- function context(_ref3) {
161
- var locale = _ref3.locale,
162
- locales = _ref3.locales,
163
- values = _ref3.values,
164
- formats = _ref3.formats,
165
- localeData = _ref3.localeData;
163
+ function context(locale, locales, values, formats, localeData) {
166
164
  var formatters = defaultFormats(locale, locales, localeData, formats);
167
165
 
168
166
  var ctx = function ctx(name, type, format) {
@@ -178,13 +176,7 @@ function context(_ref3) {
178
176
  function interpolate(translation, locale, locales, localeData) {
179
177
  return function (values) {
180
178
  var formats = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
181
- var ctx = context({
182
- locale: locale,
183
- locales: locales,
184
- localeData: localeData,
185
- formats: formats,
186
- values: values
187
- });
179
+ var ctx = context(locale, locales, values, formats, localeData);
188
180
 
189
181
  var formatMessage = function formatMessage(message) {
190
182
  if (!Array.isArray(message)) return message;
@@ -219,58 +211,11 @@ function interpolate(translation, locale, locales, localeData) {
219
211
  };
220
212
  }
221
213
 
222
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
223
-
224
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
225
-
226
- function processTokens(tokens) {
227
- if (!tokens.filter(function (token) {
228
- return !isString(token);
229
- }).length) {
230
- return tokens.join("");
231
- }
232
-
233
- return tokens.map(function (token) {
234
- if (isString(token)) {
235
- return token; // # in plural case
236
- } else if (token.type === "octothorpe") {
237
- return "#"; // simple argument
238
- } else if (token.type === "argument") {
239
- return [token.arg]; // argument with custom format (date, number)
240
- } else if (token.type === "function") {
241
- var _param = token.param && token.param.tokens[0];
242
-
243
- var param = typeof _param === "string" ? _param.trim() : _param;
244
- return [token.arg, token.key, param].filter(Boolean);
245
- }
246
-
247
- var offset = token.offset ? parseInt(token.offset) : undefined; // complex argument with cases
248
-
249
- var formatProps = {};
250
- token.cases.forEach(function (item) {
251
- formatProps[item.key] = processTokens(item.tokens);
252
- });
253
- return [token.arg, token.type, _objectSpread({
254
- offset: offset
255
- }, formatProps)];
256
- });
257
- } // Message -> (Params -> String)
258
-
259
-
260
- function compile(message) {
261
- try {
262
- return processTokens(parse(message));
263
- } catch (e) {
264
- console.error("Message cannot be parsed due to syntax errors: ".concat(message));
265
- return message;
266
- }
267
- }
268
-
269
214
  var EventEmitter = /*#__PURE__*/function () {
270
215
  function EventEmitter() {
271
216
  _classCallCheck(this, EventEmitter);
272
217
 
273
- this._events = {};
218
+ _defineProperty(this, "_events", {});
274
219
  }
275
220
 
276
221
  _createClass(EventEmitter, [{
@@ -334,6 +279,17 @@ var I18n = /*#__PURE__*/function (_EventEmitter) {
334
279
  _classCallCheck(this, I18n);
335
280
 
336
281
  _this = _super.call(this);
282
+
283
+ _defineProperty(_assertThisInitialized(_this), "_locale", void 0);
284
+
285
+ _defineProperty(_assertThisInitialized(_this), "_locales", void 0);
286
+
287
+ _defineProperty(_assertThisInitialized(_this), "_localeData", void 0);
288
+
289
+ _defineProperty(_assertThisInitialized(_this), "_messages", void 0);
290
+
291
+ _defineProperty(_assertThisInitialized(_this), "_missing", void 0);
292
+
337
293
  _this._messages = {};
338
294
  _this._localeData = {};
339
295
  if (params.missing != null) _this._missing = params.missing;
@@ -406,7 +362,7 @@ var I18n = /*#__PURE__*/function (_EventEmitter) {
406
362
  }, {
407
363
  key: "activate",
408
364
  value: function activate(locale, locales) {
409
- {
365
+ if (process.env.NODE_ENV !== "production") {
410
366
  if (!this._messages[locale]) {
411
367
  console.warn("Messages for locale \"".concat(locale, "\" not loaded."));
412
368
  }
@@ -465,8 +421,8 @@ var I18n = /*#__PURE__*/function (_EventEmitter) {
465
421
  translation = this.messages[id] || message || id;
466
422
  }
467
423
 
468
- {
469
- translation = isString(translation) ? compile(translation) : translation;
424
+ if (process.env.NODE_ENV !== "production") {
425
+ translation = isString(translation) ? compile.compileMessage(translation) : translation;
470
426
  } // hack for parsing unicode values inside a string to get parsed in react native environments
471
427
 
472
428
 
@@ -520,5 +476,8 @@ function setupI18n() {
520
476
 
521
477
  var i18n = setupI18n();
522
478
 
523
- export { I18n, formats, i18n, setupI18n };
524
- //# sourceMappingURL=core.development.js.map
479
+ exports.I18n = I18n;
480
+ exports.formats = formats;
481
+ exports.i18n = i18n;
482
+ exports.setupI18n = setupI18n;
483
+ //# sourceMappingURL=index.js.map