@lingui/core 4.0.0-next.4 → 4.0.0-next.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const compile = require('@lingui/core/compile');
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";
@@ -169,7 +169,7 @@ class I18n extends EventEmitter {
169
169
  return this._messages[this._locale] ?? {};
170
170
  }
171
171
  /**
172
- * @deprecated this has no effect. Please remove this from the code. Introduced in v4
172
+ * @deprecated this has no effect. Please remove this from the code. Deprecated in v4
173
173
  */
174
174
  get localeData() {
175
175
  return this._localeData[this._locale] ?? {};
@@ -182,7 +182,7 @@ class I18n extends EventEmitter {
182
182
  }
183
183
  }
184
184
  /**
185
- * @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Introduced in v4
185
+ * @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Deprecated in v4
186
186
  */
187
187
  loadLocaleData(localeOrAllData, localeData) {
188
188
  if (localeData != null) {
@@ -259,7 +259,7 @@ class I18n extends EventEmitter {
259
259
  }
260
260
  let translation = this.messages[id] || message || id;
261
261
  if (process.env.NODE_ENV !== "production") {
262
- translation = isString(translation) ? compile.compileMessage(translation) : translation;
262
+ translation = isString(translation) ? compileMessage.compileMessage(translation) : translation;
263
263
  }
264
264
  if (isString(translation) && UNICODE_REGEX.test(translation))
265
265
  return JSON.parse(`"${translation}"`);
@@ -271,6 +271,11 @@ class I18n extends EventEmitter {
271
271
  this._locales
272
272
  )(values, formats);
273
273
  }
274
+ // Alternative to _. Can be used in node/js without macros
275
+ // uses message descriptor only
276
+ t(descriptor) {
277
+ return this._(descriptor);
278
+ }
274
279
  date(value, format) {
275
280
  return date(this._locales || this._locale, value, format);
276
281
  }
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
  }> {
@@ -12,29 +14,25 @@ type MessageOptions = {
12
14
  message?: string;
13
15
  formats?: Formats;
14
16
  };
17
+
15
18
  type Locale = string;
16
19
  type Locales = Locale | Locale[];
17
20
  type Formats = Record<string, Intl.DateTimeFormatOptions | Intl.NumberFormatOptions>;
18
21
  type Values = Record<string, unknown>;
19
22
  /**
20
- * @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Introduced in v4
23
+ * @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Deprecated in v4
21
24
  */
22
25
  type LocaleData = {
23
26
  plurals?: (n: number, ordinal?: boolean) => ReturnType<Intl.PluralRules["select"]>;
24
27
  };
25
28
  /**
26
- * @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Introduced in v4
29
+ * @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Deprecated in v4
27
30
  */
28
31
  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
32
  type Messages = Record<string, CompiledMessage>;
35
33
  type AllMessages = Record<Locale, Messages>;
36
34
  type MessageDescriptor = {
37
- id?: string;
35
+ id: string;
38
36
  comment?: string;
39
37
  message?: string;
40
38
  values?: Record<string, unknown>;
@@ -49,7 +47,7 @@ type setupI18nProps = {
49
47
  locales?: Locales;
50
48
  messages?: AllMessages;
51
49
  /**
52
- * @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Introduced in v4
50
+ * @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Deprecated in v4
53
51
  */
54
52
  localeData?: AllLocaleData;
55
53
  missing?: MissingHandler;
@@ -69,16 +67,16 @@ declare class I18n extends EventEmitter<Events> {
69
67
  get locales(): Locales;
70
68
  get messages(): Messages;
71
69
  /**
72
- * @deprecated this has no effect. Please remove this from the code. Introduced in v4
70
+ * @deprecated this has no effect. Please remove this from the code. Deprecated in v4
73
71
  */
74
72
  get localeData(): LocaleData;
75
73
  private _loadLocaleData;
76
74
  /**
77
- * @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Introduced in v4
75
+ * @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Deprecated in v4
78
76
  */
79
77
  loadLocaleData(allLocaleData: AllLocaleData): void;
80
78
  /**
81
- * @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Introduced in v4
79
+ * @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Deprecated in v4
82
80
  */
83
81
  loadLocaleData(locale: Locale, localeData: LocaleData): void;
84
82
  private _load;
@@ -95,6 +93,7 @@ declare class I18n extends EventEmitter<Events> {
95
93
  loadAndActivate(locales: Locale | Locales, messages: Messages, notify?: boolean): void;
96
94
  activate(locale: Locale, locales?: Locales): void;
97
95
  _(id: MessageDescriptor | string, values?: Values | undefined, { message, formats }?: MessageOptions | undefined): string;
96
+ t(descriptor: MessageDescriptor): string;
98
97
  date(value: string | Date, format?: Intl.DateTimeFormatOptions): string;
99
98
  number(value: number, format?: Intl.NumberFormatOptions): string;
100
99
  }
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { compileMessage } from '@lingui/core/compile';
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";
@@ -167,7 +167,7 @@ class I18n extends EventEmitter {
167
167
  return this._messages[this._locale] ?? {};
168
168
  }
169
169
  /**
170
- * @deprecated this has no effect. Please remove this from the code. Introduced in v4
170
+ * @deprecated this has no effect. Please remove this from the code. Deprecated in v4
171
171
  */
172
172
  get localeData() {
173
173
  return this._localeData[this._locale] ?? {};
@@ -180,7 +180,7 @@ class I18n extends EventEmitter {
180
180
  }
181
181
  }
182
182
  /**
183
- * @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Introduced in v4
183
+ * @deprecated Plurals automatically used from Intl.PluralRules you can safely remove this call. Deprecated in v4
184
184
  */
185
185
  loadLocaleData(localeOrAllData, localeData) {
186
186
  if (localeData != null) {
@@ -269,6 +269,11 @@ class I18n extends EventEmitter {
269
269
  this._locales
270
270
  )(values, formats);
271
271
  }
272
+ // Alternative to _. Can be used in node/js without macros
273
+ // uses message descriptor only
274
+ t(descriptor) {
275
+ return this._(descriptor);
276
+ }
272
277
  date(value, format) {
273
278
  return date(this._locales || this._locale, value, format);
274
279
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/core",
3
- "version": "4.0.0-next.4",
3
+ "version": "4.0.0-next.5",
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
- "@messageformat/parser": "^5.0.0"
56
+ "@lingui/message-utils": "^4.0.0-next.5"
68
57
  },
69
58
  "devDependencies": {
70
59
  "@lingui/jest-mocks": "^3.0.3",
71
60
  "unbuild": "^1.1.2"
72
61
  },
73
- "gitHead": "3b999e35d26e67dec7cf0591f794be782e11022c"
62
+ "gitHead": "bdbd6cf310cbcf09e1fe288f20ef530c28de481d"
74
63
  }
package/compile.js DELETED
@@ -1,5 +0,0 @@
1
- /**
2
- * This entry is for old runtimes which do not support `exports` field in package.json
3
- * https://github.com/facebook/metro/issues/670
4
- */
5
- module.exports = require("./dist/compile.cjs")
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
@@ -1,2 +0,0 @@
1
-
2
- export { }
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 };