@lingui/macro 4.11.2 → 5.0.0-next.0

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.
Files changed (4) hide show
  1. package/README.md +1 -1
  2. package/index.d.ts +69 -289
  3. package/index.js +1 -0
  4. package/package.json +18 -38
package/README.md CHANGED
@@ -24,7 +24,7 @@ See the [reference][reference] documentation.
24
24
 
25
25
  ```jsx
26
26
  import { setupI18n } from "@lingui/core"
27
- import { t } from "@lingui/macro"
27
+ import { t } from "@lingui/core/macro"
28
28
 
29
29
  const i18n = setupI18n()
30
30
 
package/index.d.ts CHANGED
@@ -1,318 +1,98 @@
1
- // eslint-disable-next-line import/no-extraneous-dependencies
2
- import type { ReactNode, VFC, FC } from "react"
3
- import type { I18n, MessageDescriptor } from "@lingui/core"
4
- import type { TransRenderCallbackOrComponent } 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
- }
1
+ import {
2
+ t as _t,
3
+ plural as _plural,
4
+ defineMessage as _defineMessage,
5
+ msg as _msg,
6
+ select as _select,
7
+ selectOrdinal as _selectOrdinal,
8
+ SelectOptions as _SelectOptions,
9
+ ChoiceOptions as _ChoiceOptions,
10
+ MacroMessageDescriptor as _MacroMessageDescriptor,
11
+ } from "@lingui/core/macro"
12
+
13
+ import {
14
+ Trans as _Trans,
15
+ Plural as _Plural,
16
+ Select as _Select,
17
+ SelectOrdinal as _SelectOrdinal,
18
+ PluralChoiceProps as _PluralChoiceProps,
19
+ SelectChoiceProps as _SelectChoiceProps,
20
+ CommonProps as _CommonProps,
21
+ TransProps as _TransProps,
22
+ useLingui as _useLingui,
23
+ } from "@lingui/react/macro"
34
24
 
35
25
  /**
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
26
+ * @deprecated please import from `@lingui/core/macro` directly
58
27
  */
59
- export function t(descriptor: MacroMessageDescriptor): string
28
+ declare const t: typeof _t
60
29
 
61
30
  /**
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
- * ```
31
+ * @deprecated please import from `@lingui/core/macro` directly
69
32
  */
70
- export function t(
71
- literals: TemplateStringsArray,
72
- ...placeholders: any[]
73
- ): string
74
-
33
+ declare const msg: typeof _msg
75
34
  /**
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
- * ```
35
+ * @deprecated please import from `@lingui/core/macro` directly
99
36
  */
100
- export function t(i18n: I18n): {
101
- (literals: TemplateStringsArray, ...placeholders: any[]): string
102
- (descriptor: MacroMessageDescriptor): string
103
- }
104
-
37
+ declare const plural: typeof _plural
105
38
  /**
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
39
+ * @deprecated please import from `@lingui/core/macro` directly
119
40
  */
120
- export function plural(value: number | string, options: ChoiceOptions): string
121
-
41
+ declare const defineMessage: typeof _defineMessage
122
42
  /**
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
43
+ * @deprecated please import from `@lingui/core/macro` directly
141
44
  */
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
-
45
+ declare const select: typeof _select
153
46
  /**
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
47
+ * @deprecated please import from `@lingui/core/macro` directly
172
48
  */
173
- export function select(value: string, choices: SelectOptions): string
174
-
49
+ declare const selectOrdinal: typeof _selectOrdinal
175
50
  /**
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
51
+ * @deprecated please import from `@lingui/core/macro` directly
191
52
  */
192
- export function defineMessage(
193
- descriptor: MacroMessageDescriptor
194
- ): MessageDescriptor
195
-
53
+ declare const SelectOptions: _SelectOptions
196
54
  /**
197
- * Define a message for later use
198
- *
199
- * @example
200
- * ```
201
- * import { defineMessage, msg } from "@lingui/macro";
202
- * const message = defineMessage`Hello ${name}`;
203
- *
204
- * // or using shorter version
205
- * const message = msg`Hello ${name}`;
206
- * ```
55
+ * @deprecated please import from `@lingui/core/macro` directly
207
56
  */
