Skip to content

Commit 5d82d37

Browse files
feat(macro): deprecate custom i18n instance on t macro (#2059)
1 parent 6c4193a commit 5d82d37

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

packages/core/macro/index.d.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export function t(
7878
* import { I18n } from "@lingui/core";
7979
* const i18n = new I18n({
8080
* locale: "nl",
81-
* messages: { "Hello {0}": "Hallo {0}" },
81+
* messages: { "Hello {name}": "Hallo {name}" },
8282
* });
8383
* const message = t(i18n)`Hello ${name}`;
8484
* ```
@@ -89,10 +89,14 @@ export function t(
8989
* import { I18n } from "@lingui/core";
9090
* const i18n = new I18n({
9191
* locale: "nl",
92-
* messages: { "Hello {0}": "Hallo {0}" },
92+
* messages: { "Hello {name}": "Hallo {name}" },
9393
* });
9494
* const message = t(i18n)({ message: `Hello ${name}` });
9595
* ```
96+
*
97+
* @deprecated in v5, would be removed in v6.
98+
* Please use `` i18n._(msg`Hello ${name}`) `` instead
99+
*
96100
*/
97101
export function t(i18n: I18n): {
98102
(literals: TemplateStringsArray, ...placeholders: any[]): string
@@ -209,6 +213,6 @@ export function defineMessage(
209213

210214
/**
211215
* Define a message for later use
212-
* Alias for {@see defineMessage}
216+
* Alias for {@link defineMessage}
213217
*/
214218
export const msg: typeof defineMessage

website/docs/releases/migration-5.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,35 @@ You'll need to re-[`compile`](/ref/cli#compile) your messages in the new format.
233233
Read more about the motivation and discuss the changes in the related [issue](https://github.com/lingui/js-lingui/issues/2043).
234234
:::
235235

236-
## Deprecations and Removals
236+
## Deprecations
237237

238-
- Removed the deprecated `isTranslated` prop from the React `Trans` component.
239-
- Removed support of the module path strings in `LinguiConfig.extractors` property. Please pass extractor object directly.
238+
In this release, we've removed some deprecated features and introduced new deprecations.
239+
240+
### Previous Deprecations Removed
241+
242+
- Removed the `isTranslated` prop from the React `Trans` component.
243+
- Removed support of the module path strings in `LinguiConfig.extractors` property. Pass the extractor object directly.
244+
245+
### New Deprecations
246+
247+
Using a custom `i18n` instance with the `t` macro is deprecated. When you use the global `t` macro from `@lingui/macro`, it automatically relies on the global `i18n` instance. If you want to use a custom `i18n` instance, you could pass it directly to the `t` macro like this:
248+
249+
```js
250+
import { t } from "@lingui/macro";
251+
252+
t(i18n)`Hello!`;
253+
```
254+
255+
However, as Lingui evolved, an alternative approach was introduced using the `msg` macro:
256+
257+
```js
258+
import { msg } from "@lingui/macro";
259+
260+
i18n._(msg(`Hello!`));
261+
```
262+
263+
This approach is neither better nor worse; it simply offers a different way to achieve the same result.
264+
265+
From a technical perspective, supporting the custom `i18n` instance with the `t` macro required extra handling in Lingui's plugins for Babel, SWC, and ESLint, which introduced unnecessary complexity and maintenance overhead.
266+
267+
As a result, using a custom `i18n` instance with the `t` macro has been deprecated. To assist with the transition, an automatic migration is available using [GritQL](https://gist.github.com/timofei-iatsenko/876706f265d725d0aac01018f1812b39).

0 commit comments

Comments
 (0)