Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Martin Chrástek <chrastek12@gmail.com>

Apply suggestions from code review

Co-authored-by: Andrii Bodnar <29282228+andrii-bodnar@users.noreply.github.com>

Update website/docs/ref/macro.md

Co-authored-by: Martin Chrástek <chrastek12@gmail.com>

Update website/docs/ref/macro.md

Co-authored-by: Martin Chrástek <chrastek12@gmail.com>

Update website/docs/ref/macro.md

Co-authored-by: Martin Chrástek <chrastek12@gmail.com>

Update website/docs/ref/macro.md

Co-authored-by: Martin Chrástek <chrastek12@gmail.com>

Update website/docs/ref/macro.md

Co-authored-by: Martin Chrástek <chrastek12@gmail.com>

Update website/docs/ref/macro.md

Co-authored-by: Martin Chrástek <chrastek12@gmail.com>

Update website/docs/ref/macro.md

Co-authored-by: Martin Chrástek <chrastek12@gmail.com>
  • Loading branch information
timofei-iatsenko and Martin005 committed Feb 21, 2023
1 parent 4ffaa90 commit c0249d3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/macro/test/jsx-trans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const cases: TestCase[] = [
`,
},
{
name: "Preserve custom ID (template expression)",
name: "Preserve custom ID (template expression)",
input: `
import { Trans } from '@lingui/macro';
<Trans id={\`msg.hello\`}>Hello World</Trans>;
Expand Down
11 changes: 8 additions & 3 deletions website/docs/ref/macro.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ const msg = /*i18n*/{
```jsx
<Trans>Attachment {name} saved</Trans>

// ↓ ↓ ↓ ↓ ↓ ↓,
// ↓ ↓ ↓ ↓ ↓ ↓

<Trans
id={"nwR43V"}
message="Attachment {name} saved"
Expand Down Expand Up @@ -623,7 +624,7 @@ type MessageDescriptor = {
defineMessage(message: MessageDescriptor)
```

Either `id` or `message` property is required. `id` is a custom message id. If it isn't set, the `message` is used for generating an id.
Either `id` or `message` property is required. `id` is a custom message ID. If it isn't set, the `message` (and `context` if provided) are used for generating an ID.

```js
import { defineMessage } from "@lingui/macro"
Expand Down Expand Up @@ -724,13 +725,14 @@ const message = /*i18n*/{

Each message in catalog is identified by **message ID**.

While macro use message to generate ID, it's possible to override it.
While macro uses message (and `context` property if provided) to generate ID, it's possible to override it.

```jsx
import { Trans } from "@lingui/macro";
<Trans id="message.attachment_saved">Attachment {name} saved.</Trans>;

// ↓ ↓ ↓ ↓ ↓ ↓

import { Trans } from "@lingui/react";
<Trans id="message.attachment_saved" message="Attachment {name} saved." />;
```
Expand All @@ -757,6 +759,7 @@ import { Trans } from "@lingui/macro";
<Trans>Refresh inbox</Trans>;

// ↓ ↓ ↓ ↓ ↓ ↓

import { Trans } from "@lingui/react";
<Trans id={"EsCV2T"} message="Refresh inbox" />;
```
Expand All @@ -769,6 +772,7 @@ import { Trans } from "@lingui/macro";
<Trans context="correctness">right</Trans>;

// ↓ ↓ ↓ ↓ ↓ ↓

import { Trans } from "@lingui/react";
<Trans id={"d1wX4r"} message="right" />;
<Trans id={"16eaSK"} message="right" />;
Expand Down Expand Up @@ -829,6 +833,7 @@ import { Plural } from "@lingui/macro";
<Plural value={numBooks} one="Book" other="Books" />;

// ↓ ↓ ↓ ↓ ↓ ↓

import { Trans } from "@lingui/react";
<Trans id={"is7n96"} message="{numBooks, plural, one {Book} other {Books}}" values={{ numBooks }} />;
```
Expand Down
7 changes: 4 additions & 3 deletions website/docs/tutorials/react-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ function render() {

You don't need anything special to use [`Trans`](/docs/ref/macro.md#trans) inside your app (except of wrapping the root component in [`I18nProvider`](/docs/ref/react.md#i18nprovider)).

## Choosing between Generated and Explicit ID
## Choosing between generated and explicit ID

The both approaches has they pros and cons. We recommend using generated ids as it scales and gives better developer experience.
Both approaches have their pros and cons. We recommend using generated IDs as it scales and gives better developer experience.

### Using ID generated from message

#### With [`Trans`](/docs/ref/macro.md#trans)

In the examples above, the content of [`Trans`](/docs/ref/macro.md#trans) is transformed into message in MessageFormat syntax. By default, this message is used for generating ID. Considering the example above, catalog would be fulfilled by these entries:
In the example code above, the content of [`Trans`](/docs/ref/macro.md#trans) is transformed into message in MessageFormat syntax. By default, this message is used for generating ID. Considering the example above, catalog would be fulfilled by these entries:

```js
const catalog = [
Expand Down Expand Up @@ -72,6 +72,7 @@ import { Trans } from "@lingui/macro";
<Trans context="correctness">right</Trans>;

// ↓ ↓ ↓ ↓ ↓ ↓

import { Trans } from "@lingui/react";
<Trans id={"d1wX4r"} message="right" />;
<Trans id={"16eaSK"} message="right" />;
Expand Down

0 comments on commit c0249d3

Please sign in to comment.