Skip to content

Commit de65fa6

Browse files
authored
feat(data-table-v2): add i18n support to batch actions (carbon-design-system#902)
1 parent 9fcfbff commit de65fa6

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

src/components/DataTable/TableBatchActions.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@ import PropTypes from 'prop-types';
33
import React from 'react';
44

55
const translationKeys = {
6+
'carbon.table.batch.cancel': 'Cancel',
67
'carbon.table.batch.items.selected': 'items selected',
78
'carbon.table.batch.item.selected': 'item selected',
89
};
910

10-
const translateWithId = id => translationKeys[id];
11+
const translateWithId = (id, state) => {
12+
if (id === 'carbon.table.batch.cancel') {
13+
return translationKeys[id];
14+
}
15+
return `${state.totalSelected} ${translationKeys[id]}`;
16+
};
1117

1218
const TableBatchActions = ({
1319
className,
@@ -31,13 +37,14 @@ const TableBatchActions = ({
3137
{children}
3238
<div className="bx--batch-summary">
3339
<p className="bx--batch-summary__para">
34-
<span>{totalSelected}</span>{' '}
35-
{totalSelected > 1
36-
? t('carbon.table.batch.items.selected')
37-
: t('carbon.table.batch.item.selected')}
40+
<span>
41+
{totalSelected > 1
42+
? t('carbon.table.batch.items.selected', { totalSelected })
43+
: t('carbon.table.batch.item.selected', { totalSelected })}
44+
</span>
3845
</p>
3946
<button className="bx--batch-summary__cancel" onClick={onCancel}>
40-
Cancel
47+
{t('carbon.table.batch.cancel')}
4148
</button>
4249
</div>
4350
</div>

src/components/DataTable/__tests__/__snapshots__/TableBatchActions-test.js.snap

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ exports[`DataTable.TableBatchActions should render 1`] = `
1818
className="bx--batch-summary__para"
1919
>
2020
<span>
21-
10
21+
10 items selected
2222
</span>
23-
24-
items selected
2523
</p>
2624
<button
2725
className="bx--batch-summary__cancel"
@@ -52,10 +50,8 @@ exports[`DataTable.TableBatchActions should render 2`] = `
5250
className="bx--batch-summary__para"
5351
>
5452
<span>
55-
10
53+
10 items selected
5654
</span>
57-
58-
items selected
5955
</p>
6056
<button
6157
className="bx--batch-summary__cancel"

0 commit comments

Comments
 (0)