@lingui/core 5.9.1 → 6.0.0-next.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/dist/index.cjs +36 -56
- package/dist/index.d.cts +23 -7
- package/dist/index.d.mts +23 -7
- package/dist/index.mjs +36 -56
- package/macro/browser.cjs +12 -0
- package/macro/index.cjs +6 -0
- package/package.json +20 -29
- package/dist/index.d.ts +0 -159
- package/macro/index.js +0 -1
- /package/macro/{index.d.ts → index.d.cts} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -129,8 +129,7 @@ const OCTOTHORPE_PH = "%__lingui_octothorpe__%";
|
|
|
129
129
|
const getDefaultFormats = (locale, passedLocales, formats = {}) => {
|
|
130
130
|
const locales = passedLocales || locale;
|
|
131
131
|
const style = (format) => {
|
|
132
|
-
if (typeof format === "object")
|
|
133
|
-
return format;
|
|
132
|
+
if (typeof format === "object") return format;
|
|
134
133
|
return formats[format];
|
|
135
134
|
};
|
|
136
135
|
const replaceOctothorpe = (value, message) => {
|
|
@@ -164,8 +163,7 @@ function interpolate(translation, locale, locales) {
|
|
|
164
163
|
return (values = {}, formats) => {
|
|
165
164
|
const formatters = getDefaultFormats(locale, locales, formats);
|
|
166
165
|
const formatMessage = (tokens, replaceOctothorpe = false) => {
|
|
167
|
-
if (!Array.isArray(tokens))
|
|
168
|
-
return tokens;
|
|
166
|
+
if (!Array.isArray(tokens)) return tokens;
|
|
169
167
|
return tokens.reduce((message, token) => {
|
|
170
168
|
if (token === "#" && replaceOctothorpe) {
|
|
171
169
|
return message + OCTOTHORPE_PH;
|
|
@@ -204,76 +202,49 @@ function interpolate(translation, locale, locales) {
|
|
|
204
202
|
if (isString(result) && ESCAPE_SEQUENCE_REGEX.test(result)) {
|
|
205
203
|
return decodeEscapeSequences(result);
|
|
206
204
|
}
|
|
207
|
-
if (isString(result))
|
|
208
|
-
return result;
|
|
205
|
+
if (isString(result)) return result;
|
|
209
206
|
return result ? String(result) : "";
|
|
210
207
|
};
|
|
211
208
|
}
|
|
212
209
|
|
|
213
|
-
var __defProp$1 = Object.defineProperty;
|
|
214
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
215
|
-
var __publicField$1 = (obj, key, value) => {
|
|
216
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
217
|
-
return value;
|
|
218
|
-
};
|
|
219
210
|
class EventEmitter {
|
|
220
|
-
|
|
221
|
-
__publicField$1(this, "_events", {});
|
|
222
|
-
}
|
|
211
|
+
_events = {};
|
|
223
212
|
on(event, listener) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
this._events[event].push(listener);
|
|
213
|
+
this._events[event] ??= /* @__PURE__ */ new Set();
|
|
214
|
+
this._events[event].add(listener);
|
|
227
215
|
return () => this.removeListener(event, listener);
|
|
228
216
|
}
|
|
229
217
|
removeListener(event, listener) {
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
maybeListeners.splice(index, 1);
|
|
218
|
+
const listeners = this._events[event];
|
|
219
|
+
listeners?.delete(listener);
|
|
220
|
+
if (listeners?.size === 0) {
|
|
221
|
+
delete this._events[event];
|
|
222
|
+
}
|
|
236
223
|
}
|
|
237
224
|
emit(event, ...args) {
|
|
238
|
-
const
|
|
239
|
-
if (!
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
_getListeners(event) {
|
|
244
|
-
const maybeListeners = this._events[event];
|
|
245
|
-
return Array.isArray(maybeListeners) ? maybeListeners : false;
|
|
225
|
+
const listeners = this._events[event];
|
|
226
|
+
if (!listeners) return;
|
|
227
|
+
for (const listener of [...listeners]) {
|
|
228
|
+
listener.apply(this, args);
|
|
229
|
+
}
|
|
246
230
|
}
|
|
247
231
|
}
|
|
248
232
|
|
|
249
|
-
var __defProp = Object.defineProperty;
|
|
250
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
251
|
-
var __publicField = (obj, key, value) => {
|
|
252
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
253
|
-
return value;
|
|
254
|
-
};
|
|
255
233
|
class I18n extends EventEmitter {
|
|
234
|
+
_locale = "";
|
|
235
|
+
_locales;
|
|
236
|
+
_localeData = {};
|
|
237
|
+
_messages = {};
|
|
238
|
+
_missing;
|
|
239
|
+
_messageCompiler;
|
|
256
240
|
constructor(params) {
|
|
257
241
|
super();
|
|
258
|
-
__publicField(this, "_locale", "");
|
|
259
|
-
__publicField(this, "_locales");
|
|
260
|
-
__publicField(this, "_localeData", {});
|
|
261
|
-
__publicField(this, "_messages", {});
|
|
262
|
-
__publicField(this, "_missing");
|
|
263
|
-
__publicField(this, "_messageCompiler");
|
|
264
|
-
/**
|
|
265
|
-
* Alias for {@see I18n._}
|
|
266
|
-
*/
|
|
267
|
-
__publicField(this, "t", this._.bind(this));
|
|
268
242
|
if (process.env.NODE_ENV !== "production") {
|
|
269
243
|
this.setMessagesCompiler(compileMessage.compileMessage);
|
|
270
244
|
}
|
|
271
|
-
if (params.missing != null)
|
|
272
|
-
|
|
273
|
-
if (params.
|
|
274
|
-
this.load(params.messages);
|
|
275
|
-
if (params.localeData != null)
|
|
276
|
-
this.loadLocaleData(params.localeData);
|
|
245
|
+
if (params.missing != null) this._missing = params.missing;
|
|
246
|
+
if (params.messages != null) this.load(params.messages);
|
|
247
|
+
if (params.localeData != null) this.loadLocaleData(params.localeData);
|
|
277
248
|
if (typeof params.locale === "string" || params.locales) {
|
|
278
249
|
this.activate(params.locale ?? defaultLocale, params.locales);
|
|
279
250
|
}
|
|
@@ -412,17 +383,26 @@ Please compile your catalog first.
|
|
|
412
383
|
}
|
|
413
384
|
if (isString(translation) && ESCAPE_SEQUENCE_REGEX.test(translation))
|
|
414
385
|
return decodeEscapeSequences(translation);
|
|
415
|
-
if (isString(translation))
|
|
416
|
-
return translation;
|
|
386
|
+
if (isString(translation)) return translation;
|
|
417
387
|
return interpolate(
|
|
418
388
|
translation,
|
|
419
389
|
this._locale,
|
|
420
390
|
this._locales
|
|
421
391
|
)(values, options?.formats);
|
|
422
392
|
}
|
|
393
|
+
/**
|
|
394
|
+
* Alias for {@see I18n._}
|
|
395
|
+
*/
|
|
396
|
+
t = this._.bind(this);
|
|
397
|
+
/**
|
|
398
|
+
* @deprecated Use `Intl.DateTimeFormat` directly. This helper will be removed.
|
|
399
|
+
*/
|
|
423
400
|
date(value, format) {
|
|
424
401
|
return date(this._locales || this._locale, value, format);
|
|
425
402
|
}
|
|
403
|
+
/**
|
|
404
|
+
* @deprecated Use `Intl.NumberFormat` directly. This helper will be removed.
|
|
405
|
+
*/
|
|
426
406
|
number(value, format) {
|
|
427
407
|
return number(this._locales || this._locale, value, format);
|
|
428
408
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -4,8 +4,17 @@ declare const defaultLocale = "en";
|
|
|
4
4
|
type DateTimeFormatSize = "short" | "default" | "long" | "full";
|
|
5
5
|
type DateTimeFormatValue = Parameters<Intl.DateTimeFormat["format"]>[0];
|
|
6
6
|
type NumberFormatValue = Parameters<Intl.NumberFormat["format"]>[0];
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use `Intl.DateTimeFormat` directly. This helper will be removed.
|
|
9
|
+
*/
|
|
7
10
|
declare function date(locales: Locales, value: string | DateTimeFormatValue, format?: Intl.DateTimeFormatOptions | DateTimeFormatSize): string;
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated Use `Intl.DateTimeFormat` directly. This helper will be removed.
|
|
13
|
+
*/
|
|
8
14
|
declare function time(locales: Locales, value: string | DateTimeFormatValue, format?: Intl.DateTimeFormatOptions | DateTimeFormatSize): string;
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Use `Intl.NumberFormat` directly. This helper will be removed.
|
|
17
|
+
*/
|
|
9
18
|
declare function number(locales: Locales, value: NumberFormatValue, format?: Intl.NumberFormatOptions): string;
|
|
10
19
|
type PluralOptions = {
|
|
11
20
|
[key: string]: Intl.LDMLPluralRule;
|
|
@@ -25,17 +34,17 @@ declare const formats_number: typeof number;
|
|
|
25
34
|
declare const formats_plural: typeof plural;
|
|
26
35
|
declare const formats_time: typeof time;
|
|
27
36
|
declare namespace formats {
|
|
28
|
-
export {
|
|
37
|
+
export { formats_date as date, formats_defaultLocale as defaultLocale, formats_number as number, formats_plural as plural, formats_time as time };
|
|
38
|
+
export type { formats_DateTimeFormatSize as DateTimeFormatSize, formats_DateTimeFormatValue as DateTimeFormatValue, formats_NumberFormatValue as NumberFormatValue, formats_PluralOptions as PluralOptions };
|
|
29
39
|
}
|
|
30
40
|
|
|
31
41
|
declare class EventEmitter<Events extends {
|
|
32
|
-
[name: string]: (...args: any[]) =>
|
|
42
|
+
[name: string]: (...args: any[]) => void;
|
|
33
43
|
}> {
|
|
34
44
|
private readonly _events;
|
|
35
|
-
on(event:
|
|
36
|
-
removeListener(event:
|
|
37
|
-
emit(event:
|
|
38
|
-
private _getListeners;
|
|
45
|
+
on<E extends keyof Events>(event: E, listener: Events[E]): () => void;
|
|
46
|
+
removeListener<E extends keyof Events>(event: E, listener: Events[E]): void;
|
|
47
|
+
emit<E extends keyof Events>(event: E, ...args: Parameters<Events[E]>): void;
|
|
39
48
|
}
|
|
40
49
|
|
|
41
50
|
type MessageOptions = {
|
|
@@ -149,11 +158,18 @@ declare class I18n extends EventEmitter<Events> {
|
|
|
149
158
|
* Alias for {@see I18n._}
|
|
150
159
|
*/
|
|
151
160
|
t: I18n["_"];
|
|
161
|
+
/**
|
|
162
|
+
* @deprecated Use `Intl.DateTimeFormat` directly. This helper will be removed.
|
|
163
|
+
*/
|
|
152
164
|
date(value?: string | DateTimeFormatValue, format?: Intl.DateTimeFormatOptions): string;
|
|
165
|
+
/**
|
|
166
|
+
* @deprecated Use `Intl.NumberFormat` directly. This helper will be removed.
|
|
167
|
+
*/
|
|
153
168
|
number(value: NumberFormatValue, format?: Intl.NumberFormatOptions): string;
|
|
154
169
|
}
|
|
155
170
|
declare function setupI18n(params?: I18nProps): I18n;
|
|
156
171
|
|
|
157
172
|
declare const i18n: I18n;
|
|
158
173
|
|
|
159
|
-
export {
|
|
174
|
+
export { I18n, formats, i18n, setupI18n };
|
|
175
|
+
export type { AllLocaleData, AllMessages, Locale, LocaleData, Locales, MessageDescriptor, MessageOptions, Messages };
|
package/dist/index.d.mts
CHANGED
|
@@ -4,8 +4,17 @@ declare const defaultLocale = "en";
|
|
|
4
4
|
type DateTimeFormatSize = "short" | "default" | "long" | "full";
|
|
5
5
|
type DateTimeFormatValue = Parameters<Intl.DateTimeFormat["format"]>[0];
|
|
6
6
|
type NumberFormatValue = Parameters<Intl.NumberFormat["format"]>[0];
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use `Intl.DateTimeFormat` directly. This helper will be removed.
|
|
9
|
+
*/
|
|
7
10
|
declare function date(locales: Locales, value: string | DateTimeFormatValue, format?: Intl.DateTimeFormatOptions | DateTimeFormatSize): string;
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated Use `Intl.DateTimeFormat` directly. This helper will be removed.
|
|
13
|
+
*/
|
|
8
14
|
declare function time(locales: Locales, value: string | DateTimeFormatValue, format?: Intl.DateTimeFormatOptions | DateTimeFormatSize): string;
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Use `Intl.NumberFormat` directly. This helper will be removed.
|
|
17
|
+
*/
|
|
9
18
|
declare function number(locales: Locales, value: NumberFormatValue, format?: Intl.NumberFormatOptions): string;
|
|
10
19
|
type PluralOptions = {
|
|
11
20
|
[key: string]: Intl.LDMLPluralRule;
|
|
@@ -25,17 +34,17 @@ declare const formats_number: typeof number;
|
|
|
25
34
|
declare const formats_plural: typeof plural;
|
|
26
35
|
declare const formats_time: typeof time;
|
|
27
36
|
declare namespace formats {
|
|
28
|
-
export {
|
|
37
|
+
export { formats_date as date, formats_defaultLocale as defaultLocale, formats_number as number, formats_plural as plural, formats_time as time };
|
|
38
|
+
export type { formats_DateTimeFormatSize as DateTimeFormatSize, formats_DateTimeFormatValue as DateTimeFormatValue, formats_NumberFormatValue as NumberFormatValue, formats_PluralOptions as PluralOptions };
|
|
29
39
|
}
|
|
30
40
|
|
|
31
41
|
declare class EventEmitter<Events extends {
|
|
32
|
-
[name: string]: (...args: any[]) =>
|
|
42
|
+
[name: string]: (...args: any[]) => void;
|
|
33
43
|
}> {
|
|
34
44
|
private readonly _events;
|
|
35
|
-
on(event:
|
|
36
|
-
removeListener(event:
|
|
37
|
-
emit(event:
|
|
38
|
-
private _getListeners;
|
|
45
|
+
on<E extends keyof Events>(event: E, listener: Events[E]): () => void;
|
|
46
|
+
removeListener<E extends keyof Events>(event: E, listener: Events[E]): void;
|
|
47
|
+
emit<E extends keyof Events>(event: E, ...args: Parameters<Events[E]>): void;
|
|
39
48
|
}
|
|
40
49
|
|
|
41
50
|
type MessageOptions = {
|
|
@@ -149,11 +158,18 @@ declare class I18n extends EventEmitter<Events> {
|
|
|
149
158
|
* Alias for {@see I18n._}
|
|
150
159
|
*/
|
|
151
160
|
t: I18n["_"];
|
|
161
|
+
/**
|
|
162
|
+
* @deprecated Use `Intl.DateTimeFormat` directly. This helper will be removed.
|
|
163
|
+
*/
|
|
152
164
|
date(value?: string | DateTimeFormatValue, format?: Intl.DateTimeFormatOptions): string;
|
|
165
|
+
/**
|
|
166
|
+
* @deprecated Use `Intl.NumberFormat` directly. This helper will be removed.
|
|
167
|
+
*/
|
|
153
168
|
number(value: NumberFormatValue, format?: Intl.NumberFormatOptions): string;
|
|
154
169
|
}
|
|
155
170
|
declare function setupI18n(params?: I18nProps): I18n;
|
|
156
171
|
|
|
157
172
|
declare const i18n: I18n;
|
|
158
173
|
|
|
159
|
-
export {
|
|
174
|
+
export { I18n, formats, i18n, setupI18n };
|
|
175
|
+
export type { AllLocaleData, AllMessages, Locale, LocaleData, Locales, MessageDescriptor, MessageOptions, Messages };
|
package/dist/index.mjs
CHANGED
|
@@ -127,8 +127,7 @@ const OCTOTHORPE_PH = "%__lingui_octothorpe__%";
|
|
|
127
127
|
const getDefaultFormats = (locale, passedLocales, formats = {}) => {
|
|
128
128
|
const locales = passedLocales || locale;
|
|
129
129
|
const style = (format) => {
|
|
130
|
-
if (typeof format === "object")
|
|
131
|
-
return format;
|
|
130
|
+
if (typeof format === "object") return format;
|
|
132
131
|
return formats[format];
|
|
133
132
|
};
|
|
134
133
|
const replaceOctothorpe = (value, message) => {
|
|
@@ -162,8 +161,7 @@ function interpolate(translation, locale, locales) {
|
|
|
162
161
|
return (values = {}, formats) => {
|
|
163
162
|
const formatters = getDefaultFormats(locale, locales, formats);
|
|
164
163
|
const formatMessage = (tokens, replaceOctothorpe = false) => {
|
|
165
|
-
if (!Array.isArray(tokens))
|
|
166
|
-
return tokens;
|
|
164
|
+
if (!Array.isArray(tokens)) return tokens;
|
|
167
165
|
return tokens.reduce((message, token) => {
|
|
168
166
|
if (token === "#" && replaceOctothorpe) {
|
|
169
167
|
return message + OCTOTHORPE_PH;
|
|
@@ -202,76 +200,49 @@ function interpolate(translation, locale, locales) {
|
|
|
202
200
|
if (isString(result) && ESCAPE_SEQUENCE_REGEX.test(result)) {
|
|
203
201
|
return decodeEscapeSequences(result);
|
|
204
202
|
}
|
|
205
|
-
if (isString(result))
|
|
206
|
-
return result;
|
|
203
|
+
if (isString(result)) return result;
|
|
207
204
|
return result ? String(result) : "";
|
|
208
205
|
};
|
|
209
206
|
}
|
|
210
207
|
|
|
211
|
-
var __defProp$1 = Object.defineProperty;
|
|
212
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
213
|
-
var __publicField$1 = (obj, key, value) => {
|
|
214
|
-
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
215
|
-
return value;
|
|
216
|
-
};
|
|
217
208
|
class EventEmitter {
|
|
218
|
-
|
|
219
|
-
__publicField$1(this, "_events", {});
|
|
220
|
-
}
|
|
209
|
+
_events = {};
|
|
221
210
|
on(event, listener) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
this._events[event].push(listener);
|
|
211
|
+
this._events[event] ??= /* @__PURE__ */ new Set();
|
|
212
|
+
this._events[event].add(listener);
|
|
225
213
|
return () => this.removeListener(event, listener);
|
|
226
214
|
}
|
|
227
215
|
removeListener(event, listener) {
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
maybeListeners.splice(index, 1);
|
|
216
|
+
const listeners = this._events[event];
|
|
217
|
+
listeners?.delete(listener);
|
|
218
|
+
if (listeners?.size === 0) {
|
|
219
|
+
delete this._events[event];
|
|
220
|
+
}
|
|
234
221
|
}
|
|
235
222
|
emit(event, ...args) {
|
|
236
|
-
const
|
|
237
|
-
if (!
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
_getListeners(event) {
|
|
242
|
-
const maybeListeners = this._events[event];
|
|
243
|
-
return Array.isArray(maybeListeners) ? maybeListeners : false;
|
|
223
|
+
const listeners = this._events[event];
|
|
224
|
+
if (!listeners) return;
|
|
225
|
+
for (const listener of [...listeners]) {
|
|
226
|
+
listener.apply(this, args);
|
|
227
|
+
}
|
|
244
228
|
}
|
|
245
229
|
}
|
|
246
230
|
|
|
247
|
-
var __defProp = Object.defineProperty;
|
|
248
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
249
|
-
var __publicField = (obj, key, value) => {
|
|
250
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
251
|
-
return value;
|
|
252
|
-
};
|
|
253
231
|
class I18n extends EventEmitter {
|
|
232
|
+
_locale = "";
|
|
233
|
+
_locales;
|
|
234
|
+
_localeData = {};
|
|
235
|
+
_messages = {};
|
|
236
|
+
_missing;
|
|
237
|
+
_messageCompiler;
|
|
254
238
|
constructor(params) {
|
|
255
239
|
super();
|
|
256
|
-
__publicField(this, "_locale", "");
|
|
257
|
-
__publicField(this, "_locales");
|
|
258
|
-
__publicField(this, "_localeData", {});
|
|
259
|
-
__publicField(this, "_messages", {});
|
|
260
|
-
__publicField(this, "_missing");
|
|
261
|
-
__publicField(this, "_messageCompiler");
|
|
262
|
-
/**
|
|
263
|
-
* Alias for {@see I18n._}
|
|
264
|
-
*/
|
|
265
|
-
__publicField(this, "t", this._.bind(this));
|
|
266
240
|
if (process.env.NODE_ENV !== "production") {
|
|
267
241
|
this.setMessagesCompiler(compileMessage);
|
|
268
242
|
}
|
|
269
|
-
if (params.missing != null)
|
|
270
|
-
|
|
271
|
-
if (params.
|
|
272
|
-
this.load(params.messages);
|
|
273
|
-
if (params.localeData != null)
|
|
274
|
-
this.loadLocaleData(params.localeData);
|
|
243
|
+
if (params.missing != null) this._missing = params.missing;
|
|
244
|
+
if (params.messages != null) this.load(params.messages);
|
|
245
|
+
if (params.localeData != null) this.loadLocaleData(params.localeData);
|
|
275
246
|
if (typeof params.locale === "string" || params.locales) {
|
|
276
247
|
this.activate(params.locale ?? defaultLocale, params.locales);
|
|
277
248
|
}
|
|
@@ -410,17 +381,26 @@ Please compile your catalog first.
|
|
|
410
381
|
}
|
|
411
382
|
if (isString(translation) && ESCAPE_SEQUENCE_REGEX.test(translation))
|
|
412
383
|
return decodeEscapeSequences(translation);
|
|
413
|
-
if (isString(translation))
|
|
414
|
-
return translation;
|
|
384
|
+
if (isString(translation)) return translation;
|
|
415
385
|
return interpolate(
|
|
416
386
|
translation,
|
|
417
387
|
this._locale,
|
|
418
388
|
this._locales
|
|
419
389
|
)(values, options?.formats);
|
|
420
390
|
}
|
|
391
|
+
/**
|
|
392
|
+
* Alias for {@see I18n._}
|
|
393
|
+
*/
|
|
394
|
+
t = this._.bind(this);
|
|
395
|
+
/**
|
|
396
|
+
* @deprecated Use `Intl.DateTimeFormat` directly. This helper will be removed.
|
|
397
|
+
*/
|
|
421
398
|
date(value, format) {
|
|
422
399
|
return date(this._locales || this._locale, value, format);
|
|
423
400
|
}
|
|
401
|
+
/**
|
|
402
|
+
* @deprecated Use `Intl.NumberFormat` directly. This helper will be removed.
|
|
403
|
+
*/
|
|
424
404
|
number(value, format) {
|
|
425
405
|
return number(this._locales || this._locale, value, format);
|
|
426
406
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const t = function () {}
|
|
2
|
+
export const msg = function () {}
|
|
3
|
+
export const ph = function () {}
|
|
4
|
+
export const defineMessage = function () {}
|
|
5
|
+
export const plural = function () {}
|
|
6
|
+
export const select = function () {}
|
|
7
|
+
export const selectOrdinal = function () {}
|
|
8
|
+
|
|
9
|
+
throw new Error(
|
|
10
|
+
`The macro you imported from "@lingui/core/macro" is being executed outside the context of compilation. \n` +
|
|
11
|
+
`This indicates that you don't configured correctly one of the "babel-plugin-macros" / "@lingui/swc-plugin" / "babel-plugin-lingui-macro"`,
|
|
12
|
+
)
|
package/macro/index.cjs
ADDED
package/package.json
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-next.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"description": "I18n tools for javascript",
|
|
6
|
-
"
|
|
7
|
-
"module": "./dist/index.mjs",
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
6
|
+
"type": "module",
|
|
9
7
|
"author": {
|
|
10
8
|
"name": "Tomáš Ehrlich",
|
|
11
9
|
"email": "tomas.ehrlich@gmail.com"
|
|
@@ -22,7 +20,7 @@
|
|
|
22
20
|
],
|
|
23
21
|
"scripts": {
|
|
24
22
|
"build": "unbuild",
|
|
25
|
-
"
|
|
23
|
+
"check-types": "tsc --noEmit"
|
|
26
24
|
},
|
|
27
25
|
"homepage": "https://lingui.dev",
|
|
28
26
|
"repository": {
|
|
@@ -34,22 +32,14 @@
|
|
|
34
32
|
"url": "https://github.com/lingui/js-lingui/issues"
|
|
35
33
|
},
|
|
36
34
|
"engines": {
|
|
37
|
-
"node": ">=
|
|
35
|
+
"node": ">=22.19.0"
|
|
38
36
|
},
|
|
39
37
|
"exports": {
|
|
40
|
-
".":
|
|
41
|
-
"require": {
|
|
42
|
-
"types": "./dist/index.d.cts",
|
|
43
|
-
"default": "./dist/index.cjs"
|
|
44
|
-
},
|
|
45
|
-
"import": {
|
|
46
|
-
"types": "./dist/index.d.mts",
|
|
47
|
-
"default": "./dist/index.mjs"
|
|
48
|
-
}
|
|
49
|
-
},
|
|
38
|
+
".": "./dist/index.mjs",
|
|
50
39
|
"./macro": {
|
|
51
|
-
"
|
|
52
|
-
"
|
|
40
|
+
"browser": "./macro/browser.cjs",
|
|
41
|
+
"types": "./macro/index.d.cts",
|
|
42
|
+
"default": "./macro/index.cjs"
|
|
53
43
|
},
|
|
54
44
|
"./package.json": "./package.json"
|
|
55
45
|
},
|
|
@@ -57,28 +47,29 @@
|
|
|
57
47
|
"LICENSE",
|
|
58
48
|
"README.md",
|
|
59
49
|
"dist/",
|
|
60
|
-
"macro/
|
|
61
|
-
"macro/index.
|
|
50
|
+
"macro/browser.cjs",
|
|
51
|
+
"macro/index.d.cts",
|
|
52
|
+
"macro/index.cjs"
|
|
62
53
|
],
|
|
63
54
|
"dependencies": {
|
|
64
|
-
"@babel
|
|
65
|
-
"@lingui/message-utils": "
|
|
55
|
+
"@lingui/babel-plugin-lingui-macro": "6.0.0-next.0",
|
|
56
|
+
"@lingui/message-utils": "6.0.0-next.0"
|
|
66
57
|
},
|
|
67
58
|
"devDependencies": {
|
|
68
|
-
"@lingui/
|
|
69
|
-
"unbuild": "
|
|
59
|
+
"@lingui/test-utils": "3.0.3",
|
|
60
|
+
"unbuild": "3.6.1",
|
|
61
|
+
"vitest": "4.0.18"
|
|
70
62
|
},
|
|
71
63
|
"peerDependencies": {
|
|
72
|
-
"@lingui/babel-plugin-lingui-macro": "5.9.1",
|
|
73
64
|
"babel-plugin-macros": "2 || 3"
|
|
74
65
|
},
|
|
75
66
|
"peerDependenciesMeta": {
|
|
76
|
-
"@lingui/babel-plugin-lingui-macro": {
|
|
77
|
-
"optional": true
|
|
78
|
-
},
|
|
79
67
|
"babel-plugin-macros": {
|
|
80
68
|
"optional": true
|
|
81
69
|
}
|
|
82
70
|
},
|
|
83
|
-
"
|
|
71
|
+
"unbuild": {
|
|
72
|
+
"declaration": "node16"
|
|
73
|
+
},
|
|
74
|
+
"gitHead": "a9576050487a4f7dfbc88db20814d5a1bb861c8c"
|
|
84
75
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { CompiledMessage } from '@lingui/message-utils/compileMessage';
|
|
2
|
-
|
|
3
|
-
declare const defaultLocale = "en";
|
|
4
|
-
type DateTimeFormatSize = "short" | "default" | "long" | "full";
|
|
5
|
-
type DateTimeFormatValue = Parameters<Intl.DateTimeFormat["format"]>[0];
|
|
6
|
-
type NumberFormatValue = Parameters<Intl.NumberFormat["format"]>[0];
|
|
7
|
-
declare function date(locales: Locales, value: string | DateTimeFormatValue, format?: Intl.DateTimeFormatOptions | DateTimeFormatSize): string;
|
|
8
|
-
declare function time(locales: Locales, value: string | DateTimeFormatValue, format?: Intl.DateTimeFormatOptions | DateTimeFormatSize): string;
|
|
9
|
-
declare function number(locales: Locales, value: NumberFormatValue, format?: Intl.NumberFormatOptions): string;
|
|
10
|
-
type PluralOptions = {
|
|
11
|
-
[key: string]: Intl.LDMLPluralRule;
|
|
12
|
-
} & {
|
|
13
|
-
offset: number;
|
|
14
|
-
other: string;
|
|
15
|
-
};
|
|
16
|
-
declare function plural(locales: Locales, ordinal: boolean, value: number, { offset, ...rules }: PluralOptions): string;
|
|
17
|
-
|
|
18
|
-
type formats_DateTimeFormatSize = DateTimeFormatSize;
|
|
19
|
-
type formats_DateTimeFormatValue = DateTimeFormatValue;
|
|
20
|
-
type formats_NumberFormatValue = NumberFormatValue;
|
|
21
|
-
type formats_PluralOptions = PluralOptions;
|
|
22
|
-
declare const formats_date: typeof date;
|
|
23
|
-
declare const formats_defaultLocale: typeof defaultLocale;
|
|
24
|
-
declare const formats_number: typeof number;
|
|
25
|
-
declare const formats_plural: typeof plural;
|
|
26
|
-
declare const formats_time: typeof time;
|
|
27
|
-
declare namespace formats {
|
|
28
|
-
export { type formats_DateTimeFormatSize as DateTimeFormatSize, type formats_DateTimeFormatValue as DateTimeFormatValue, type formats_NumberFormatValue as NumberFormatValue, type formats_PluralOptions as PluralOptions, formats_date as date, formats_defaultLocale as defaultLocale, formats_number as number, formats_plural as plural, formats_time as time };
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
declare class EventEmitter<Events extends {
|
|
32
|
-
[name: string]: (...args: any[]) => any;
|
|
33
|
-
}> {
|
|
34
|
-
private readonly _events;
|
|
35
|
-
on(event: keyof Events, listener: Events[typeof event]): () => void;
|
|
36
|
-
removeListener(event: keyof Events, listener: Events[typeof event]): void;
|
|
37
|
-
emit(event: keyof Events, ...args: Parameters<Events[typeof event]>): void;
|
|
38
|
-
private _getListeners;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
type MessageOptions = {
|
|
42
|
-
message?: string;
|
|
43
|
-
formats?: Formats;
|
|
44
|
-
comment?: string;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
type Locale = string;
|
|
48
|
-
type Locales = Locale | Locale[];
|
|
49
|
-
type Formats = Record<string, Intl.DateTimeFormatOptions | Intl.NumberFormatOptions>;
|
|
50
|
-
type Values = Record<string, unknown>;
|
|
51
|
-
/**
|
|
52
|
-
* @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Deprecated in v4
|
|
53
|
-
*/
|
|
54
|
-
type LocaleData = {
|
|
55
|
-
plurals?: (n: number, ordinal?: boolean) => ReturnType<Intl.PluralRules["select"]>;
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Deprecated in v4
|
|
59
|
-
*/
|
|
60
|
-
type AllLocaleData = Record<Locale, LocaleData>;
|
|
61
|
-
type UncompiledMessage = string;
|
|
62
|
-
type Messages = Record<string, UncompiledMessage | CompiledMessage>;
|
|
63
|
-
type AllMessages = Record<Locale, Messages>;
|
|
64
|
-
type MessageDescriptor = {
|
|
65
|
-
id: string;
|
|
66
|
-
comment?: string;
|
|
67
|
-
message?: string;
|
|
68
|
-
values?: Record<string, unknown>;
|
|
69
|
-
};
|
|
70
|
-
type MissingMessageEvent = {
|
|
71
|
-
locale: Locale;
|
|
72
|
-
id: string;
|
|
73
|
-
};
|
|
74
|
-
type MissingHandler = string | ((locale: string, id: string) => string);
|
|
75
|
-
type I18nProps = {
|
|
76
|
-
locale?: Locale;
|
|
77
|
-
locales?: Locales;
|
|
78
|
-
messages?: AllMessages;
|
|
79
|
-
/**
|
|
80
|
-
* @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Deprecated in v4
|
|
81
|
-
*/
|
|
82
|
-
localeData?: AllLocaleData;
|
|
83
|
-
missing?: MissingHandler;
|
|
84
|
-
};
|
|
85
|
-
type Events = {
|
|
86
|
-
change: () => void;
|
|
87
|
-
missing: (event: MissingMessageEvent) => void;
|
|
88
|
-
};
|
|
89
|
-
type LoadAndActivateOptions = {
|
|
90
|
-
/** initial active locale */
|
|
91
|
-
locale: Locale;
|
|
92
|
-
/** list of alternative locales (BCP 47 language tags) which are used for number and date formatting */
|
|
93
|
-
locales?: Locales;
|
|
94
|
-
/** compiled message catalog */
|
|
95
|
-
messages: Messages;
|
|
96
|
-
};
|
|
97
|
-
type MessageCompiler = (message: string) => CompiledMessage;
|
|
98
|
-
declare class I18n extends EventEmitter<Events> {
|
|
99
|
-
private _locale;
|
|
100
|
-
private _locales?;
|
|
101
|
-
private _localeData;
|
|
102
|
-
private _messages;
|
|
103
|
-
private _missing?;
|
|
104
|
-
private _messageCompiler?;
|
|
105
|
-
constructor(params: I18nProps);
|
|
106
|
-
get locale(): string;
|
|
107
|
-
get locales(): Locales | undefined;
|
|
108
|
-
get messages(): Messages;
|
|
109
|
-
/**
|
|
110
|
-
* @deprecated this has no effect. Please remove this from the code. Deprecated in v4
|
|
111
|
-
*/
|
|
112
|
-
get localeData(): LocaleData;
|
|
113
|
-
private _loadLocaleData;
|
|
114
|
-
/**
|
|
115
|
-
* Registers a `MessageCompiler` to enable the use of uncompiled catalogs at runtime.
|
|
116
|
-
*
|
|
117
|
-
* In production builds, the `MessageCompiler` is typically excluded to reduce bundle size.
|
|
118
|
-
* By default, message catalogs should be precompiled during the build process. However,
|
|
119
|
-
* if you need to compile catalogs at runtime, you can use this method to set a message compiler.
|
|
120
|
-
*
|
|
121
|
-
* Example usage:
|
|
122
|
-
*
|
|
123
|
-
* ```ts
|
|
124
|
-
* import { compileMessage } from "@lingui/message-utils/compileMessage";
|
|
125
|
-
*
|
|
126
|
-
* i18n.setMessagesCompiler(compileMessage);
|
|
127
|
-
* ```
|
|
128
|
-
*/
|
|
129
|
-
setMessagesCompiler(compiler: MessageCompiler): this;
|
|
130
|
-
/**
|
|
131
|
-
* @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Deprecated in v4
|
|
132
|
-
*/
|
|
133
|
-
loadLocaleData(allLocaleData: AllLocaleData): void;
|
|
134
|
-
/**
|
|
135
|
-
* @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Deprecated in v4
|
|
136
|
-
*/
|
|
137
|
-
loadLocaleData(locale: Locale, localeData: LocaleData): void;
|
|
138
|
-
private _load;
|
|
139
|
-
load(allMessages: AllMessages): void;
|
|
140
|
-
load(locale: Locale, messages: Messages): void;
|
|
141
|
-
/**
|
|
142
|
-
* @param options {@link LoadAndActivateOptions}
|
|
143
|
-
*/
|
|
144
|
-
loadAndActivate({ locale, locales, messages }: LoadAndActivateOptions): void;
|
|
145
|
-
activate(locale: Locale, locales?: Locales): void;
|
|
146
|
-
_(descriptor: MessageDescriptor): string;
|
|
147
|
-
_(id: string, values?: Values, options?: MessageOptions): string;
|
|
148
|
-
/**
|
|
149
|
-
* Alias for {@see I18n._}
|
|
150
|
-
*/
|
|
151
|
-
t: I18n["_"];
|
|
152
|
-
date(value?: string | DateTimeFormatValue, format?: Intl.DateTimeFormatOptions): string;
|
|
153
|
-
number(value: NumberFormatValue, format?: Intl.NumberFormatOptions): string;
|
|
154
|
-
}
|
|
155
|
-
declare function setupI18n(params?: I18nProps): I18n;
|
|
156
|
-
|
|
157
|
-
declare const i18n: I18n;
|
|
158
|
-
|
|
159
|
-
export { type AllLocaleData, type AllMessages, I18n, type Locale, type LocaleData, type Locales, type MessageDescriptor, type MessageOptions, type Messages, formats, i18n, setupI18n };
|
package/macro/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require("@lingui/babel-plugin-lingui-macro/macro")
|
|
File without changes
|