208
- export function defineMessage(
209
- literals: TemplateStringsArray,
210
- ...placeholders: any[]
211
- ): MessageDescriptor
212
-
57
+ declare const ChoiceOptions: _ChoiceOptions
213
58
  /**
214
- * Define a message for later use
215
- * Alias for {@see defineMessage}
59
+ * @deprecated please import from `@lingui/core/macro` directly
216
60
  */
217
- export const msg: typeof defineMessage
218
-
219
- type CommonProps = TransRenderCallbackOrComponent & {
220
- id?: string
221
- comment?: string
222
- context?: string
223
- }
224
-
225
- type TransProps = {
226
- children: ReactNode
227
- } & CommonProps
228
-
229
- type PluralChoiceProps = {
230
- value: string | number
231
- /** Offset of value when calculating plural forms */
232
- offset?: number
233
- zero?: ReactNode
234
- one?: ReactNode
235
- two?: ReactNode
236
- few?: ReactNode
237
- many?: ReactNode
238
-
239
- /** Catch-all option */
240
- other: ReactNode
241
- /** Exact match form, corresponds to =N rule */
242
- [digit: `_${number}`]: ReactNode
243
- } & CommonProps
244
-
245
- type SelectChoiceProps = {
246
- value: string
247
- /** Catch-all option */
248
- other: ReactNode
249
- [option: `_${string}`]: ReactNode
250
- } & CommonProps
61
+ declare const MacroMessageDescriptor: _MacroMessageDescriptor
251
62
 
252
63
  /**
253
- * Trans is the basic macro for static messages,
254
- * messages with variables, but also for messages with inline markup
255
- *
256
- * @example
257
- * ```
258
- * <Trans>Hello {username}. Read the <a href="/docs">docs</a>.</Trans>
259
- * ```
260
- * @example
261
- * ```
262
- * <Trans id="custom.id">Hello {username}.</Trans>
263
- * ```
64
+ * @deprecated please import from `@lingui/react/macro` directly
264
65
  */
265
- export const Trans: FC<TransProps>
266
-
66
+ declare const Trans: typeof _Trans
267
67
  /**
268
- * Props of Plural macro are transformed into plural format.
269
- *
270
- * @example
271
- * ```
272
- * import { Plural } from "@lingui/macro"
273
- * <Plural value={numBooks} one="Book" other="Books" />
274
- *
275
- * // ↓ ↓ ↓ ↓ ↓ ↓
276
- * import { Trans } from "@lingui/react"
277
- * <Trans id="{numBooks, plural, one {Book} other {Books}}" values={{ numBooks }} />
278
- * ```
68
+ * @deprecated please import from `@lingui/react/macro` directly
279
69
  */
280
- export const Plural: VFC<PluralChoiceProps>
70
+ export const Plural: typeof _Plural
281
71
  /**
282
- * Props of SelectOrdinal macro are transformed into selectOrdinal format.
283
- *
284
- * @example
285
- * ```
286
- * // count == 1 -> 1st
287
- * // count == 2 -> 2nd
288
- * // count == 3 -> 3rd
289
- * // count == 4 -> 4th
290
- * <SelectOrdinal
291
- * value={count}
292
- * one="#st"
293
- * two="#nd"
294
- * few="#rd"
295
- * other="#th"
296
- * />
297
- * ```
72
+ * @deprecated please import from `@lingui/react/macro` directly
298
73
  */
299
- export const SelectOrdinal: VFC<PluralChoiceProps>
300
-
74
+ export const PluralChoiceProps: _PluralChoiceProps
75
+ /**
76
+ * @deprecated please import from `@lingui/react/macro` directly
77
+ */
78
+ export const SelectChoiceProps: _SelectChoiceProps
79
+ /**
80
+ * @deprecated please import from `@lingui/react/macro` directly
81
+ */
82
+ export const Select: typeof _Select
83
+ /**
84
+ * @deprecated please import from `@lingui/react/macro` directly
85
+ */
86
+ export const CommonProps: _CommonProps
87
+ /**
88
+ * @deprecated please import from `@lingui/react/macro` directly
89
+ */
90
+ export const SelectOrdinal: typeof _SelectOrdinal
91
+ /**
92
+ * @deprecated please import from `@lingui/react/macro` directly
93
+ */
94
+ export const TransProps: _TransProps
301
95
  /**
302
- * Props of Select macro are transformed into select format
303
- *
304
- * @example
305
- * ```
306
- * // gender == "female" -> Her book
307
- * // gender == "male" -> His book
308
- * // gender == "non-binary" -> Their book
309
- *
310
- * <Select
311
- * value={gender}
312
- * _male="His book"
313
- * _female="Her book"
314
- * other="Their book"
315
- * />
316
- * ```
96
+ * @deprecated please import from `@lingui/react/macro` directly
317
97
  */
