Skip to content

Commit ba43e3c

Browse files
committed
feat(Shortcut): add internationalization (i18n) support
Assisted by Claude Code
1 parent fcdf86f commit ba43e3c

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed
Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
1-
import { render } from '@testing-library/react';
1+
import { render, screen } from '@testing-library/react';
22
import Shortcut from './Shortcut';
33

44
describe('Shortcut component', () => {
55
it('should render correctly', () => {
66
expect(render(<Shortcut description='Shortcut description' keys={[ 'cmd', 'shift' ]} click/>)).toMatchSnapshot();
77
});
8+
9+
it('should render custom i18n labels for mouse actions', () => {
10+
render(
11+
<Shortcut
12+
keys={[]}
13+
hover hoverLabel="Survoler"
14+
click clickLabel="Cliquer"
15+
rightClick rightClickLabel="Clic droit"
16+
drag dragLabel="Glisser"
17+
dragAndDrop dragAndDropLabel="Glisser + Déposer"
18+
/>
19+
);
20+
21+
expect(screen.getByText('Survoler')).toBeInTheDocument();
22+
expect(screen.getByText('Cliquer')).toBeInTheDocument();
23+
expect(screen.getByText('Clic droit')).toBeInTheDocument();
24+
expect(screen.getByText('Glisser')).toBeInTheDocument();
25+
expect(screen.getByText('Glisser + Déposer')).toBeInTheDocument();
26+
});
827
});

packages/module/src/Shortcut/Shortcut.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ export interface ShortcutProps {
2121
drag?: boolean;
2222
/** Show drag and drop in the shortcut */
2323
dragAndDrop?: boolean;
24+
/** Custom label for the "Hover" mouse action. Defaults to "Hover" */
25+
hoverLabel?: string;
26+
/** Custom label for the "Click" mouse action. Defaults to "Click" */
27+
clickLabel?: string;
28+
/** Custom label for the "Right click" mouse action. Defaults to "Right click" */
29+
rightClickLabel?: string;
30+
/** Custom label for the "Drag" mouse action. Defaults to "Drag" */
31+
dragLabel?: string;
32+
/** Custom label for the "Drag + Drop" mouse action. Defaults to "Drag + Drop" */
33+
dragAndDropLabel?: string;
2434
/** Shortcut className */
2535
className?: string;
2636
/** Custom OUIA ID */
@@ -54,6 +64,11 @@ const Shortcut: FunctionComponent<ShortcutProps> = ({
5464
drag,
5565
rightClick,
5666
dragAndDrop,
67+
hoverLabel = 'Hover',
68+
clickLabel = 'Click',
69+
rightClickLabel = 'Right click',
70+
dragLabel = 'Drag',
71+
dragAndDropLabel = 'Drag + Drop',
5772
className,
5873
ouiaId = 'Shortcut',
5974
...props
@@ -62,7 +77,7 @@ const Shortcut: FunctionComponent<ShortcutProps> = ({
6277
const badges = [
6378
...(hover ? [
6479
<Label variant="outline" key="hover" data-test-id="hover">
65-
<MouseIcon /> Hover
80+
<MouseIcon />{` ${hoverLabel}`}
6681
</Label>
6782
] : []),
6883
...keys.map((key) => {
@@ -75,22 +90,22 @@ const Shortcut: FunctionComponent<ShortcutProps> = ({
7590
)}),
7691
...(click ? [
7792
<Label variant="outline" key="click" data-test-id="click">
78-
<MouseIcon /> Click
93+
<MouseIcon />{` ${clickLabel}`}
7994
</Label>
8095
] : []),
8196
...(rightClick ? [
8297
<Label variant="outline" key="right-click" data-test-id="right-click">
83-
<MouseIcon /> Right click
98+
<MouseIcon />{` ${rightClickLabel}`}
8499
</Label>
85100
] : []),
86101
...(drag ? [
87102
<Label variant="outline" key="drag" data-test-id="drag">
88-
<MouseIcon /> Drag
103+
<MouseIcon />{` ${dragLabel}`}
89104
</Label>
90105
] : []),
91106
...(dragAndDrop ? [
92107
<Label variant="outline" key="drag-and-drop" data-test-id="drag-and-drop">
93-
<MouseIcon /> Drag + Drop
108+
<MouseIcon />{` ${dragAndDropLabel}`}
94109
</Label>
95110
] : [])
96111
]

0 commit comments

Comments
 (0)