@lingui/macro 3.12.0 → 3.13.2
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/constants.js +4 -2
- package/global.d.ts +20 -14
- package/index.d.ts +20 -16
- package/index.js +0 -1
- package/macroJs.js +11 -2
- package/macroJsx.js +10 -3
- package/package.json +4 -2
package/constants.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.EXTRACT_MARK = exports.COMMENT = exports.MESSAGE = exports.ID = void 0;
|
|
6
|
+
exports.CONTEXT = exports.EXTRACT_MARK = exports.COMMENT = exports.MESSAGE = exports.ID = void 0;
|
|
7
7
|
var ID = "id";
|
|
8
8
|
exports.ID = ID;
|
|
9
9
|
var MESSAGE = "message";
|
|
@@ -11,4 +11,6 @@ exports.MESSAGE = MESSAGE;
|
|
|
11
11
|
var COMMENT = "comment";
|
|
12
12
|
exports.COMMENT = COMMENT;
|
|
13
13
|
var EXTRACT_MARK = "i18n";
|
|
14
|
-
exports.EXTRACT_MARK = EXTRACT_MARK;
|
|
14
|
+
exports.EXTRACT_MARK = EXTRACT_MARK;
|
|
15
|
+
var CONTEXT = "context";
|
|
16
|
+
exports.CONTEXT = CONTEXT;
|
package/global.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-ignore
|
|
1
2
|
declare module "@lingui/macro" {
|
|
2
3
|
import type { MessageDescriptor, I18n } from "@lingui/core"
|
|
3
4
|
|
|
@@ -28,9 +29,9 @@ declare module "@lingui/macro" {
|
|
|
28
29
|
* });
|
|
29
30
|
* ```
|
|
30
31
|
*
|
|
31
|
-
* @param
|
|
32
|
+
* @param descriptor The message descriptor to translate
|
|
32
33
|
*/
|
|
33
|
-
export function t(
|
|
34
|
+
export function t(descriptor: MessageDescriptor): string
|
|
34
35
|
|
|
35
36
|
/**
|
|
36
37
|
* Translates a template string using the global I18n instance
|
|
@@ -47,7 +48,7 @@ declare module "@lingui/macro" {
|
|
|
47
48
|
): string
|
|
48
49
|
|
|
49
50
|
/**
|
|
50
|
-
* Translates a template string using a given I18n instance
|
|
51
|
+
* Translates a template string or message descriptor using a given I18n instance
|
|
51
52
|
*
|
|
52
53
|
* @example
|
|
53
54
|
* ```
|
|
@@ -59,12 +60,24 @@ declare module "@lingui/macro" {
|
|
|
59
60
|
* });
|
|
60
61
|
* const message = t(i18n)`Hello ${name}`;
|
|
61
62
|
* ```
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```
|
|
66
|
+
* import { t } from "@lingui/macro";
|
|
67
|
+
* import { I18n } from "@lingui/core";
|
|
68
|
+
* const i18n = new I18n({
|
|
69
|
+
* locale: "nl",
|
|
70
|
+
* messages: { "Hello {0}": "Hallo {0}" },
|
|
71
|
+
* });
|
|
72
|
+
* const message = t(i18n)({ message: `Hello ${name}` });
|
|
73
|
+
* ```
|
|
62
74
|
*/
|
|
63
75
|
export function t(
|
|
64
|
-
i18n: I18n
|
|
65
|
-
|
|
66
|
-
...placeholders: any[]
|
|
67
|
-
|
|
76
|
+
i18n: I18n
|
|
77
|
+
): {
|
|
78
|
+
(literals: TemplateStringsArray, ...placeholders: any[]): string
|
|
79
|
+
(descriptor: MessageDescriptor): string
|
|
80
|
+
}
|
|
68
81
|
|
|
69
82
|
export type UnderscoreDigit<T = string> = { [digit: string]: T }
|
|
70
83
|
export type ChoiceOptions<T = string> = {
|
|
@@ -146,13 +159,6 @@ declare module "@lingui/macro" {
|
|
|
146
159
|
choices: Record<string, string> & BasicType
|
|
147
160
|
): string
|
|
148
161
|
|
|
149
|
-
/**
|
|
150
|
-
* Defines multiple messages for extraction
|
|
151
|
-
*/
|
|
152
|
-
export function defineMessages<M extends Record<string, MessageDescriptor>>(
|
|
153
|
-
messages: M
|
|
154
|
-
): M
|
|
155
|
-
|
|
156
162
|
/**
|
|
157
163
|
* Define a message for later use
|
|
158
164
|
*
|
package/index.d.ts
CHANGED
|
@@ -34,9 +34,9 @@ export type ChoiceOptions<T = string> = {
|
|
|
34
34
|
* });
|
|
35
35
|
* ```
|
|
36
36
|
*
|
|
37
|
-
* @param
|
|
37
|
+
* @param descriptor The message descriptor to translate
|
|
38
38
|
*/
|
|
39
|
-
export function t(
|
|
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
|
-
|
|
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
|
|
@@ -136,15 +148,6 @@ export function selectOrdinal(
|
|
|
136
148
|
*/
|
|
137
149
|
export function select(value: string, choices: ChoiceOptions): string
|
|
138
150
|
|
|
139
|
-
/**
|
|
140
|
-
* Defines multiple messages for extraction
|
|
141
|
-
*
|
|
142
|
-
* @see {@link defineMessage} for more details
|
|
143
|
-
*/
|
|
144
|
-
export function defineMessages<M extends Record<string, MessageDescriptor>>(
|
|
145
|
-
messages: M
|
|
146
|
-
): M
|
|
147
|
-
|
|
148
151
|
/**
|
|
149
152
|
* Define a message for later use
|
|
150
153
|
*
|
|
@@ -168,6 +171,7 @@ export type TransProps = {
|
|
|
168
171
|
id?: string
|
|
169
172
|
comment?: string
|
|
170
173
|
values?: Record<string, unknown>
|
|
174
|
+
context?: string
|
|
171
175
|
component?: React.ComponentType<TransRenderProps>
|
|
172
176
|
render?: (props: TransRenderProps) => ReactElement<any, any> | null
|
|
173
177
|
}
|
package/index.js
CHANGED
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/macroJsx.js
CHANGED
|
@@ -81,7 +81,8 @@ var MacroJSX = /*#__PURE__*/function () {
|
|
|
81
81
|
var _this$stripMacroAttri = _this.stripMacroAttributes(path.node),
|
|
82
82
|
attributes = _this$stripMacroAttri.attributes,
|
|
83
83
|
id = _this$stripMacroAttri.id,
|
|
84
|
-
comment = _this$stripMacroAttri.comment
|
|
84
|
+
comment = _this$stripMacroAttri.comment,
|
|
85
|
+
context = _this$stripMacroAttri.context;
|
|
85
86
|
|
|
86
87
|
if (!id && !message) {
|
|
87
88
|
return;
|
|
@@ -103,6 +104,10 @@ var MacroJSX = /*#__PURE__*/function () {
|
|
|
103
104
|
if (comment) {
|
|
104
105
|
attributes.push(_this.types.jsxAttribute(_this.types.jsxIdentifier(_constants.COMMENT), _this.types.stringLiteral(comment)));
|
|
105
106
|
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (context) {
|
|
110
|
+
attributes.push(_this.types.jsxAttribute(_this.types.jsxIdentifier(_constants.CONTEXT), _this.types.stringLiteral(context)));
|
|
106
111
|
} // Parameters for variable substitution
|
|
107
112
|
|
|
108
113
|
|
|
@@ -147,7 +152,8 @@ var MacroJSX = /*#__PURE__*/function () {
|
|
|
147
152
|
var id = attributes.filter(_this.attrName([_constants.ID]))[0];
|
|
148
153
|
var message = attributes.filter(_this.attrName([_constants.MESSAGE]))[0];
|
|
149
154
|
var comment = attributes.filter(_this.attrName([_constants.COMMENT]))[0];
|
|
150
|
-
var
|
|
155
|
+
var context = attributes.filter(_this.attrName([_constants.CONTEXT]))[0];
|
|
156
|
+
var reserved = [_constants.ID, _constants.MESSAGE, _constants.COMMENT, _constants.CONTEXT];
|
|
151
157
|
|
|
152
158
|
if (_this.isI18nComponent(node)) {// no reserved prop names
|
|
153
159
|
} else if (_this.isChoiceComponent(node)) {
|
|
@@ -158,6 +164,7 @@ var MacroJSX = /*#__PURE__*/function () {
|
|
|
158
164
|
id: maybeNodeValue(id),
|
|
159
165
|
message: maybeNodeValue(message),
|
|
160
166
|
comment: maybeNodeValue(comment),
|
|
167
|
+
context: maybeNodeValue(context),
|
|
161
168
|
attributes: attributes.filter(_this.attrName(reserved, true))
|
|
162
169
|
};
|
|
163
170
|
});
|
|
@@ -225,7 +232,7 @@ var MacroJSX = /*#__PURE__*/function () {
|
|
|
225
232
|
(0, _defineProperty2.default)(this, "tokenizeChoiceComponent", function (node) {
|
|
226
233
|
var element = node.openingElement;
|
|
227
234
|
var format = element.name.name.toLowerCase();
|
|
228
|
-
var props = element.attributes.filter(_this.attrName([_constants.ID, _constants.COMMENT, _constants.MESSAGE, "key", // we remove <Trans /> react props that are not useful for translation
|
|
235
|
+
var props = element.attributes.filter(_this.attrName([_constants.ID, _constants.COMMENT, _constants.MESSAGE, _constants.CONTEXT, "key", // we remove <Trans /> react props that are not useful for translation
|
|
229
236
|
"render", "component", "components"], true));
|
|
230
237
|
var token = {
|
|
231
238
|
type: "arg",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/macro",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.13.2",
|
|
4
4
|
"description": "Macro for generating messages in ICU MessageFormat syntax",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": {
|
|
@@ -30,10 +30,12 @@
|
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@babel/runtime": "^7.11.2",
|
|
33
|
-
"@lingui/conf": "^3.
|
|
33
|
+
"@lingui/conf": "^3.13.2",
|
|
34
34
|
"ramda": "^0.27.1"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
+
"@lingui/core": "^3.13.0",
|
|
38
|
+
"@lingui/react": "^3.13.0",
|
|
37
39
|
"babel-plugin-macros": "2 || 3"
|
|
38
40
|
}
|
|
39
41
|
}
|