@lingui/macro 3.12.0 → 3.12.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.
package/global.d.ts CHANGED
@@ -28,9 +28,9 @@ declare module "@lingui/macro" {
28
28
  * });
29
29
  * ```
30
30
  *
31
- * @param messageDescriptior The descriptor to translate
31
+ * @param descriptor The message descriptor to translate
32
32
  */
33
- export function t(messageDescriptior: MessageDescriptor): string
33
+ export function t(descriptor: MessageDescriptor): string
34
34
 
35
35
  /**
36
36
  * Translates a template string using the global I18n instance
@@ -47,7 +47,7 @@ declare module "@lingui/macro" {
47
47
  ): string
48
48
 
49
49
  /**
50
- * Translates a template string using a given I18n instance
50
+ * Translates a template string or message descriptor using a given I18n instance
51
51
  *
52
52
  * @example
53
53
  * ```
@@ -59,12 +59,24 @@ declare module "@lingui/macro" {
59
59
  * });
60
60
  * const message = t(i18n)`Hello ${name}`;
61
61
  * ```
62
+ *
63
+ * @example
64
+ * ```
65
+ * import { t } from "@lingui/macro";
66
+ * import { I18n } from "@lingui/core";
67
+ * const i18n = new I18n({
68
+ * locale: "nl",
69
+ * messages: { "Hello {0}": "Hallo {0}" },
70
+ * });
71
+ * const message = t(i18n)({ message: `Hello ${name}` });
72
+ * ```
62
73
  */
63
74
  export function t(
64
- i18n: I18n,
65
- literals: TemplateStringsArray,
66
- ...placeholders: any[]
67
- ): string
75
+ i18n: I18n
76
+ ): {
77
+ (literals: TemplateStringsArray, ...placeholders: any[]): string
78
+ (descriptor: MessageDescriptor): string
79
+ }
68
80
 
69
81
  export type UnderscoreDigit<T = string> = { [digit: string]: T }
70
82
  export type ChoiceOptions<T = string> = {
package/index.d.ts CHANGED
@@ -34,9 +34,9 @@ export type ChoiceOptions<T = string> = {
34
34
  * });
35
35
  * ```
36
36
  *
37
- * @param messageDescriptior The descriptor to translate
37
+ * @param descriptor The message descriptor to translate
38
38
  */
39
- export function t(messageDescriptior: MessageDescriptor): string
39
+ export function t(descriptor: MessageDescriptor): string
40
40
 
41
41
  /**
42
42
  * Translates a template string using the global I18n instance
@@ -53,7 +53,7 @@ export function t(
53
53
  ): string
54
54
 
55
55
  /**
56
- * Translates a template string using a given I18n instance
56
+ * Translates a template string or message descriptor using a given I18n instance
57
57
  *
58
58
  * @example
59
59
  * ```
@@ -65,12 +65,24 @@ export function t(
65
65
  * });
66
66
  * const message = t(i18n)`Hello ${name}`;
67
67
  * ```
68
+ *
69
+ * @example
70
+ * ```
71
+ * import { t } from "@lingui/macro";
72
+ * import { I18n } from "@lingui/core";
73
+ * const i18n = new I18n({
74
+ * locale: "nl",
75
+ * messages: { "Hello {0}": "Hallo {0}" },
76
+ * });
77
+ * const message = t(i18n)({ message: `Hello ${name}` });
78
+ * ```
68
79
  */
69
80
  export function t(
70
- i18n: I18n,
71
- literals: TemplateStringsArray,
72
- ...placeholders: any[]
73
- ): string
81
+ i18n: I18n
82
+ ): {
83
+ (literals: TemplateStringsArray, ...placeholders: any[]): string
84
+ (descriptor: MessageDescriptor): string
85
+ }
74
86
 
75
87
  /**
76
88
  * Pluralize a message
package/macroJs.js CHANGED
@@ -129,6 +129,15 @@ var MacroJs = /*#__PURE__*/function () {
129
129
  comment: _comment
130
130
  }, i18nInstance);
131
131
 
132
+ return false;
133
+ } // t(i18nInstance)(messageDescriptor) -> i18nInstance._(messageDescriptor)
134
+
135
+
136
+ if (_this.types.isCallExpression(path.node) && _this.types.isCallExpression(path.parentPath.node) && _this.types.isIdentifier(path.node.arguments[0]) && _this.isIdentifier(path.node.callee, "t")) {
137
+ var _i18nInstance = path.node.arguments[0];
138
+
139
+ _this.replaceTAsFunction(path.parentPath, _i18nInstance);
140
+
132
141
  return false;
133
142
  }
134
143
 
@@ -167,10 +176,10 @@ var MacroJs = /*#__PURE__*/function () {
167
176
 
168
177
  path.replaceWith(descriptor);
169
178
  });
170
- (0, _defineProperty2.default)(this, "replaceTAsFunction", function (path) {
179
+ (0, _defineProperty2.default)(this, "replaceTAsFunction", function (path, linguiInstance) {
171
180
  var descriptor = _this.processDescriptor(path.node.arguments[0]);
172
181
 
173
- var newNode = _this.types.callExpression(_this.types.memberExpression(_this.types.identifier(_this.i18nImportName), _this.types.identifier("_")), [descriptor]);
182
+ var newNode = _this.types.callExpression(_this.types.memberExpression(linguiInstance !== null && linguiInstance !== void 0 ? linguiInstance : _this.types.identifier(_this.i18nImportName), _this.types.identifier("_")), [descriptor]);
174
183
 
175
184
  path.replaceWith(newNode);
176
185
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingui/macro",
3
- "version": "3.12.0",
3
+ "version": "3.12.1",
4
4
  "description": "Macro for generating messages in ICU MessageFormat syntax",
5
5
  "main": "index.js",
6
6
  "author": {
@@ -30,7 +30,7 @@
30
30
  ],
31
31
  "dependencies": {
32
32
  "@babel/runtime": "^7.11.2",
33
- "@lingui/conf": "^3.12.0",
33
+ "@lingui/conf": "^3.12.1",
34
34
  "ramda": "^0.27.1"
35
35
  },
36
36
  "peerDependencies": {