@lingui/core 3.15.0 → 3.16.1

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 (68) hide show
  1. package/CHANGELOG.md +395 -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} +44 -86
  6. package/build/cjs/index.js.map +1 -0
  7. package/build/compile.d.ts +2 -0
  8. package/build/esm/compile.js +66 -0
  9. package/build/esm/compile.js.map +1 -0
  10. package/{esm/dev.development.js → build/esm/index.js} +31 -78
  11. package/build/esm/index.js.map +1 -0
  12. package/{esm → build/esm}/package.json +0 -0
  13. package/build/index.d.ts +94 -0
  14. package/compile.js +5 -0
  15. package/package.json +17 -13
  16. package/cjs/context.d.ts +0 -4
  17. package/cjs/context.d.ts.map +0 -1
  18. package/cjs/core.development.js +0 -543
  19. package/cjs/core.development.js.map +0 -1
  20. package/cjs/core.production.min.js +0 -2
  21. package/cjs/core.production.min.js.map +0 -1
  22. package/cjs/dev/compile.d.ts +0 -3
  23. package/cjs/dev/compile.d.ts.map +0 -1
  24. package/cjs/dev/index.d.ts +0 -4
  25. package/cjs/dev/index.d.ts.map +0 -1
  26. package/cjs/dev/loadLocaleData.d.ts +0 -5
  27. package/cjs/dev/loadLocaleData.d.ts.map +0 -1
  28. package/cjs/dev.development.js +0 -543
  29. package/cjs/dev.development.js.map +0 -1
  30. package/cjs/dev.production.min.js +0 -2
  31. package/cjs/dev.production.min.js.map +0 -1
  32. package/cjs/essentials.d.ts +0 -4
  33. package/cjs/essentials.d.ts.map +0 -1
  34. package/cjs/eventEmitter.d.ts +0 -10
  35. package/cjs/eventEmitter.d.ts.map +0 -1
  36. package/cjs/formats.d.ts +0 -4
  37. package/cjs/formats.d.ts.map +0 -1
  38. package/cjs/i18n.d.ts +0 -63
  39. package/cjs/i18n.d.ts.map +0 -1
  40. package/cjs/index.d.ts +0 -5
  41. package/cjs/index.d.ts.map +0 -1
  42. package/esm/context.d.ts +0 -4
  43. package/esm/context.d.ts.map +0 -1
  44. package/esm/core.development.js.map +0 -1
  45. package/esm/core.production.min.js +0 -2
  46. package/esm/core.production.min.js.map +0 -1
  47. package/esm/dev/compile.d.ts +0 -3
  48. package/esm/dev/compile.d.ts.map +0 -1
  49. package/esm/dev/index.d.ts +0 -4
  50. package/esm/dev/index.d.ts.map +0 -1
  51. package/esm/dev/loadLocaleData.d.ts +0 -5
  52. package/esm/dev/loadLocaleData.d.ts.map +0 -1
  53. package/esm/dev.development.js.map +0 -1
  54. package/esm/dev.js +0 -18
  55. package/esm/dev.production.min.js +0 -2
  56. package/esm/dev.production.min.js.map +0 -1
  57. package/esm/essentials.d.ts +0 -4
  58. package/esm/essentials.d.ts.map +0 -1
  59. package/esm/eventEmitter.d.ts +0 -10
  60. package/esm/eventEmitter.d.ts.map +0 -1
  61. package/esm/formats.d.ts +0 -4
  62. package/esm/formats.d.ts.map +0 -1
  63. package/esm/i18n.d.ts +0 -63
  64. package/esm/i18n.d.ts.map +0 -1
  65. package/esm/index.d.ts +0 -5
  66. package/esm/index.d.ts.map +0 -1
  67. package/esm/index.js +0 -18
  68. package/index.js +0 -5
