Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow comment prop on react Trans component #1718

Merged
merged 2 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/react/src/Trans.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type TransProps = {
values?: Record<string, unknown>
components?: { [key: string]: React.ElementType | any }
formats?: Record<string, unknown>
comment?: string
children?: React.ReactNode
} & TransRenderCallbackOrComponent

Expand Down
13 changes: 10 additions & 3 deletions website/docs/ref/react.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ Default rendering component can be set using `defaultComponent` prop in [`I18nPr
| Prop name | Type | Description |
|-------------| ----------------------------------------- |------------------------------------------------|
| `className` | string | Class name to be added to `<span>` element |
| `render` | Function(props) -> Element \| `null` | Custom render callback to render translation |
| `component` | Component \| `null` | Custom component to render translation |
| `render` | Function(props) -> Element \| `null` | Custom render callback to render translation |
| `component` | Component \| `null` | Custom component to render translation |
| `comment` | string | Comment picked up by extractor to provide translation context |

`className` is used only for built-in components (when *render* is string).

Expand Down Expand Up @@ -153,7 +154,7 @@ import { Trans } from "@lingui/macro"
```
:::

It's also possible to use `Trans` component directly without macros. In that case, `id` identifies the message being translated. `values` and `components` are arguments and components used for formatting translation:
It's also possible to use `Trans` component directly without macros. In that case, `id` identifies the message being translated. `values` and `components` are arguments and components used for formatting translation. `comment` helps add context for translators:

```jsx
<Trans id="my.message" message="Hello World"/>
Expand All @@ -164,6 +165,12 @@ It's also possible to use `Trans` component directly without macros. In that cas
values={{ name: 'Arthur' }}
/>

<Trans
id="hello.world"
message="Hello world"
comment="a message that says hi to the world"
/>

// number of tag corresponds to index in `components` prop
<Trans
id="link"
Expand Down