@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.
- package/CHANGELOG.md +384 -0
- package/build/LICENSE +21 -0
- package/build/cjs/compile.js +68 -0
- package/build/cjs/compile.js.map +1 -0
- package/{esm/core.development.js → build/cjs/index.js} +46 -87
- package/build/cjs/index.js.map +1 -0
- package/build/compile.d.ts +2 -0
- package/build/compile.js +1 -0
- package/build/esm/compile.js +66 -0
- package/build/esm/compile.js.map +1 -0
- package/{esm/dev.development.js → build/esm/index.js} +33 -79
- package/build/esm/index.js.map +1 -0
- package/{esm → build/esm}/package.json +0 -0
- package/build/index.d.ts +94 -0
- package/build/index.js +1 -0
- package/package.json +16 -13
- package/cjs/context.d.ts +0 -4
- package/cjs/context.d.ts.map +0 -1
- package/cjs/core.development.js +0 -542
- package/cjs/core.development.js.map +0 -1
- package/cjs/core.production.min.js +0 -2
- package/cjs/core.production.min.js.map +0 -1
- package/cjs/dev/compile.d.ts +0 -3
- package/cjs/dev/compile.d.ts.map +0 -1
- package/cjs/dev/index.d.ts +0 -4
- package/cjs/dev/index.d.ts.map +0 -1
- package/cjs/dev/loadLocaleData.d.ts +0 -5
- package/cjs/dev/loadLocaleData.d.ts.map +0 -1
- package/cjs/dev.development.js +0 -542
- package/cjs/dev.development.js.map +0 -1
- package/cjs/dev.production.min.js +0 -2
- package/cjs/dev.production.min.js.map +0 -1
- package/cjs/essentials.d.ts +0 -4
- package/cjs/essentials.d.ts.map +0 -1
- package/cjs/eventEmitter.d.ts +0 -10
- package/cjs/eventEmitter.d.ts.map +0 -1
- package/cjs/formats.d.ts +0 -4
- package/cjs/formats.d.ts.map +0 -1
- package/cjs/i18n.d.ts +0 -63
- package/cjs/i18n.d.ts.map +0 -1
- package/cjs/index.d.ts +0 -5
- package/cjs/index.d.ts.map +0 -1
- package/esm/context.d.ts +0 -4
- package/esm/context.d.ts.map +0 -1
- package/esm/core.development.js.map +0 -1
- package/esm/core.production.min.js +0 -2
- package/esm/core.production.min.js.map +0 -1
- package/esm/dev/compile.d.ts +0 -3
- package/esm/dev/compile.d.ts.map +0 -1
- package/esm/dev/index.d.ts +0 -4
- package/esm/dev/index.d.ts.map +0 -1
- package/esm/dev/loadLocaleData.d.ts +0 -5
- package/esm/dev/loadLocaleData.d.ts.map +0 -1
- package/esm/dev.development.js.map +0 -1
- package/esm/dev.js +0 -18
- package/esm/dev.production.min.js +0 -2
- package/esm/dev.production.min.js.map +0 -1
- package/esm/essentials.d.ts +0 -4
- package/esm/essentials.d.ts.map +0 -1
- package/esm/eventEmitter.d.ts +0 -10
- package/esm/eventEmitter.d.ts.map +0 -1
- package/esm/formats.d.ts +0 -4
- package/esm/formats.d.ts.map +0 -1
- package/esm/i18n.d.ts +0 -63
- package/esm/i18n.d.ts.map +0 -1
- package/esm/index.d.ts +0 -5
- package/esm/index.d.ts.map +0 -1
- package/esm/index.js +0 -18
- package/index.js +0 -5
package/cjs/core.development.js
DELETED
|
@@ -1,542 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
|
|
6
|
-
var _createClass = require('@babel/runtime/helpers/createClass');
|
|
7
|
-
var _inherits = require('@babel/runtime/helpers/inherits');
|
|
8
|
-
var _possibleConstructorReturn = require('@babel/runtime/helpers/possibleConstructorReturn');
|
|
9
|
-
var _getPrototypeOf = require('@babel/runtime/helpers/getPrototypeOf');
|
|
10
|
-
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
11
|
-
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
12
|
-
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
13
|
-
var messageformatParser = require('messageformat-parser');
|
|
14
|
-
|
|
15
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
16
|
-
|
|
17
|
-
var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
|
|
18
|
-
var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
|
|
19
|
-
var _inherits__default = /*#__PURE__*/_interopDefaultLegacy(_inherits);
|
|
20
|
-
var _possibleConstructorReturn__default = /*#__PURE__*/_interopDefaultLegacy(_possibleConstructorReturn);
|
|
21
|
-
var _getPrototypeOf__default = /*#__PURE__*/_interopDefaultLegacy(_getPrototypeOf);
|
|
22
|
-
var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
|
|
23
|
-
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
|
|
24
|
-
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
25
|
-
|
|
26
|
-
var isString = function isString(s) {
|
|
27
|
-
return typeof s === "string";
|
|
28
|
-
};
|
|
29
|
-
var isFunction = function isFunction(f) {
|
|
30
|
-
return typeof f === "function";
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/** Memoized cache */
|
|
34
|
-
|
|
35
|
-
var numberFormats = new Map();
|
|
36
|
-
var dateFormats = new Map();
|
|
37
|
-
function date(locales) {
|
|
38
|
-
var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
39
|
-
var memoize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
40
|
-
return function (value) {
|
|
41
|
-
if (isString(value)) value = new Date(value);
|
|
42
|
-
|
|
43
|
-
if (memoize) {
|
|
44
|
-
var key = cacheKey(locales, format);
|
|
45
|
-
var cachedFormatter = dateFormats.get(key);
|
|
46
|
-
|
|
47
|
-
if (cachedFormatter) {
|
|
48
|
-
return cachedFormatter.format(value);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
var _formatter = new Intl.DateTimeFormat(locales, format);
|
|
52
|
-
|
|
53
|
-
dateFormats.set(key, _formatter);
|
|
54
|
-
return _formatter.format(value);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
var formatter = new Intl.DateTimeFormat(locales, format);
|
|
58
|
-
return formatter.format(value);
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
function number(locales) {
|
|
62
|
-
var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
63
|
-
var memoize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
64
|
-
return function (value) {
|
|
65
|
-
if (memoize) {
|
|
66
|
-
var key = cacheKey(locales, format);
|
|
67
|
-
var cachedFormatter = numberFormats.get(key);
|
|
68
|
-
|
|
69
|
-
if (cachedFormatter) {
|
|
70
|
-
return cachedFormatter.format(value);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
var _formatter2 = new Intl.NumberFormat(locales, format);
|
|
74
|
-
|
|
75
|
-
numberFormats.set(key, _formatter2);
|
|
76
|
-
return _formatter2.format(value);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
var formatter = new Intl.NumberFormat(locales, format);
|
|
80
|
-
return formatter.format(value);
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
/** Memoize helpers */
|
|
84
|
-
|
|
85
|
-
function cacheKey(locales) {
|
|
86
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
87
|
-
var localeKey = Array.isArray(locales) ? locales.sort().join('-') : locales;
|
|
88
|
-
return "".concat(localeKey, "-").concat(JSON.stringify(options));
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
var formats = /*#__PURE__*/Object.freeze({
|
|
92
|
-
__proto__: null,
|
|
93
|
-
date: date,
|
|
94
|
-
number: number
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
var UNICODE_REGEX = /\\u[a-fA-F0-9]{4}|\\x[a-fA-F0-9]{2}/g;
|
|
98
|
-
|
|
99
|
-
var defaultFormats = function defaultFormats(locale, locales) {
|
|
100
|
-
var localeData = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
101
|
-
plurals: undefined
|
|
102
|
-
};
|
|
103
|
-
var formats = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
104
|
-
locales = locales || locale;
|
|
105
|
-
var plurals = localeData.plurals;
|
|
106
|
-
|
|
107
|
-
var style = function style(format) {
|
|
108
|
-
return isString(format) ? formats[format] || {
|
|
109
|
-
style: format
|
|
110
|
-
} : format;
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
var replaceOctothorpe = function replaceOctothorpe(value, message) {
|
|
114
|
-
return function (ctx) {
|
|
115
|
-
var msg = isFunction(message) ? message(ctx) : message;
|
|
116
|
-
var norm = Array.isArray(msg) ? msg : [msg];
|
|
117
|
-
|
|
118
|
-
var valueStr = number(locales)(value);
|
|
119
|
-
|
|
120
|
-
return norm.map(function (m) {
|
|
121
|
-
return isString(m) ? m.replace("#", valueStr) : m;
|
|
122
|
-
});
|
|
123
|
-
};
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
if (!plurals) {
|
|
127
|
-
console.error("Plurals for locale ".concat(locale, " aren't loaded. Use i18n.loadLocaleData method to load plurals for specific locale. Using other plural rule as a fallback."));
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return {
|
|
131
|
-
plural: function plural(value, _ref) {
|
|
132
|
-
var _ref$offset = _ref.offset,
|
|
133
|
-
offset = _ref$offset === void 0 ? 0 : _ref$offset,
|
|
134
|
-
rules = _objectWithoutProperties__default['default'](_ref, ["offset"]);
|
|
135
|
-
|
|
136
|
-
var message = rules[value] || rules[plurals === null || plurals === void 0 ? void 0 : plurals(value - offset)] || rules.other;
|
|
137
|
-
return replaceOctothorpe(value - offset, message);
|
|
138
|
-
},
|
|
139
|
-
selectordinal: function selectordinal(value, _ref2) {
|
|
140
|
-
var _ref2$offset = _ref2.offset,
|
|
141
|
-
offset = _ref2$offset === void 0 ? 0 : _ref2$offset,
|
|
142
|
-
rules = _objectWithoutProperties__default['default'](_ref2, ["offset"]);
|
|
143
|
-
|
|
144
|
-
var message = rules[value] || rules[plurals === null || plurals === void 0 ? void 0 : plurals(value - offset, true)] || rules.other;
|
|
145
|
-
return replaceOctothorpe(value - offset, message);
|
|
146
|
-
},
|
|
147
|
-
select: function select(value, rules) {
|
|
148
|
-
return rules[value] || rules.other;
|
|
149
|
-
},
|
|
150
|
-
number: function number$1(value, format) {
|
|
151
|
-
return number(locales, style(format))(value);
|
|
152
|
-
},
|
|
153
|
-
date: function date$1(value, format) {
|
|
154
|
-
return date(locales, style(format))(value);
|
|
155
|
-
},
|
|
156
|
-
undefined: function undefined$1(value) {
|
|
157
|
-
return value;
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
}; // Params -> CTX
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Creates a context object, which formats ICU MessageFormat arguments based on
|
|
164
|
-
* argument type.
|
|
165
|
-
*
|
|
166
|
-
* @param locale - Locale of message
|
|
167
|
-
* @param locales - Locales to be used when formatting the numbers or dates
|
|
168
|
-
* @param values - Parameters for variable interpolation
|
|
169
|
-
* @param localeData - Locale data (e.g: plurals)
|
|
170
|
-
* @param formats - Custom format styles
|
|
171
|
-
* @returns {function(string, string, any)}
|
|
172
|
-
*/
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
function context(_ref3) {
|
|
176
|
-
var locale = _ref3.locale,
|
|
177
|
-
locales = _ref3.locales,
|
|
178
|
-
values = _ref3.values,
|
|
179
|
-
formats = _ref3.formats,
|
|
180
|
-
localeData = _ref3.localeData;
|
|
181
|
-
var formatters = defaultFormats(locale, locales, localeData, formats);
|
|
182
|
-
|
|
183
|
-
var ctx = function ctx(name, type, format) {
|
|
184
|
-
var value = values[name];
|
|
185
|
-
var formatted = formatters[type](value, format);
|
|
186
|
-
var message = isFunction(formatted) ? formatted(ctx) : formatted;
|
|
187
|
-
return Array.isArray(message) ? message.join("") : message;
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
return ctx;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function interpolate(translation, locale, locales, localeData) {
|
|
194
|
-
return function (values) {
|
|
195
|
-
var formats = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
196
|
-
var ctx = context({
|
|
197
|
-
locale: locale,
|
|
198
|
-
locales: locales,
|
|
199
|
-
localeData: localeData,
|
|
200
|
-
formats: formats,
|
|
201
|
-
values: values
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
var formatMessage = function formatMessage(message) {
|
|
205
|
-
if (!Array.isArray(message)) return message;
|
|
206
|
-
return message.reduce(function (message, token) {
|
|
207
|
-
if (isString(token)) return message + token;
|
|
208
|
-
|
|
209
|
-
var _token = _slicedToArray__default['default'](token, 3),
|
|
210
|
-
name = _token[0],
|
|
211
|
-
type = _token[1],
|
|
212
|
-
format = _token[2];
|
|
213
|
-
|
|
214
|
-
var interpolatedFormat = {};
|
|
215
|
-
|
|
216
|
-
if (format != null && !isString(format)) {
|
|
217
|
-
Object.keys(format).forEach(function (key) {
|
|
218
|
-
interpolatedFormat[key] = formatMessage(format[key]);
|
|
219
|
-
});
|
|
220
|
-
} else {
|
|
221
|
-
interpolatedFormat = format;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
var value = ctx(name, type, interpolatedFormat);
|
|
225
|
-
if (value == null) return message;
|
|
226
|
-
return message + value;
|
|
227
|
-
}, "");
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
var result = formatMessage(translation);
|
|
231
|
-
if (isString(result) && UNICODE_REGEX.test(result)) return JSON.parse("\"".concat(result.trim(), "\""));
|
|
232
|
-
if (isString(result)) return result.trim();
|
|
233
|
-
return result;
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
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; }
|
|
238
|
-
|
|
239
|
-
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__default['default'](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; }
|
|
240
|
-
|
|
241
|
-
function processTokens(tokens) {
|
|
242
|
-
if (!tokens.filter(function (token) {
|
|
243
|
-
return !isString(token);
|
|
244
|
-
}).length) {
|
|
245
|
-
return tokens.join("");
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return tokens.map(function (token) {
|
|
249
|
-
if (isString(token)) {
|
|
250
|
-
return token; // # in plural case
|
|
251
|
-
} else if (token.type === "octothorpe") {
|
|
252
|
-
return "#"; // simple argument
|
|
253
|
-
} else if (token.type === "argument") {
|
|
254
|
-
return [token.arg]; // argument with custom format (date, number)
|
|
255
|
-
} else if (token.type === "function") {
|
|
256
|
-
var _param = token.param && token.param.tokens[0];
|
|
257
|
-
|
|
258
|
-
var param = typeof _param === "string" ? _param.trim() : _param;
|
|
259
|
-
return [token.arg, token.key, param].filter(Boolean);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
var offset = token.offset ? parseInt(token.offset) : undefined; // complex argument with cases
|
|
263
|
-
|
|
264
|
-
var formatProps = {};
|
|
265
|
-
token.cases.forEach(function (item) {
|
|
266
|
-
formatProps[item.key] = processTokens(item.tokens);
|
|
267
|
-
});
|
|
268
|
-
return [token.arg, token.type, _objectSpread({
|
|
269
|
-
offset: offset
|
|
270
|
-
}, formatProps)];
|
|
271
|
-
});
|
|
272
|
-
} // Message -> (Params -> String)
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
function compile(message) {
|
|
276
|
-
try {
|
|
277
|
-
return processTokens(messageformatParser.parse(message));
|
|
278
|
-
} catch (e) {
|
|
279
|
-
console.error("Message cannot be parsed due to syntax errors: ".concat(message));
|
|
280
|
-
return message;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
var EventEmitter = /*#__PURE__*/function () {
|
|
285
|
-
function EventEmitter() {
|
|
286
|
-
_classCallCheck__default['default'](this, EventEmitter);
|
|
287
|
-
|
|
288
|
-
this._events = {};
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
_createClass__default['default'](EventEmitter, [{
|
|
292
|
-
key: "on",
|
|
293
|
-
value: function on(event, listener) {
|
|
294
|
-
var _this = this;
|
|
295
|
-
|
|
296
|
-
if (!this._hasEvent(event)) this._events[event] = [];
|
|
297
|
-
|
|
298
|
-
this._events[event].push(listener);
|
|
299
|
-
|
|
300
|
-
return function () {
|
|
301
|
-
return _this.removeListener(event, listener);
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
}, {
|
|
305
|
-
key: "removeListener",
|
|
306
|
-
value: function removeListener(event, listener) {
|
|
307
|
-
if (!this._hasEvent(event)) return;
|
|
308
|
-
|
|
309
|
-
var index = this._events[event].indexOf(listener);
|
|
310
|
-
|
|
311
|
-
if (~index) this._events[event].splice(index, 1);
|
|
312
|
-
}
|
|
313
|
-
}, {
|
|
314
|
-
key: "emit",
|
|
315
|
-
value: function emit(event) {
|
|
316
|
-
var _this2 = this;
|
|
317
|
-
|
|
318
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
319
|
-
args[_key - 1] = arguments[_key];
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
if (!this._hasEvent(event)) return;
|
|
323
|
-
|
|
324
|
-
this._events[event].map(function (listener) {
|
|
325
|
-
return listener.apply(_this2, args);
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
}, {
|
|
329
|
-
key: "_hasEvent",
|
|
330
|
-
value: function _hasEvent(event) {
|
|
331
|
-
return Array.isArray(this._events[event]);
|
|
332
|
-
}
|
|
333
|
-
}]);
|
|
334
|
-
|
|
335
|
-
return EventEmitter;
|
|
336
|
-
}();
|
|
337
|
-
|
|
338
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; }
|
|
339
|
-
|
|
340
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
341
|
-
var I18n = /*#__PURE__*/function (_EventEmitter) {
|
|
342
|
-
_inherits__default['default'](I18n, _EventEmitter);
|
|
343
|
-
|
|
344
|
-
var _super = _createSuper(I18n);
|
|
345
|
-
|
|
346
|
-
function I18n(params) {
|
|
347
|
-
var _this;
|
|
348
|
-
|
|
349
|
-
_classCallCheck__default['default'](this, I18n);
|
|
350
|
-
|
|
351
|
-
_this = _super.call(this);
|
|
352
|
-
_this._messages = {};
|
|
353
|
-
_this._localeData = {};
|
|
354
|
-
if (params.missing != null) _this._missing = params.missing;
|
|
355
|
-
if (params.messages != null) _this.load(params.messages);
|
|
356
|
-
if (params.localeData != null) _this.loadLocaleData(params.localeData);
|
|
357
|
-
|
|
358
|
-
if (params.locale != null || params.locales != null) {
|
|
359
|
-
_this.activate(params.locale, params.locales);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
return _this;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
_createClass__default['default'](I18n, [{
|
|
366
|
-
key: "_loadLocaleData",
|
|
367
|
-
value: function _loadLocaleData(locale, localeData) {
|
|
368
|
-
if (this._localeData[locale] == null) {
|
|
369
|
-
this._localeData[locale] = localeData;
|
|
370
|
-
} else {
|
|
371
|
-
Object.assign(this._localeData[locale], localeData);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
}, {
|
|
375
|
-
key: "loadLocaleData",
|
|
376
|
-
value: function loadLocaleData(localeOrAllData, localeData) {
|
|
377
|
-
var _this2 = this;
|
|
378
|
-
|
|
379
|
-
if (localeData != null) {
|
|
380
|
-
// loadLocaleData('en', enLocaleData)
|
|
381
|
-
// Loading locale data for a single locale.
|
|
382
|
-
this._loadLocaleData(localeOrAllData, localeData);
|
|
383
|
-
} else {
|
|
384
|
-
// loadLocaleData(allLocaleData)
|
|
385
|
-
// Loading all locale data at once.
|
|
386
|
-
Object.keys(localeOrAllData).forEach(function (locale) {
|
|
387
|
-
return _this2._loadLocaleData(locale, localeOrAllData[locale]);
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
this.emit("change");
|
|
392
|
-
}
|
|
393
|
-
}, {
|
|
394
|
-
key: "_load",
|
|
395
|
-
value: function _load(locale, messages) {
|
|
396
|
-
if (this._messages[locale] == null) {
|
|
397
|
-
this._messages[locale] = messages;
|
|
398
|
-
} else {
|
|
399
|
-
Object.assign(this._messages[locale], messages);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}, {
|
|
403
|
-
key: "load",
|
|
404
|
-
value: function load(localeOrMessages, messages) {
|
|
405
|
-
var _this3 = this;
|
|
406
|
-
|
|
407
|
-
if (messages != null) {
|
|
408
|
-
// load('en', catalog)
|
|
409
|
-
// Loading a catalog for a single locale.
|
|
410
|
-
this._load(localeOrMessages, messages);
|
|
411
|
-
} else {
|
|
412
|
-
// load(catalogs)
|
|
413
|
-
// Loading several locales at once.
|
|
414
|
-
Object.keys(localeOrMessages).forEach(function (locale) {
|
|
415
|
-
return _this3._load(locale, localeOrMessages[locale]);
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
this.emit("change");
|
|
420
|
-
}
|
|
421
|
-
}, {
|
|
422
|
-
key: "activate",
|
|
423
|
-
value: function activate(locale, locales) {
|
|
424
|
-
{
|
|
425
|
-
if (!this._messages[locale]) {
|
|
426
|
-
console.warn("Messages for locale \"".concat(locale, "\" not loaded."));
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
if (!this._localeData[locale]) {
|
|
430
|
-
console.warn("Locale data for locale \"".concat(locale, "\" not loaded. Plurals won't work correctly."));
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
this._locale = locale;
|
|
435
|
-
this._locales = locales;
|
|
436
|
-
this.emit("change");
|
|
437
|
-
} // method for translation and formatting
|
|
438
|
-
|
|
439
|
-
}, {
|
|
440
|
-
key: "_",
|
|
441
|
-
value: function _(id) {
|
|
442
|
-
var values = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
443
|
-
|
|
444
|
-
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
445
|
-
message = _ref.message,
|
|
446
|
-
formats = _ref.formats,
|
|
447
|
-
context = _ref.context;
|
|
448
|
-
|
|
449
|
-
if (!isString(id)) {
|
|
450
|
-
values = id.values || values;
|
|
451
|
-
message = id.message;
|
|
452
|
-
context = id.context;
|
|
453
|
-
id = id.id;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
var messageMissing = !context && !this.messages[id];
|
|
457
|
-
var contextualMessageMissing = context && !this.messages[context][id];
|
|
458
|
-
var messageUnreachable = contextualMessageMissing || messageMissing; // replace missing messages with custom message for debugging
|
|
459
|
-
|
|
460
|
-
var missing = this._missing;
|
|
461
|
-
|
|
462
|
-
if (missing && messageUnreachable) {
|
|
463
|
-
return isFunction(missing) ? missing(this._locale, id, context) : missing;
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
if (messageUnreachable) {
|
|
467
|
-
this.emit("missing", {
|
|
468
|
-
id: id,
|
|
469
|
-
context: context,
|
|
470
|
-
locale: this._locale
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
var translation;
|
|
475
|
-
|
|
476
|
-
if (context && !contextualMessageMissing) {
|
|
477
|
-
// context is like a subdirectory of other keys
|
|
478
|
-
translation = this.messages[context][id] || message || id;
|
|
479
|
-
} else {
|
|
480
|
-
translation = this.messages[id] || message || id;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
{
|
|
484
|
-
translation = isString(translation) ? compile(translation) : translation;
|
|
485
|
-
} // hack for parsing unicode values inside a string to get parsed in react native environments
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
if (isString(translation) && UNICODE_REGEX.test(translation)) return JSON.parse("\"".concat(translation, "\""));
|
|
489
|
-
if (isString(translation)) return translation;
|
|
490
|
-
return interpolate(translation, this._locale, this._locales, this.localeData)(values, formats);
|
|
491
|
-
}
|
|
492
|
-
}, {
|
|
493
|
-
key: "date",
|
|
494
|
-
value: function date$1(value, format) {
|
|
495
|
-
return date(this._locales || this._locale, format)(value);
|
|
496
|
-
}
|
|
497
|
-
}, {
|
|
498
|
-
key: "number",
|
|
499
|
-
value: function number$1(value, format) {
|
|
500
|
-
return number(this._locales || this._locale, format)(value);
|
|
501
|
-
}
|
|
502
|
-
}, {
|
|
503
|
-
key: "locale",
|
|
504
|
-
get: function get() {
|
|
505
|
-
return this._locale;
|
|
506
|
-
}
|
|
507
|
-
}, {
|
|
508
|
-
key: "locales",
|
|
509
|
-
get: function get() {
|
|
510
|
-
return this._locales;
|
|
511
|
-
}
|
|
512
|
-
}, {
|
|
513
|
-
key: "messages",
|
|
514
|
-
get: function get() {
|
|
515
|
-
var _this$_messages$this$;
|
|
516
|
-
|
|
517
|
-
return (_this$_messages$this$ = this._messages[this._locale]) !== null && _this$_messages$this$ !== void 0 ? _this$_messages$this$ : {};
|
|
518
|
-
}
|
|
519
|
-
}, {
|
|
520
|
-
key: "localeData",
|
|
521
|
-
get: function get() {
|
|
522
|
-
var _this$_localeData$thi;
|
|
523
|
-
|
|
524
|
-
return (_this$_localeData$thi = this._localeData[this._locale]) !== null && _this$_localeData$thi !== void 0 ? _this$_localeData$thi : {};
|
|
525
|
-
}
|
|
526
|
-
}]);
|
|
527
|
-
|
|
528
|
-
return I18n;
|
|
529
|
-
}(EventEmitter);
|
|
530
|
-
|
|
531
|
-
function setupI18n() {
|
|
532
|
-
var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
533
|
-
return new I18n(params);
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
var i18n = setupI18n();
|
|
537
|
-
|
|
538
|
-
exports.I18n = I18n;
|
|
539
|
-
exports.formats = formats;
|
|
540
|
-
exports.i18n = i18n;
|
|
541
|
-
exports.setupI18n = setupI18n;
|
|
542
|
-
//# sourceMappingURL=core.development.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core.development.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/classCallCheck"),t=require("@babel/runtime/helpers/createClass"),r=require("@babel/runtime/helpers/inherits"),n=require("@babel/runtime/helpers/possibleConstructorReturn"),a=require("@babel/runtime/helpers/getPrototypeOf"),l=require("@babel/runtime/helpers/slicedToArray"),o=require("@babel/runtime/helpers/objectWithoutProperties");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=i(e),u=i(t),c=i(r),f=i(n),h=i(a),v=i(l),d=i(o),m=function(e){return"string"==typeof e},_=function(e){return"function"==typeof e},g=new Map,y=new Map;function p(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return function(n){if(m(n)&&(n=new Date(n)),r){var a=D(e,t),l=y.get(a);if(l)return l.format(n);var o=new Intl.DateTimeFormat(e,t);return y.set(a,o),o.format(n)}var i=new Intl.DateTimeFormat(e,t);return i.format(n)}}function b(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];return function(n){if(r){var a=D(e,t),l=g.get(a);if(l)return l.format(n);var o=new Intl.NumberFormat(e,t);return g.set(a,o),o.format(n)}var i=new Intl.NumberFormat(e,t);return i.format(n)}}function D(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=Array.isArray(e)?e.sort().join("-"):e;return"".concat(r,"-").concat(JSON.stringify(t))}var k=Object.freeze({__proto__:null,date:p,number:b}),A=/\\u[a-fA-F0-9]{4}|\\x[a-fA-F0-9]{2}/g;function O(e){var t=e.locale,r=e.locales,n=e.values,a=e.formats,l=e.localeData,o=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{plurals:void 0},n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};t=t||e;var a=r.plurals,l=function(e){return m(e)?n[e]||{style:e}:e},o=function(e,r){return function(n){var a=_(r)?r(n):r,l=Array.isArray(a)?a:[a],o=b(t)(e);return l.map((function(e){return m(e)?e.replace("#",o):e}))}};return a||console.error("Plurals for locale ".concat(e," aren't loaded. Use i18n.loadLocaleData method to load plurals for specific locale. Using other plural rule as a fallback.")),{plural:function(e,t){var r=t.offset,n=void 0===r?0:r,l=d.default(t,["offset"]),i=l[e]||l[null==a?void 0:a(e-n)]||l.other;return o(e-n,i)},selectordinal:function(e,t){var r=t.offset,n=void 0===r?0:r,l=d.default(t,["offset"]),i=l[e]||l[null==a?void 0:a(e-n,!0)]||l.other;return o(e-n,i)},select:function(e,t){return t[e]||t.other},number:function(e,r){return b(t,l(r))(e)},date:function(e,r){return p(t,l(r))(e)},undefined:function(e){return e}}}(t,r,l,a);return function e(t,r,a){var l=n[t],i=o[r](l,a),s=_(i)?i(e):i;return Array.isArray(s)?s.join(""):s}}function j(e,t,r,n){return function(a){var l=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=O({locale:t,locales:r,localeData:n,formats:l,values:a}),i=function e(t){return Array.isArray(t)?t.reduce((function(t,r){if(m(r))return t+r;var n=v.default(r,3),a=n[0],l=n[1],i=n[2],s={};null==i||m(i)?s=i:Object.keys(i).forEach((function(t){s[t]=e(i[t])}));var u=o(a,l,s);return null==u?t:t+u}),""):t},s=i(e);return m(s)&&A.test(s)?JSON.parse('"'.concat(s.trim(),'"')):m(s)?s.trim():s}}var x=function(){function e(){s.default(this,e),this._events={}}return u.default(e,[{key:"on",value:function(e,t){var r=this;return this._hasEvent(e)||(this._events[e]=[]),this._events[e].push(t),function(){return r.removeListener(e,t)}}},{key:"removeListener",value:function(e,t){if(this._hasEvent(e)){var r=this._events[e].indexOf(t);~r&&this._events[e].splice(r,1)}}},{key:"emit",value:function(e){for(var t=this,r=arguments.length,n=new Array(r>1?r-1:0),a=1;a<r;a++)n[a-1]=arguments[a];this._hasEvent(e)&&this._events[e].map((function(e){return e.apply(t,n)}))}},{key:"_hasEvent",value:function(e){return Array.isArray(this._events[e])}}]),e}();function w(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=h.default(e);if(t){var a=h.default(this).constructor;r=Reflect.construct(n,arguments,a)}else r=n.apply(this,arguments);return f.default(this,r)}}var L=function(e){c.default(r,e);var t=w(r);function r(e){var n;return s.default(this,r),n=t.call(this),n._messages={},n._localeData={},null!=e.missing&&(n._missing=e.missing),null!=e.messages&&n.load(e.messages),null!=e.localeData&&n.loadLocaleData(e.localeData),null==e.locale&&null==e.locales||n.activate(e.locale,e.locales),n}return u.default(r,[{key:"_loadLocaleData",value:function(e,t){null==this._localeData[e]?this._localeData[e]=t:Object.assign(this._localeData[e],t)}},{key:"loadLocaleData",value:function(e,t){var r=this;null!=t?this._loadLocaleData(e,t):Object.keys(e).forEach((function(t){return r._loadLocaleData(t,e[t])})),this.emit("change")}},{key:"_load",value:function(e,t){null==this._messages[e]?this._messages[e]=t:Object.assign(this._messages[e],t)}},{key:"load",value:function(e,t){var r=this;null!=t?this._load(e,t):Object.keys(e).forEach((function(t){return r._load(t,e[t])})),this.emit("change")}},{key:"activate",value:function(e,t){this._locale=e,this._locales=t,this.emit("change")}},{key:"_",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.message,a=r.formats,l=r.context;m(e)||(t=e.values||t,n=e.message,l=e.context,e=e.id);var o,i=!l&&!this.messages[e],s=l&&!this.messages[l][e],u=s||i,c=this._missing;return c&&u?_(c)?c(this._locale,e,l):c:(u&&this.emit("missing",{id:e,context:l,locale:this._locale}),o=l&&!s?this.messages[l][e]||n||e:this.messages[e]||n||e,m(o)&&A.test(o)?JSON.parse('"'.concat(o,'"')):m(o)?o:j(o,this._locale,this._locales,this.localeData)(t,a))}},{key:"date",value:function(e,t){return p(this._locales||this._locale,t)(e)}},{key:"number",value:function(e,t){return b(this._locales||this._locale,t)(e)}},{key:"locale",get:function(){return this._locale}},{key:"locales",get:function(){return this._locales}},{key:"messages",get:function(){var e;return null!==(e=this._messages[this._locale])&&void 0!==e?e:{}}},{key:"localeData",get:function(){var e;return null!==(e=this._localeData[this._locale])&&void 0!==e?e:{}}}]),r}(x);function q(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return new L(e)}var E=q();exports.I18n=L,exports.formats=k,exports.i18n=E,exports.setupI18n=q;
|
|
2
|
-
//# sourceMappingURL=core.production.min.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core.production.min.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/cjs/dev/compile.d.ts
DELETED
package/cjs/dev/compile.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../packages/core/src/dev/compile.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AA+CzC,MAAM,CAAC,OAAO,UAAU,OAAO,CAC7B,OAAO,EAAE,MAAM,GACd,eAAe,CAOjB"}
|
package/cjs/dev/index.d.ts
DELETED
package/cjs/dev/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../packages/core/src/dev/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,WAAW,CAAA;AAC/B,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAE7C,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"loadLocaleData.d.ts","sourceRoot":"","sources":["../packages/core/src/dev/loadLocaleData.ts"],"names":[],"mappings":"iCAEwB,MAAM;;;AAA9B,wBAOC"}
|