package/CHANGELOG.md ADDED
@@ -0,0 +1,395 @@
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.1](https://github.com/lingui/js-lingui/compare/v3.16.0...v3.16.1) (2023-01-24)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **core:** sub entry export for react-native ([#1350](https://github.com/lingui/js-lingui/issues/1350)) ([c178ce3](https://github.com/lingui/js-lingui/commit/c178ce3cc91e64d190965dc684df74162cc17d02))
12
+
13
+
14
+
15
+
16
+
17
+ # [3.16.0](https://github.com/lingui/js-lingui/compare/v3.15.0...v3.16.0) (2023-01-18)
18
+
19
+ **Note:** Version bump only for package @lingui/core
20
+
21
+
22
+
23
+
24
+
25
+ # [3.15.0](https://github.com/lingui/js-lingui/compare/v3.14.0...v3.15.0) (2022-11-07)
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * Pass formatter to pluralization function ([#1294](https://github.com/lingui/js-lingui/issues/1294)) ([33af3ba](https://github.com/lingui/js-lingui/commit/33af3ba3dc22bd4128d98e061cb9d97f75c6503a))
31
+
32
+
33
+
34
+
35
+
36
+ # [3.14.0](https://github.com/lingui/js-lingui/compare/v3.13.3...v3.14.0) (2022-06-22)
37
+
38
+
39
+ ### Bug Fixes
40
+
41
+ * Add extra package.json under `/esm` ([#1258](https://github.com/lingui/js-lingui/issues/1258)) ([80cd337](https://github.com/lingui/js-lingui/commit/80cd3378ceb5677bfa50b14f67e4e31703392298))
42
+
43
+
44
+
45
+
46
+
47
+ ## [3.13.3](https://github.com/lingui/js-lingui/compare/v3.13.2...v3.13.3) (2022-04-24)
48
+
49
+ **Note:** Version bump only for package @lingui/core
50
+
51
+
52
+
53
+
54
+
55
+ ## [3.13.2](https://github.com/lingui/js-lingui/compare/v3.13.1...v3.13.2) (2022-01-24)
56
+
57
+
58
+ ### Bug Fixes
59
+
60
+ * localeData interpolation broken ([457735b](https://github.com/lingui/js-lingui/commit/457735bb61f0a75d0ce176874b1c67a65c4b3084))
61
+
62
+
63
+
64
+
65
+
66
+ ## [3.13.1](https://github.com/lingui/js-lingui/compare/v3.13.0...v3.13.1) (2022-01-21)
67
+
68
+
69
+ ### Bug Fixes
70
+
71
+ * 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))
72
+
73
+
74
+
75
+
76
+
77
+ # [3.13.0](https://github.com/lingui/js-lingui/compare/v3.12.1...v3.13.0) (2021-11-26)
78
+
79
+
80
+ ### Features
81
+
82
+ * msgctxt support ([#1094](https://github.com/lingui/js-lingui/issues/1094)) ([8ee42cb](https://github.com/lingui/js-lingui/commit/8ee42cbfe26bc6d055748dcf2713ab8ade7ec827))
83
+
84
+
85
+
86
+
87
+
88
+ ## [3.12.1](https://github.com/lingui/js-lingui/compare/v3.12.0...v3.12.1) (2021-09-28)
89
+
90
+ **Note:** Version bump only for package @lingui/core
91
+
92
+
93
+
94
+
95
+
96
+ # [3.12.0](https://github.com/lingui/js-lingui/compare/v3.11.1...v3.12.0) (2021-09-28)
97
+
98
+ **Note:** Version bump only for package @lingui/core
99
+
100
+
101
+
102
+
103
+
104
+ ## [3.11.1](https://github.com/lingui/js-lingui/compare/v3.11.0...v3.11.1) (2021-09-07)
105
+
106
+ **Note:** Version bump only for package @lingui/core
107
+
108
+
109
+
110
+
111
+
112
+ # [3.11.0](https://github.com/lingui/js-lingui/compare/v3.10.4...v3.11.0) (2021-09-07)
113
+
114
+
115
+ ### Bug Fixes
116
+
117
+ * 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))
118
+ * 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))
119
+
120
+
121
+
122
+
123
+
124
+ ## [3.10.4](https://github.com/lingui/js-lingui/compare/v3.10.3...v3.10.4) (2021-06-16)
125
+
126
+ **Note:** Version bump only for package @lingui/core
127
+
128
+
129
+
130
+
131
+
132
+ ## [3.10.3](https://github.com/lingui/js-lingui/compare/v3.10.2...v3.10.3) (2021-06-14)
133
+
134
+
135
+ ### Bug Fixes
136
+
137
+ * add string return type to i18n._ ([#1081](https://github.com/lingui/js-lingui/issues/1081)) ([68d32d6](https://github.com/lingui/js-lingui/commit/68d32d63899c9a0b2c66891070831c6488a7d013))
138
+
139
+
140
+
141
+
142
+
143
+ ## [3.10.2](https://github.com/lingui/js-lingui/compare/v3.10.1...v3.10.2) (2021-06-08)
144
+
145
+ **Note:** Version bump only for package @lingui/core
146
+
147
+
148
+
149
+
150
+
151
+ ## [3.10.1](https://github.com/lingui/js-lingui/compare/v3.10.0...v3.10.1) (2021-06-08)
152
+
153
+
154
+ ### Bug Fixes
155
+
156
+ * reverts reduce size of ESM packages ([#1066](https://github.com/lingui/js-lingui/issues/1066)) ([3a057e0](https://github.com/lingui/js-lingui/commit/3a057e0c61224b98c93203e0d88136fa48f309ba))
157
+
158
+
159
+
160
+
161
+
162
+ # [3.10.0](https://github.com/lingui/js-lingui/compare/v3.9.0...v3.10.0) (2021-06-08)
163
+
164
+
165
+ ### Bug Fixes
166
+
167
+ * reduce size of ESM packages ([#1066](https://github.com/lingui/js-lingui/issues/1066)) ([9990eba](https://github.com/lingui/js-lingui/commit/9990ebaa9d30f7e218c106a2abfd7ddbcf0e0170))
168
+
169
+
170
+
171
+
172
+
173
+ # [3.9.0](https://github.com/lingui/js-lingui/compare/v3.8.10...v3.9.0) (2021-05-18)
174
+
175
+
176
+ ### Bug Fixes
177
+
178
+ * 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))
179
+
180
+
181
+
182
+
183
+
184
+ ## [3.8.10](https://github.com/lingui/js-lingui/compare/v3.8.9...v3.8.10) (2021-04-19)
185
+
186
+ **Note:** Version bump only for package @lingui/core
187
+
188
+
189
+
190
+
191
+
192
+ ## [3.8.9](https://github.com/lingui/js-lingui/compare/v3.8.8...v3.8.9) (2021-04-09)
193
+
194
+
195
+ ### Bug Fixes
196
+
197
+ * event emitter refactor (reverted) ([#1038](https://github.com/lingui/js-lingui/issues/1038)) ([f299493](https://github.com/lingui/js-lingui/commit/f299493999299fe9a7d0e01b9045e7f0a9813c6a))
198
+
199
+
200
+
201
+
202
+
203
+ ## [3.8.8](https://github.com/lingui/js-lingui/compare/v3.8.7...v3.8.8) (2021-04-09)
204
+
205
+ **Note:** Version bump only for package @lingui/core
206
+
207
+
208
+
209
+
210
+
211
+ ## [3.8.7](https://github.com/lingui/js-lingui/compare/v3.8.6...v3.8.7) (2021-04-09)
212
+
213
+
214
+ ### Bug Fixes
215
+
216
+ * 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))
217
+
218
+
219
+
220
+
221
+
222
+ ## [3.8.6](https://github.com/lingui/js-lingui/compare/v3.8.5...v3.8.6) (2021-04-08)
223
+
224
+ **Note:** Version bump only for package @lingui/core
225
+
226
+
227
+
228
+
229
+
230
+ ## [3.8.5](https://github.com/lingui/js-lingui/compare/v3.8.4...v3.8.5) (2021-04-08)
231
+
232
+ **Note:** Version bump only for package @lingui/core
233
+
234
+
235
+
236
+
237
+
238
+ ## [3.8.4](https://github.com/lingui/js-lingui/compare/v3.8.3...v3.8.4) (2021-04-08)
239
+
240
+
241
+ ### Bug Fixes
242
+
243
+ * undefined interpolation on t macro ([#1030](https://github.com/lingui/js-lingui/issues/1030)) ([194f9b3](https://github.com/lingui/js-lingui/commit/194f9b318434bcaf4b68af549a6ed246fed2be02))
244
+
245
+
246
+
247
+
248
+
249
+ ## [3.8.3](https://github.com/lingui/js-lingui/compare/v3.8.2...v3.8.3) (2021-04-05)
250
+
251
+ **Note:** Version bump only for package @lingui/core
252
+
253
+
254
+
255
+
256
+
257
+ ## [3.8.2](https://github.com/lingui/js-lingui/compare/v3.8.1...v3.8.2) (2021-03-31)
258
+
259
+ **Note:** Version bump only for package @lingui/core
260
+
261
+
262
+
263
+
264
+
265
+ ## [3.8.1](https://github.com/lingui/js-lingui/compare/v3.8.0...v3.8.1) (2021-03-23)
266
+
267
+ **Note:** Version bump only for package @lingui/core
268
+
269
+
270
+
271
+
272
+
273
+ # [3.8.0](https://github.com/lingui/js-lingui/compare/v3.7.2...v3.8.0) (2021-03-23)
274
+
275
+ **Note:** Version bump only for package @lingui/core
276
+
277
+
278
+
279
+
280
+
281
+ ## [3.7.2](https://github.com/lingui/js-lingui/compare/v3.7.1...v3.7.2) (2021-03-14)
282
+
283
+ **Note:** Version bump only for package @lingui/core
284
+
285
+
286
+
287
+
288
+
289
+ ## [3.7.1](https://github.com/lingui/js-lingui/compare/v3.7.0...v3.7.1) (2021-03-07)
290
+
291
+
292
+ ### Bug Fixes
293
+
294
+ * 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))
295
+
296
+
297
+
298
+
299
+
300
+ # [3.7.0](https://github.com/lingui/js-lingui/compare/v3.6.0...v3.7.0) (2021-03-04)
301
+
302
+
303
+ ### Features
304
+
305
+ * raise event on missing translation ([#993](https://github.com/lingui/js-lingui/issues/993)) ([ecf83c3](https://github.com/lingui/js-lingui/commit/ecf83c37e177cb10f157fb8913d73e18662e3ca4))
306
+
307
+
308
+
309
+
310
+
311
+ # [3.6.0](https://github.com/lingui/js-lingui/compare/v3.5.1...v3.6.0) (2021-02-23)
312
+
313
+
314
+ ### Features
315
+
316
+ * ship universal modules with ESM ([#979](https://github.com/lingui/js-lingui/issues/979)) ([6cd5fe0](https://github.com/lingui/js-lingui/commit/6cd5fe0a71dd5cf7e0832bd3e9902a2f6ba789f6))
317
+
318
+
319
+
320
+
321
+
322
+ ## [3.5.1](https://github.com/lingui/js-lingui/compare/v3.5.0...v3.5.1) (2021-02-09)
323
+
324
+ **Note:** Version bump only for package @lingui/core
325
+
326
+
327
+
328
+
329
+
330
+ # [3.5.0](https://github.com/lingui/js-lingui/compare/v3.4.0...v3.5.0) (2021-02-02)
331
+
332
+ **Note:** Version bump only for package @lingui/core
333
+
334
+
335
+
336
+
337
+
338
+ # [3.4.0](https://github.com/lingui/js-lingui/compare/v3.3.0...v3.4.0) (2021-01-13)
339
+
340
+
341
+ ### Bug Fixes
342
+
343
+ * added return type to i18n._ ([#922](https://github.com/lingui/js-lingui/issues/922)) ([249c486](https://github.com/lingui/js-lingui/commit/249c486d258a4fb44bae1e3da1765e00003429a7))
344
+
345
+
346
+
347
+
348
+
349
+ # [3.3.0](https://github.com/lingui/js-lingui/compare/v3.2.3...v3.3.0) (2020-12-08)
350
+
351
+ **Note:** Version bump only for package @lingui/core
352
+
353
+
354
+
355
+
356
+
357
+ ## [3.2.3](https://github.com/lingui/js-lingui/compare/v3.2.2...v3.2.3) (2020-11-22)
358
+
359
+ **Note:** Version bump only for package @lingui/core
360
+
361
+
362
+
363
+
364
+
365
+ ## [3.2.2](https://github.com/lingui/js-lingui/compare/v3.2.1...v3.2.2) (2020-11-20)
366
+
367
+ **Note:** Version bump only for package @lingui/core
368
+
369
+
370
+
371
+
372
+
373
+ # [3.2.0](https://github.com/lingui/js-lingui/compare/v3.1.0...v3.2.0) (2020-11-12)
374
+
375
+
376
+ ### Bug Fixes
377
+
378
+ * MessageDescriptor values type ([#848](https://github.com/lingui/js-lingui/issues/848)) ([9712d94](https://github.com/lingui/js-lingui/commit/9712d94d043c8d40cbc5d017474b5938eb02f8d6))
379
+
380
+
381
+
382
+
383
+
384
+ # [3.1.0](https://github.com/lingui/js-lingui/compare/v3.0.3...v3.1.0) (2020-11-10)
385
+
386
+
387
+ ### Bug Fixes
388
+
389
+ * improved performance of formatters ([#818](https://github.com/lingui/js-lingui/issues/818)) ([22667ad](https://github.com/lingui/js-lingui/commit/22667adba5b07cc94abacff8e8b5f5b19202576c))
390
+ * 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))
391
+
392
+
393
+ ### Features
394
+
395
+ * 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) {
@@ -145,25 +147,20 @@ var defaultFormats = function defaultFormats(locale, locales) {
145
147
  };
146
148
  }; // Params -> CTX
147
149
 
148
- /**
149
- * Creates a context object, which formats ICU MessageFormat arguments based on
150
- * argument type.
151
- *
152
- * @param locale - Locale of message
153
- * @param locales - Locales to be used when formatting the numbers or dates
154
- * @param values - Parameters for variable interpolation
155
- * @param localeData - Locale data (e.g: plurals)
156
- * @param formats - Custom format styles
157
- * @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)}
158
160
  */
159
161
 
160
162
 
161
- function context(_ref3) {
162
- var locale = _ref3.locale,
163
- locales = _ref3.locales,
164
- values = _ref3.values,
165
- formats = _ref3.formats,
166
- localeData = _ref3.localeData;
163
+ function context(locale, locales, values, formats, localeData) {
167
164
  var formatters = defaultFormats(locale, locales, localeData, formats);
168
165
 
169
166
  var ctx = function ctx(name, type, format) {
@@ -179,13 +176,7 @@ function context(_ref3) {
179
176
  function interpolate(translation, locale, locales, localeData) {
180
177
  return function (values) {
181
178
  var formats = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
182
- var ctx = context({
183
- locale: locale,
184
- locales: locales,
185
- localeData: localeData,
186
- formats: formats,
187
- values: values
188
- });
179
+ var ctx = context(locale, locales, values, formats, localeData);
189
180
 
190
181
  var formatMessage = function formatMessage(message) {
191
182
  if (!Array.isArray(message)) return message;
@@ -220,58 +211,11 @@ function interpolate(translation, locale, locales, localeData) {
220
211
  };
221
212
  }
222
213
 
223
- 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; }
224
-
225
- 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; }
226
-
227
- function processTokens(tokens) {
228
- if (!tokens.filter(function (token) {
229
- return !isString(token);
230
- }).length) {
231
- return tokens.join("");
232
- }
233
-
234
- return tokens.map(function (token) {
235
- if (isString(token)) {
236
- return token; // # in plural case
237
- } else if (token.type === "octothorpe") {
238
- return "#"; // simple argument
239
- } else if (token.type === "argument") {
240
- return [token.arg]; // argument with custom format (date, number)
241
- } else if (token.type === "function") {
242
- var _param = token.param && token.param.tokens[0];
243
-
244
- var param = typeof _param === "string" ? _param.trim() : _param;
245
- return [token.arg, token.key, param].filter(Boolean);
246
- }
247
-
248
- var offset = token.offset ? parseInt(token.offset) : undefined; // complex argument with cases
249
-
250
- var formatProps = {};
251
- token.cases.forEach(function (item) {
252
- formatProps[item.key] = processTokens(item.tokens);
253
- });
254
- return [token.arg, token.type, _objectSpread({
255
- offset: offset
256
- }, formatProps)];
257
- });
258
- } // Message -> (Params -> String)
259
-
260
-
261
- function compile(message) {
262
- try {
263
- return processTokens(parse(message));
264
- } catch (e) {
265
- console.error("Message cannot be parsed due to syntax errors: ".concat(message));
266
- return message;
267
- }
268
- }
269
-
270
214
  var EventEmitter = /*#__PURE__*/function () {
271
215
  function EventEmitter() {
272
216
  _classCallCheck(this, EventEmitter);
273
217
 
274
- this._events = {};
218
+ _defineProperty(this, "_events", {});
275
219
  }
276
220
 
277
221
  _createClass(EventEmitter, [{
@@ -335,6 +279,17 @@ var I18n = /*#__PURE__*/function (_EventEmitter) {
335
279
  _classCallCheck(this, I18n);
336
280
 
337
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
+
338
293
  _this._messages = {};
339
294
  _this._localeData = {};
340
295
  if (params.missing != null) _this._missing = params.missing;
@@ -407,7 +362,7 @@ var I18n = /*#__PURE__*/function (_EventEmitter) {
407
362
  }, {
408
363
  key: "activate",
409
364
  value: function activate(locale, locales) {
410
- {
365
+ if (process.env.NODE_ENV !== "production") {
411
366
  if (!this._messages[locale]) {
412
367
  console.warn("Messages for locale \"".concat(locale, "\" not loaded."));
413
368
  }
@@ -466,8 +421,8 @@ var I18n = /*#__PURE__*/function (_EventEmitter) {
466
421
  translation = this.messages[id] || message || id;
467
422
  }
468
423
 
469
- {
470
- translation = isString(translation) ? compile(translation) : translation;
424
+ if (process.env.NODE_ENV !== "production") {
425
+ translation = isString(translation) ? compile.compileMessage(translation) : translation;
471
426
  } // hack for parsing unicode values inside a string to get parsed in react native environments
472
427
 
473
428
 
@@ -521,5 +476,8 @@ function setupI18n() {
521
476
 
522
477
  var i18n = setupI18n();
523
478
 
524
- export { I18n, formats, i18n, setupI18n };
525
- //# 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