You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/guides/custom-formatter.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ description: Learn how to write a custom localization message formatter for your
5
5
6
6
# Custom Formatter
7
7
8
-
If your project requires a message catalog format that Lingui doesn't [natively support](/docs/ref/catalog-formats.md), you can create a custom formatter to handle it. A custom formatter allows you to define how extracted strings are formatted into a custom catalog format, providing flexibility for specialized workflows and integration with unique file structures.
8
+
If your project requires a message catalog format that Lingui doesn't [natively support](/ref/catalog-formats), you can create a custom formatter to handle it. A custom formatter allows you to define how extracted strings are formatted into a custom catalog format, providing flexibility for specialized workflows and integration with unique file structures.
Copy file name to clipboardExpand all lines: website/docs/guides/dynamic-loading-catalogs.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ description: Learn how to set up dynamic loading of message catalogs in Lingui t
7
7
8
8
Internationalization in modern applications requires careful handling of localized messages to avoid bloating the initial bundle size. By default, Lingui makes it easy to load all strings for a single active locale. For even greater efficiency, developers can selectively load only the messages needed on demand using [`i18n.load`](/ref/core#i18n.load), ensuring minimal resource usage.
9
9
10
-
The [`I18nProvider`](/docs/ref/react.md#i18nprovider) component doesn't make assumptions about your app's structure, giving you the freedom to load only the necessary messages for the currently selected language.
10
+
The [`I18nProvider`](/ref/react#i18nprovider) component doesn't make assumptions about your app's structure, giving you the freedom to load only the necessary messages for the currently selected language.
11
11
12
12
This guide shows how to set up dynamic loading of message catalogs, ensuring only the needed catalogs are loaded, which reduces bundle size and improves performance.
Copy file name to clipboardExpand all lines: website/docs/guides/explicit-vs-generated-ids.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -148,7 +148,7 @@ function render() {
148
148
}
149
149
```
150
150
151
-
In the example code above, the content of [`Trans`](/docs/ref/macro.mdx#trans) is transformed into a message in MessageFormat syntax. By default, this message is used for generating the ID. Considering the example above, the catalog would contain these entries:
151
+
In the example code above, the content of [`Trans`](/ref/macro#trans) is transformed into a message in MessageFormat syntax. By default, this message is used for generating the ID. Considering the example above, the catalog would contain these entries:
152
152
153
153
```js
154
154
constcatalog= [
@@ -202,7 +202,7 @@ The messages with IDs `msg.header` and `msg.hello` will be extracted with their
202
202
203
203
### With Core Macro
204
204
205
-
To use custom IDs in non-JSX macros, call the [`msg`](/docs/ref/macro.mdx#definemessage) function with a message descriptor object, passing the ID using the `id` property:
205
+
To use custom IDs in non-JSX macros, call the [`msg`](/ref/macro#definemessage) function with a message descriptor object, passing the ID using the `id` property:
Message `msg.greeting` will be extracted with default value `Hello World`.
214
214
215
-
For all other js macros ([`plural`](/docs/ref/macro.mdx#plural), [`select`](/docs/ref/macro.mdx#select), [`selectOrdinal`](/docs/ref/macro.mdx#selectordinal), use them inside [`msg`](/docs/ref/macro.mdx#definemessage) macro to pass ID (in this case, `'msg.caption'`).
215
+
For all other js macros ([`plural`](/ref/macro#plural), [`select`](/ref/macro#select), [`selectOrdinal`](/ref/macro#selectordinal), use them inside [`msg`](/ref/macro#definemessage) macro to pass ID (in this case, `'msg.caption'`).
Copy file name to clipboardExpand all lines: website/docs/guides/lazy-translations.md
+11-26Lines changed: 11 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,11 +5,11 @@ description: Lazy translations allow you to defer translation of a message until
5
5
6
6
# Lazy Translations
7
7
8
-
Lazy translation allows you to defer translation of a message until it's rendered, giving you flexibility in how and where you define messages in your code. With lazy translation, you can tag a string with the [`msg`](/docs/ref/macro.mdx#definemessage) macro to create a _message descriptor_ that can be saved, passed around as a variable, and rendered later.
8
+
Lazy translation allows you to defer translation of a message until it's rendered, giving you flexibility in how and where you define messages in your code. With lazy translation, you can tag a string with the [`msg`](/ref/macro#definemessage) macro to create a _message descriptor_ that can be saved, passed around as a variable, and rendered later.
9
9
10
10
## Usage Example
11
11
12
-
To render the message descriptor as a string-only translation, pass it to the [`i18n._()`](/docs/ref/core.md#i18n._) method:
12
+
To render the message descriptor as a string-only translation, pass it to the [`i18n._()`](/ref/core#i18n._) method:
13
13
14
14
```jsx
15
15
import { msg } from"@lingui/core/macro";
@@ -24,7 +24,7 @@ export function getTranslatedColorNames() {
24
24
25
25
## Usage in React
26
26
27
-
To render the message descriptor in a React component, pass its `id` to the [`Trans`](/docs/ref/react.md#trans) component as a value of the `id` prop:
27
+
To render the message descriptor in a React component, pass its `id` to the [`Trans`](/ref/react#trans) component as a value of the `id` prop:
28
28
29
29
```jsx
30
30
import { msg } from"@lingui/core/macro";
@@ -53,7 +53,7 @@ Please note that we import the `<Trans>` component from `@lingui/react` to use t
53
53
54
54
Sometimes you need to choose between different messages to display depending on the value of a variable. For example, imagine you have a numeric "status" code that comes from an API, and you need to display a message that represents the current status.
55
55
56
-
An easy way to do this is to create an object that maps the possible values of "status" to message descriptors (tagged with the [`msg`](/docs/ref/macro.mdx#definemessage) macro) and render them as needed with deferred translation:
56
+
An easy way to do this is to create an object that maps the possible values of "status" to message descriptors (tagged with the [`msg`](/ref/macro#definemessage) macro) and render them as needed with deferred translation:
In the following contrived example, we document how a welcome message will or will not be updated when locale changes. The documented behavior may not be intuitive at first, but it is expected, because of the way the `useMemo` dependencies work.
78
78
79
-
To avoid bugs with stale translations, use the `_` function returned from the [`useLingui`](/docs/ref/react.md#uselingui) hook: it is safe to use with memoization because its reference changes whenever the Lingui context updates.
80
-
81
-
:::tip
82
-
You can also use the `t` function from the [`useLingui`](/docs/ref/macro.mdx#uselingui) macro hook, which behaves the same way as `_` from the runtime [`useLingui`](/docs/ref/react.md#uselingui) counterpart.
83
-
:::
79
+
To avoid bugs with stale translations, use the `t` function returned from the [`useLingui`](/ref/macro#uselingui) macro: it is safe to use with memoization because its reference changes whenever the Lingui context updates.
84
80
85
81
Keep in mind that `useMemo` is primarily a performance optimization tool in React. Because of this, there might be no need to memoize your translations. Additionally, this issue is not present when using the `Trans` component, which we recommend using whenever possible.
86
82
87
83
```jsx
88
-
import { msg } from"@lingui/core/macro";
89
84
import { i18n } from"@lingui/core";
90
-
import { useLingui } from"@lingui/react";
85
+
import { msg } from"@lingui/core/macro";
86
+
import { useLingui } from"@lingui/react/macro";
91
87
92
88
constwelcomeMessage= msg`Welcome!`;
93
89
@@ -111,24 +107,13 @@ export function Welcome() {
111
107
return<div>{buggyWelcome}</div>;
112
108
}
113
109
114
-
// ✅ Good! `useMemo` has i18n context in the dependency
110
+
// ✅ Good! `useMemo` consumes the `t` function from the `useLingui` macro
115
111
exportfunctionWelcome() {
116
-
constlinguiCtx=useLingui();
117
-
118
-
constwelcome=useMemo(() => {
119
-
returnlinguiCtx.i18n._(welcomeMessage);
120
-
}, [linguiCtx]);
121
-
122
-
return<div>{welcome}</div>;
123
-
}
124
-
125
-
// 🤩 Better! `useMemo` consumes the `_` function from the Lingui context
Copy file name to clipboardExpand all lines: website/docs/guides/message-extraction.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ Message extraction is a key part of the internationalization process. It involve
9
9
10
10
In practice, developers define messages directly in the source code, and the extraction tool automatically collects these messages and stores them in a message catalog for translation.
11
11
12
-
Read more about the [`lingui extract`](/docs/ref/cli.md) command.
12
+
Read more about the [`lingui extract`](/ref/cli#extract) command.
13
13
14
14
## Supported Patterns
15
15
@@ -19,7 +19,7 @@ The extractor operates at a static level, meaning that it analyzes the source co
19
19
20
20
> Macros are JavaScript transformers that run at build time. The value returned by a macro is inlined into the bundle instead of the original function call.
21
21
22
-
The Lingui Macro provides powerful macros to transform JavaScript objects and JSX elements into [ICU MessageFormat](/docs/guides/message-format.md) messages at compile time.
22
+
The Lingui Macro provides powerful macros to transform JavaScript objects and JSX elements into [ICU MessageFormat](/guides/message-format) messages at compile time.
23
23
24
24
Extractor supports all macro usage, such as the following examples:
25
25
@@ -39,7 +39,7 @@ const jsx = <Trans>Hi, my name is {name}</Trans>;
39
39
40
40
The extractor matches the `t` and `Trans` macro calls and extracts the messages from them.
41
41
42
-
For more usage examples, see to the [Macros](/docs/ref/macro.mdx) reference.
42
+
For more usage examples, see to the [Macros](/ref/macro) reference.
43
43
44
44
### Non-Macros Usage
45
45
@@ -108,7 +108,7 @@ The extractor can locate source files in two ways: by specifying a glob pattern
108
108
109
109
By default, `lingui extract` uses a glob pattern to search for source files containing messages.
110
110
111
-
The pattern is defined in the [`catalogs`](/docs//ref/conf.md#catalogs) property of the Lingui configuration file in your project's root directory.
111
+
The pattern is defined in the [`catalogs`](/ref/conf#catalogs) property of the Lingui configuration file in your project's root directory.
112
112
113
113

114
114

@@ -208,10 +208,10 @@ The extractor supports TypeScript, Flow, and JavaScript (Stage 3) out of the box
208
208
209
209
If you are using some experimental features (Stage 0 - Stage 2) or frameworks with custom syntax such as Vue.js or Svelte, you may want to implement your own custom extractor.
210
210
211
-
Visit [Custom Extractor](/docs/guides/custom-extractor.md) to learn how to create a custom extractor.
211
+
Visit [Custom Extractor](/guides/custom-extractor) to learn how to create a custom extractor.
0 commit comments