@lingui/core 4.0.0-next.4 → 4.0.0-next.6
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 +8 -5
- package/dist/index.d.ts +17 -13
- package/dist/index.mjs +7 -4
- package/package.json +4 -15
- package/compile.js +0 -5
- package/dist/compile.cjs +0 -53
- package/dist/compile.d.ts +0 -2
- package/dist/compile.mjs +0 -51
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const compileMessage = require('@lingui/message-utils/compileMessage');
|
|
4
4
|
|
|
5
5
|
const isString = (s) => typeof s === "string";
|
|
6
6
|
const isFunction = (f) => typeof f === "function";
|
|
@@ -147,6 +147,10 @@ class EventEmitter {
|
|
|
147
147
|
class I18n extends EventEmitter {
|
|
148
148
|
constructor(params) {
|
|
149
149
|
super();
|
|
150
|
+
/**
|
|
151
|
+
* Alias for {@see I18n._}
|
|
152
|
+
*/
|
|
153
|
+
this.t = this._.bind(this);
|
|
150
154
|
this._messages = {};
|
|
151
155
|
this._localeData = {};
|
|
152
156
|
if (params.missing != null)
|
|
@@ -169,7 +173,7 @@ class I18n extends EventEmitter {
|
|
|
169
173
|
return this._messages[this._locale] ?? {};
|
|
170
174
|
}
|
|
171
175
|
/**
|
|
172
|
-
* @deprecated this has no effect. Please remove this from the code.
|
|
176
|
+
* @deprecated this has no effect. Please remove this from the code. Deprecated in v4
|
|
173
177
|
*/
|
|
174
178
|
get localeData() {
|
|
175
179
|
return this._localeData[this._locale] ?? {};
|
|
@@ -182,7 +186,7 @@ class I18n extends EventEmitter {
|
|
|
182
186
|
}
|
|
183
187
|
}
|
|
184
188
|
/**
|
|
185
|
-
* @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call.
|
|
189
|
+
* @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Deprecated in v4
|
|
186
190
|
*/
|
|
187
191
|
loadLocaleData(localeOrAllData, localeData) {
|
|
188
192
|
if (localeData != null) {
|
|
@@ -242,7 +246,6 @@ class I18n extends EventEmitter {
|
|
|
242
246
|
this._locales = locales;
|
|
243
247
|
this.emit("change");
|
|
244
248
|
}
|
|
245
|
-
// method for translation and formatting
|
|
246
249
|
_(id, values = {}, { message, formats } = {}) {
|
|
247
250
|
if (!isString(id)) {
|
|
248
251
|
values = id.values || values;
|
|
@@ -259,7 +262,7 @@ class I18n extends EventEmitter {
|
|
|
259
262
|
}
|
|
260
263
|
let translation = this.messages[id] || message || id;
|
|
261
264
|
if (process.env.NODE_ENV !== "production") {
|
|
262
|
-
translation = isString(translation) ?
|
|
265
|
+
translation = isString(translation) ? compileMessage.compileMessage(translation) : translation;
|
|
263
266
|
}
|
|
264
267
|
if (isString(translation) && UNICODE_REGEX.test(translation))
|
|
265
268
|
return JSON.parse(`"${translation}"`);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CompiledMessage } from '@lingui/message-utils/compileMessage';
|
|
2
|
+
|
|
1
3
|
declare class EventEmitter<Events extends {
|
|
2
4
|
[name: string]: (...args: any[]) => any;
|
|
3
5
|
}> {
|
|
@@ -11,30 +13,27 @@ declare class EventEmitter<Events extends {
|
|
|
11
13
|
type MessageOptions = {
|
|
12
14
|
message?: string;
|
|
13
15
|
formats?: Formats;
|
|
16
|
+
comment?: string;
|
|
14
17
|
};
|
|
18
|
+
|
|
15
19
|
type Locale = string;
|
|
16
20
|
type Locales = Locale | Locale[];
|
|
17
21
|
type Formats = Record<string, Intl.DateTimeFormatOptions | Intl.NumberFormatOptions>;
|
|
18
22
|
type Values = Record<string, unknown>;
|
|
19
23
|
/**
|
|
20
|
-
* @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call.
|
|
24
|
+
* @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Deprecated in v4
|
|
21
25
|
*/
|
|
22
26
|
type LocaleData = {
|
|
23
27
|
plurals?: (n: number, ordinal?: boolean) => ReturnType<Intl.PluralRules["select"]>;
|
|
24
28
|
};
|
|
25
29
|
/**
|
|
26
|
-
* @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call.
|
|
30
|
+
* @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Deprecated in v4
|
|
27
31
|
*/
|
|
28
32
|
type AllLocaleData = Record<Locale, LocaleData>;
|
|
29
|
-
type CompiledIcuChoices = Record<string, CompiledMessage> & {
|
|
30
|
-
offset: number;
|
|
31
|
-
};
|
|
32
|
-
type CompiledMessageToken = string | [name: string, type?: string, format?: null | string | CompiledIcuChoices];
|
|
33
|
-
type CompiledMessage = string | CompiledMessageToken[];
|
|
34
33
|
type Messages = Record<string, CompiledMessage>;
|
|
35
34
|
type AllMessages = Record<Locale, Messages>;
|
|
36
35
|
type MessageDescriptor = {
|
|
37
|
-
id
|
|
36
|
+
id: string;
|
|
38
37
|
comment?: string;
|
|
39
38
|
message?: string;
|
|
40
39
|
values?: Record<string, unknown>;
|
|
@@ -49,7 +48,7 @@ type setupI18nProps = {
|
|
|
49
48
|
locales?: Locales;
|
|
50
49
|
messages?: AllMessages;
|
|
51
50
|
/**
|
|
52
|
-
* @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call.
|
|
51
|
+
* @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Deprecated in v4
|
|
53
52
|
*/
|
|
54
53
|
localeData?: AllLocaleData;
|
|
55
54
|
missing?: MissingHandler;
|
|
@@ -69,16 +68,16 @@ declare class I18n extends EventEmitter<Events> {
|
|
|
69
68
|
get locales(): Locales;
|
|
70
69
|
get messages(): Messages;
|
|
71
70
|
/**
|
|
72
|
-
* @deprecated this has no effect. Please remove this from the code.
|
|
71
|
+
* @deprecated this has no effect. Please remove this from the code. Deprecated in v4
|
|
73
72
|
*/
|
|
74
73
|
get localeData(): LocaleData;
|
|
75
74
|
private _loadLocaleData;
|
|
76
75
|
/**
|
|
77
|
-
* @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call.
|
|
76
|
+
* @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Deprecated in v4
|
|
78
77
|
*/
|
|
79
78
|
loadLocaleData(allLocaleData: AllLocaleData): void;
|
|
80
79
|
/**
|
|
81
|
-
* @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call.
|
|
80
|
+
* @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Deprecated in v4
|
|
82
81
|
*/
|
|
83
82
|
loadLocaleData(locale: Locale, localeData: LocaleData): void;
|
|
84
83
|
private _load;
|
|
@@ -94,7 +93,12 @@ declare class I18n extends EventEmitter<Events> {
|
|
|
94
93
|
*/
|
|
95
94
|
loadAndActivate(locales: Locale | Locales, messages: Messages, notify?: boolean): void;
|
|
96
95
|
activate(locale: Locale, locales?: Locales): void;
|
|
97
|
-
_(
|
|
96
|
+
_(descriptor: MessageDescriptor): string;
|
|
97
|
+
_(id: string, values?: Values, options?: MessageOptions): string;
|
|
98
|
+
/**
|
|
99
|
+
* Alias for {@see I18n._}
|
|
100
|
+
*/
|
|
101
|
+
t: I18n["_"];
|
|
98
102
|
date(value: string | Date, format?: Intl.DateTimeFormatOptions): string;
|
|
99
103
|
number(value: number, format?: Intl.NumberFormatOptions): string;
|
|
100
104
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { compileMessage } from '@lingui/
|
|
1
|
+
import { compileMessage } from '@lingui/message-utils/compileMessage';
|
|
2
2
|
|
|
3
3
|
const isString = (s) => typeof s === "string";
|
|
4
4
|
const isFunction = (f) => typeof f === "function";
|
|
@@ -145,6 +145,10 @@ class EventEmitter {
|
|
|
145
145
|
class I18n extends EventEmitter {
|
|
146
146
|
constructor(params) {
|
|
147
147
|
super();
|
|
148
|
+
/**
|
|
149
|
+
* Alias for {@see I18n._}
|
|
150
|
+
*/
|
|
151
|
+
this.t = this._.bind(this);
|
|
148
152
|
this._messages = {};
|
|
149
153
|
this._localeData = {};
|
|
150
154
|
if (params.missing != null)
|
|
@@ -167,7 +171,7 @@ class I18n extends EventEmitter {
|
|
|
167
171
|
return this._messages[this._locale] ?? {};
|
|
168
172
|
}
|
|
169
173
|
/**
|
|
170
|
-
* @deprecated this has no effect. Please remove this from the code.
|
|
174
|
+
* @deprecated this has no effect. Please remove this from the code. Deprecated in v4
|
|
171
175
|
*/
|
|
172
176
|
get localeData() {
|
|
173
177
|
return this._localeData[this._locale] ?? {};
|
|
@@ -180,7 +184,7 @@ class I18n extends EventEmitter {
|
|
|
180
184
|
}
|
|
181
185
|
}
|
|
182
186
|
/**
|
|
183
|
-
* @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call.
|
|
187
|
+
* @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Deprecated in v4
|
|
184
188
|
*/
|
|
185
189
|
loadLocaleData(localeOrAllData, localeData) {
|
|
186
190
|
if (localeData != null) {
|
|
@@ -240,7 +244,6 @@ class I18n extends EventEmitter {
|
|
|
240
244
|
this._locales = locales;
|
|
241
245
|
this.emit("change");
|
|
242
246
|
}
|
|
243
|
-
// method for translation and formatting
|
|
244
247
|
_(id, values = {}, { message, formats } = {}) {
|
|
245
248
|
if (!isString(id)) {
|
|
246
249
|
values = id.values || values;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/core",
|
|
3
|
-
"version": "4.0.0-next.
|
|
3
|
+
"version": "4.0.0-next.6",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"description": "I18n tools for javascript",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -44,31 +44,20 @@
|
|
|
44
44
|
"default": "./dist/index.mjs"
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
|
-
"./compile": {
|
|
48
|
-
"require": {
|
|
49
|
-
"types": "./dist/compile.d.ts",
|
|
50
|
-
"default": "./dist/compile.cjs"
|
|
51
|
-
},
|
|
52
|
-
"import": {
|
|
53
|
-
"types": "./dist/compile.d.ts",
|
|
54
|
-
"default": "./dist/compile.mjs"
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
47
|
"./package.json": "./package.json"
|
|
58
48
|
},
|
|
59
49
|
"files": [
|
|
60
50
|
"LICENSE",
|
|
61
51
|
"README.md",
|
|
62
|
-
"dist/"
|
|
63
|
-
"compile.js"
|
|
52
|
+
"dist/"
|
|
64
53
|
],
|
|
65
54
|
"dependencies": {
|
|
66
55
|
"@babel/runtime": "^7.20.13",
|
|
67
|
-
"@
|
|
56
|
+
"@lingui/message-utils": "^4.0.0-next.6"
|
|
68
57
|
},
|
|
69
58
|
"devDependencies": {
|
|
70
59
|
"@lingui/jest-mocks": "^3.0.3",
|
|
71
60
|
"unbuild": "^1.1.2"
|
|
72
61
|
},
|
|
73
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "d4d9e149b2419d1796e14176d53703a7cff4b82c"
|
|
74
63
|
}
|
package/compile.js
DELETED
package/dist/compile.cjs
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const parser = require('@messageformat/parser');
|
|
4
|
-
|
|
5
|
-
function processTokens(tokens, mapText) {
|
|
6
|
-
if (!tokens.filter((token) => token.type !== "content").length) {
|
|
7
|
-
return tokens.map((token) => mapText(token.value)).join("");
|
|
8
|
-
}
|
|
9
|
-
return tokens.map((token) => {
|
|
10
|
-
if (token.type === "content") {
|
|
11
|
-
return mapText(token.value);
|
|
12
|
-
} else if (token.type === "octothorpe") {
|
|
13
|
-
return "#";
|
|
14
|
-
} else if (token.type === "argument") {
|
|
15
|
-
return [token.arg];
|
|
16
|
-
} else if (token.type === "function") {
|
|
17
|
-
const _param = token?.param?.[0];
|
|
18
|
-
if (_param) {
|
|
19
|
-
return [token.arg, token.key, _param.value.trim()];
|
|
20
|
-
} else {
|
|
21
|
-
return [token.arg, token.key];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
const offset = token.pluralOffset;
|
|
25
|
-
const formatProps = {};
|
|
26
|
-
token.cases.forEach((item) => {
|
|
27
|
-
formatProps[item.key.replace(/^=(.)+/, "$1")] = processTokens(
|
|
28
|
-
item.tokens,
|
|
29
|
-
mapText
|
|
30
|
-
);
|
|
31
|
-
});
|
|
32
|
-
return [
|
|
33
|
-
token.arg,
|
|
34
|
-
token.type,
|
|
35
|
-
{
|
|
36
|
-
offset,
|
|
37
|
-
...formatProps
|
|
38
|
-
}
|
|
39
|
-
];
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
function compileMessage(message, mapText = (v) => v) {
|
|
43
|
-
try {
|
|
44
|
-
return processTokens(parser.parse(message), mapText);
|
|
45
|
-
} catch (e) {
|
|
46
|
-
console.error(`${e.message}
|
|
47
|
-
|
|
48
|
-
Message: ${message}`);
|
|
49
|
-
return message;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
exports.compileMessage = compileMessage;
|
package/dist/compile.d.ts
DELETED
package/dist/compile.mjs
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { parse } from '@messageformat/parser';
|
|
2
|
-
|
|
3
|
-
function processTokens(tokens, mapText) {
|
|
4
|
-
if (!tokens.filter((token) => token.type !== "content").length) {
|
|
5
|
-
return tokens.map((token) => mapText(token.value)).join("");
|
|
6
|
-
}
|
|
7
|
-
return tokens.map((token) => {
|
|
8
|
-
if (token.type === "content") {
|
|
9
|
-
return mapText(token.value);
|
|
10
|
-
} else if (token.type === "octothorpe") {
|
|
11
|
-
return "#";
|
|
12
|
-
} else if (token.type === "argument") {
|
|
13
|
-
return [token.arg];
|
|
14
|
-
} else if (token.type === "function") {
|
|
15
|
-
const _param = token?.param?.[0];
|
|
16
|
-
if (_param) {
|
|
17
|
-
return [token.arg, token.key, _param.value.trim()];
|
|
18
|
-
} else {
|
|
19
|
-
return [token.arg, token.key];
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
const offset = token.pluralOffset;
|
|
23
|
-
const formatProps = {};
|
|
24
|
-
token.cases.forEach((item) => {
|
|
25
|
-
formatProps[item.key.replace(/^=(.)+/, "$1")] = processTokens(
|
|
26
|
-
item.tokens,
|
|
27
|
-
mapText
|
|
28
|
-
);
|
|
29
|
-
});
|
|
30
|
-
return [
|
|
31
|
-
token.arg,
|
|
32
|
-
token.type,
|
|
33
|
-
{
|
|
34
|
-
offset,
|
|
35
|
-
...formatProps
|
|
36
|
-
}
|
|
37
|
-
];
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
function compileMessage(message, mapText = (v) => v) {
|
|
41
|
-
try {
|
|
42
|
-
return processTokens(parse(message), mapText);
|
|
43
|
-
} catch (e) {
|
|
44
|
-
console.error(`${e.message}
|
|
45
|
-
|
|
46
|
-
Message: ${message}`);
|
|
47
|
-
return message;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export { compileMessage };
|