@lingui/macro 3.17.2 → 4.0.0-next.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/build/global.d.ts +2 -0
- package/build/index.d.ts +131 -42
- package/build/index.js +57 -49
- package/build/macroJs.js +127 -99
- package/build/macroJsx.js +136 -116
- package/build/utils.js +0 -11
- package/index.d.ts +297 -0
- package/package.json +19 -9
- package/CHANGELOG.md +0 -449
package/index.d.ts
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
+
import type { ReactElement, ReactNode, VFC, FC } from "react"
|
|
3
|
+
import type { I18n, MessageDescriptor } from "@lingui/core"
|
|
4
|
+
import type { TransRenderProps } from "@lingui/react"
|
|
5
|
+
|
|
6
|
+
export type ChoiceOptions = {
|
|
7
|
+
/** Offset of value when calculating plural forms */
|
|
8
|
+
offset?: number
|
|
9
|
+
zero?: string
|
|
10
|
+
one?: string
|
|
11
|
+
two?: string
|
|
12
|
+
few?: string
|
|
13
|
+
many?: string
|
|
14
|
+
|
|
15
|
+
/** Catch-all option */
|
|
16
|
+
other?: string
|
|
17
|
+
/** Exact match form, corresponds to =N rule */
|
|
18
|
+
[digit: `${number}`]: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type MacroMessageDescriptor = (
|
|
22
|
+
| {
|
|
23
|
+
id: string
|
|
24
|
+
message?: string
|
|
25
|
+
}
|
|
26
|
+
| {
|
|
27
|
+
id?: string
|
|
28
|
+
message: string
|
|
29
|
+
}
|
|
30
|
+
) & {
|
|
31
|
+
comment?: string
|
|
32
|
+
context?: string
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Translates a message descriptor
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```
|
|
40
|
+
* import { t } from "@lingui/macro";
|
|
41
|
+
* const message = t({
|
|
42
|
+
* id: "msg.hello",
|
|
43
|
+
* comment: "Greetings at the homepage",
|
|
44
|
+
* message: `Hello ${name}`,
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```
|
|
50
|
+
* import { t } from "@lingui/macro";
|
|
51
|
+
* const message = t({
|
|
52
|
+
* id: "msg.plural",
|
|
53
|
+
* message: plural(value, { one: "...", other: "..." }),
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @param descriptor The message descriptor to translate
|
|
58
|
+
*/
|
|
59
|
+
export function t(descriptor: MacroMessageDescriptor): string
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Translates a template string using the global I18n instance
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```
|
|
66
|
+
* import { t } from "@lingui/macro";
|
|
67
|
+
* const message = t`Hello ${name}`;
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export function t(
|
|
71
|
+
literals: TemplateStringsArray,
|
|
72
|
+
...placeholders: any[]
|
|
73
|
+
): string
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Translates a template string or message descriptor using a given I18n instance
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```
|
|
80
|
+
* import { t } from "@lingui/macro";
|
|
81
|
+
* import { I18n } from "@lingui/core";
|
|
82
|
+
* const i18n = new I18n({
|
|
83
|
+
* locale: "nl",
|
|
84
|
+
* messages: { "Hello {0}": "Hallo {0}" },
|
|
85
|
+
* });
|
|
86
|
+
* const message = t(i18n)`Hello ${name}`;
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```
|
|
91
|
+
* import { t } from "@lingui/macro";
|
|
92
|
+
* import { I18n } from "@lingui/core";
|
|
93
|
+
* const i18n = new I18n({
|
|
94
|
+
* locale: "nl",
|
|
95
|
+
* messages: { "Hello {0}": "Hallo {0}" },
|
|
96
|
+
* });
|
|
97
|
+
* const message = t(i18n)({ message: `Hello ${name}` });
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export function t(i18n: I18n): {
|
|
101
|
+
(literals: TemplateStringsArray, ...placeholders: any[]): string
|
|
102
|
+
(descriptor: MacroMessageDescriptor): string
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Pluralize a message
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```
|
|
110
|
+
* import { plural } from "@lingui/macro";
|
|
111
|
+
* const message = plural(count, {
|
|
112
|
+
* one: "# Book",
|
|
113
|
+
* other: "# Books",
|
|
114
|
+
* });
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* @param value Determines the plural form
|
|
118
|
+
* @param options Object with available plural forms
|
|
119
|
+
*/
|
|
120
|
+
export function plural(value: number | string, options: ChoiceOptions): string
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Pluralize a message using ordinal forms
|
|
124
|
+
*
|
|
125
|
+
* Similar to `plural` but instead of using cardinal plural forms,
|
|
126
|
+
* it uses ordinal forms.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```
|
|
130
|
+
* import { selectOrdinal } from "@lingui/macro";
|
|
131
|
+
* const message = selectOrdinal(count, {
|
|
132
|
+
* one: "#st",
|
|
133
|
+
* two: "#nd",
|
|
134
|
+
* few: "#rd",
|
|
135
|
+
* other: "#th",
|
|
136
|
+
* });
|
|
137
|
+
* ```
|
|
138
|
+
*
|
|
139
|
+
* @param value Determines the plural form
|
|
140
|
+
* @param options Object with available plural forms
|
|
141
|
+
*/
|
|
142
|
+
export function selectOrdinal(
|
|
143
|
+
value: number | string,
|
|
144
|
+
options: ChoiceOptions
|
|
145
|
+
): string
|
|
146
|
+
|
|
147
|
+
type SelectOptions = {
|
|
148
|
+
/** Catch-all option */
|
|
149
|
+
other: string
|
|
150
|
+
[matches: string]: string
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Selects a translation based on a value
|
|
155
|
+
*
|
|
156
|
+
* Select works like a switch statement. It will
|
|
157
|
+
* select one of the forms in `options` object which
|
|
158
|
+
* key matches exactly `value`.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```
|
|
162
|
+
* import { select } from "@lingui/macro";
|
|
163
|
+
* const message = select(gender, {
|
|
164
|
+
* male: "he",
|
|
165
|
+
* female: "she",
|
|
166
|
+
* other: "they",
|
|
167
|
+
* });
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* @param value The key of choices to use
|
|
171
|
+
* @param choices
|
|
172
|
+
*/
|
|
173
|
+
export function select(value: string, choices: SelectOptions): string
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Define a message for later use
|
|
177
|
+
*
|
|
178
|
+
* `defineMessage` can be used to add comments for translators,
|
|
179
|
+
* or to override the message ID.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```
|
|
183
|
+
* import { defineMessage } from "@lingui/macro";
|
|
184
|
+
* const message = defineMessage({
|
|
185
|
+
* comment: "Greetings on the welcome page",
|
|
186
|
+
* message: `Welcome, ${name}!`,
|
|
187
|
+
* });
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* @param descriptor The message descriptor
|
|
191
|
+
*/
|
|
192
|
+
export function defineMessage(
|
|
193
|
+
descriptor: MacroMessageDescriptor
|
|
194
|
+
): MessageDescriptor
|
|
195
|
+
|
|
196
|
+
type CommonProps = {
|
|
197
|
+
id?: string
|
|
198
|
+
comment?: string
|
|
199
|
+
context?: string
|
|
200
|
+
render?: (props: TransRenderProps) => ReactElement<any, any> | null
|
|
201
|
+
i18n?: I18n
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
type TransProps = {
|
|
205
|
+
children: ReactNode
|
|
206
|
+
} & CommonProps
|
|
207
|
+
|
|
208
|
+
type PluralChoiceProps = {
|
|
209
|
+
value: string | number
|
|
210
|
+
/** Offset of value when calculating plural forms */
|
|
211
|
+
offset?: number
|
|
212
|
+
zero?: ReactNode
|
|
213
|
+
one?: ReactNode
|
|
214
|
+
two?: ReactNode
|
|
215
|
+
few?: ReactNode
|
|
216
|
+
many?: ReactNode
|
|
217
|
+
|
|
218
|
+
/** Catch-all option */
|
|
219
|
+
other: ReactNode
|
|
220
|
+
/** Exact match form, corresponds to =N rule */
|
|
221
|
+
[digit: `_${number}`]: ReactNode
|
|
222
|
+
} & CommonProps
|
|
223
|
+
|
|
224
|
+
type SelectChoiceProps = {
|
|
225
|
+
value: string
|
|
226
|
+
/** Catch-all option */
|
|
227
|
+
other: ReactNode
|
|
228
|
+
[option: `_${string}`]: ReactNode
|
|
229
|
+
} & CommonProps
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Trans is the basic macro for static messages,
|
|
233
|
+
* messages with variables, but also for messages with inline markup
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```
|
|
237
|
+
* <Trans>Hello {username}. Read the <a href="/docs">docs</a>.</Trans>
|
|
238
|
+
* ```
|
|
239
|
+
* @example
|
|
240
|
+
* ```
|
|
241
|
+
* <Trans id="custom.id">Hello {username}.</Trans>
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
export const Trans: FC<TransProps>
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Props of Plural macro are transformed into plural format.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```
|
|
251
|
+
* import { Plural } from "@lingui/macro"
|
|
252
|
+
* <Plural value={numBooks} one="Book" other="Books" />
|
|
253
|
+
*
|
|
254
|
+
* // ↓ ↓ ↓ ↓ ↓ ↓
|
|
255
|
+
* import { Trans } from "@lingui/react"
|
|
256
|
+
* <Trans id="{numBooks, plural, one {Book} other {Books}}" values={{ numBooks }} />
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
export const Plural: VFC<PluralChoiceProps>
|
|
260
|
+
/**
|
|
261
|
+
* Props of SelectOrdinal macro are transformed into selectOrdinal format.
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```
|
|
265
|
+
* // count == 1 -> 1st
|
|
266
|
+
* // count == 2 -> 2nd
|
|
267
|
+
* // count == 3 -> 3rd
|
|
268
|
+
* // count == 4 -> 4th
|
|
269
|
+
* <SelectOrdinal
|
|
270
|
+
* value={count}
|
|
271
|
+
* one="#st"
|
|
272
|
+
* two="#nd"
|
|
273
|
+
* few="#rd"
|
|
274
|
+
* other="#th"
|
|
275
|
+
* />
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
export const SelectOrdinal: VFC<PluralChoiceProps>
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Props of Select macro are transformed into select format
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```
|
|
285
|
+
* // gender == "female" -> Her book
|
|
286
|
+
* // gender == "male" -> His book
|
|
287
|
+
* // gender == "non-binary" -> Their book
|
|
288
|
+
*
|
|
289
|
+
* <Select
|
|
290
|
+
* value={gender}
|
|
291
|
+
* _male="His book"
|
|
292
|
+
* _female="Her book"
|
|
293
|
+
* other="Their book"
|
|
294
|
+
* />
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
export const Select: VFC<SelectChoiceProps>
|
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lingui/macro",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-next.1",
|
|
4
4
|
"description": "Macro for generating messages in ICU MessageFormat syntax",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
|
+
"types": "./index.d.ts",
|
|
6
7
|
"author": {
|
|
7
8
|
"name": "Tomáš Ehrlich",
|
|
8
9
|
"email": "tomas.ehrlich@gmail.com"
|
|
9
10
|
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"test:tsd": "tsd"
|
|
13
|
+
},
|
|
10
14
|
"license": "MIT",
|
|
11
15
|
"keywords": [
|
|
12
16
|
"babel-plugin-macros"
|
|
@@ -19,26 +23,32 @@
|
|
|
19
23
|
"url": "https://github.com/lingui/js-lingui/issues"
|
|
20
24
|
},
|
|
21
25
|
"engines": {
|
|
22
|
-
"node": ">=
|
|
26
|
+
"node": ">=16.0.0"
|
|
23
27
|
},
|
|
24
28
|
"files": [
|
|
25
29
|
"LICENSE",
|
|
26
30
|
"README.md",
|
|
27
|
-
"build/"
|
|
31
|
+
"build/",
|
|
32
|
+
"index.d.ts"
|
|
28
33
|
],
|
|
29
34
|
"dependencies": {
|
|
30
35
|
"@babel/runtime": "^7.20.13",
|
|
31
36
|
"@babel/types": "^7.20.7",
|
|
32
|
-
"@lingui/
|
|
33
|
-
"
|
|
37
|
+
"@lingui/cli": "^4.0.0-next.1",
|
|
38
|
+
"@lingui/conf": "^4.0.0-next.1"
|
|
34
39
|
},
|
|
35
40
|
"peerDependencies": {
|
|
36
|
-
"@lingui/core": "
|
|
37
|
-
"@lingui/react": "
|
|
41
|
+
"@lingui/core": "4.0.0-next.1",
|
|
42
|
+
"@lingui/react": "4.0.0-next.1",
|
|
38
43
|
"babel-plugin-macros": "2 || 3"
|
|
39
44
|
},
|
|
40
45
|
"devDependencies": {
|
|
41
|
-
"@
|
|
46
|
+
"@babel/core": "7.20.12",
|
|
47
|
+
"@babel/parser": "7.20.15",
|
|
48
|
+
"@babel/traverse": "7.20.12",
|
|
49
|
+
"@types/babel-plugin-macros": "^2.8.5",
|
|
50
|
+
"prettier": "2.8.3",
|
|
51
|
+
"tsd": "^0.26.1"
|
|
42
52
|
},
|
|
43
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "27ee8e213ff6d0c7a0cd2b21c573d7f6da43fd85"
|
|
44
54
|
}
|