318
- export const Select: VFC<SelectChoiceProps>
98
+ export const useLingui: typeof _useLingui
package/index.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require("@lingui/babel-plugin-lingui-macro/macro")
package/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
2
  "name": "@lingui/macro",
3
- "version": "4.11.2",
3
+ "version": "5.0.0-next.0",
4
4
  "description": "Macro for generating messages in ICU MessageFormat syntax",
5
- "main": "./dist/index.cjs",
6
- "module": "./dist/index.mjs",
5
+ "main": "./index.js",
7
6
  "types": "./index.d.ts",
8
7
  "sideEffects": false,
9
8
  "author": {
@@ -11,9 +10,7 @@
11
10
  "email": "tomas.ehrlich@gmail.com"
12
11
  },
13
12
  "scripts": {
14
- "test:tsd": "tsd",
15
- "build": "rimraf ./dist && unbuild",
16
- "stub": "unbuild --stub"
13
+ "test:tsd": "tsd"
17
14
  },
18
15
  "license": "MIT",
19
16
  "keywords": [
@@ -38,49 +35,32 @@
38
35
  },
39
36
  "exports": {
40
37
  ".": {
41
- "require": {
42
- "types": "./index.d.ts",
43
- "default": "./dist/index.cjs"
44
- },
45
- "import": {
46
- "types": "./index.d.ts",
47
- "default": "./dist/index.mjs"
48
- }
49
- },
50
- "./node": {
51
- "require": {
52
- "types": "./dist/index.d.ts"
53
- },
54
- "import": {
55
- "types": "./dist/index.d.ts"
56
- }
38
+ "types": "./index.d.ts",
39
+ "default": "./index.js"
57
40
  }
58
41
  },
59
42
  "files": [
60
43
  "LICENSE",
61
44
  "README.md",
62
45
  "dist/",
63
- "index.d.ts"
46
+ "index.d.ts",
47
+ "index.js"
64
48
  ],
65
49
  "dependencies": {
66
- "@babel/runtime": "^7.20.13",
67
- "@babel/types": "^7.20.7",
68
- "@lingui/conf": "4.11.2",
69
- "@lingui/core": "4.11.2",
70
- "@lingui/message-utils": "4.11.2"
50
+ "@lingui/core": "^5.0.0-next.0",
51
+ "@lingui/react": "^5.0.0-next.0"
71
52
  },
72
53
  "peerDependencies": {
73
- "@lingui/react": "^4.0.0",
54
+ "@lingui/babel-plugin-lingui-macro": "4.11.2",
74
55
  "babel-plugin-macros": "2 || 3"
75
56
  },
76
- "devDependencies": {
77
- "@babel/core": "7.20.12",
78
- "@babel/parser": "7.20.15",
79
- "@babel/traverse": "7.20.12",
80
- "@types/babel-plugin-macros": "^2.8.5",
81
- "prettier": "2.8.3",
82
- "tsd": "^0.26.1",
83
- "unbuild": "2.0.0"
57
+ "peerDependenciesMeta": {
58
+ "@lingui/babel-plugin-lingui-macro": {
59
+ "optional": true
60
+ },
61
+ "babel-plugin-macros": {
62
+ "optional": true
63
+ }
84
64
  },
85
- "gitHead": "17e0af54b0b9d9577db2cef1be680a6d871611e7"
65
+ "gitHead": "2192f8d54699a3846ff8fe6f3992697be2da68a8"
86
66
  }