Skip to content

Commit 3477c32

Browse files
author
Christoffer Jahren
authored
feat: allow comment prop on react Trans component (#1718)
1 parent 53f6a7c commit 3477c32

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

packages/react/src/Trans.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export type TransProps = {
2727
values?: Record<string, unknown>
2828
components?: { [key: string]: React.ElementType | any }
2929
formats?: Record<string, unknown>
30+
comment?: string
3031
children?: React.ReactNode
3132
} & TransRenderCallbackOrComponent
3233

website/docs/ref/react.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ Default rendering component can be set using `defaultComponent` prop in [`I18nPr
1818
| Prop name | Type | Description |
1919
|-------------| ----------------------------------------- |------------------------------------------------|
2020
| `className` | string | Class name to be added to `<span>` element |
21-
| `render` | Function(props) -> Element \| `null` | Custom render callback to render translation |
22-
| `component` | Component \| `null` | Custom component to render translation |
21+
| `render` | Function(props) -> Element \| `null` | Custom render callback to render translation |
22+
| `component` | Component \| `null` | Custom component to render translation |
23+
| `comment` | string | Comment picked up by extractor to provide translation context |
2324

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

@@ -153,7 +154,7 @@ import { Trans } from "@lingui/macro"
153154
```
154155
:::
155156

156-
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:
157+
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:
157158

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

168+
<Trans
169+
id="hello.world"
170+
message="Hello world"
171+
comment="a message that says hi to the world"
172+
/>
173+
167174
// number of tag corresponds to index in `components` prop
168175
<Trans
169176
id="link"

0 commit comments

Comments
 (0)