Skip to content

Commit 4252bfa

Browse files
committed
feat: add translation support for sorting functionality in table component
1 parent d4c544c commit 4252bfa

File tree

6 files changed

+21
-4
lines changed

6 files changed

+21
-4
lines changed

packages/components/AGENTS.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,15 @@ Use the `condition && <Element />` pattern to render JSX elements only when a co
3535
```
3636

3737
Avoid using `hidden={condition}` unless the element should always be present in the DOM but visually hidden.
38+
39+
### Language texts
40+
41+
All UI texts must be stored in `src/locales/en.ts` and `src/locales/de.ts`.
42+
New translations get the prefix `kol-` and are referenced in the code using the
43+
`translate()` helper, e.g. `translate('kol-example')`.
44+
Call `translate()` once when the component instance is created (e.g. in a field
45+
initializer) and reuse the result. This prevents unnecessary work while still
46+
updating texts when the component is rerendered. Cache the value in a class
47+
property whose name starts with `translate` followed by the translation
48+
identifier, for example `translateSort` for `kol-sort` or `translateOrderBy`
49+
for `kol-order-by`.

packages/components/src/components/table-stateless/component.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ export class KolTableStateless implements TableStatelessAPI {
7171

7272
private checkboxRefs: HTMLInputElement[] = [];
7373

74+
private translateSort = translate('kol-sort');
75+
7476
@State()
7577
private tableDivElementHasScrollbar = false;
7678

@@ -840,6 +842,7 @@ export class KolTableStateless implements TableStatelessAPI {
840842
exportparts="icon"
841843
_icons={{ right: sortButtonIcon }}
842844
_label={cell.label}
845+
_ariaDescription={this.translateSort}
843846
_on={{
844847
onClick: (event: MouseEvent) => {
845848
if (typeof this.state._on?.onSort === 'function' && cell.key && cell.sortDirection) {

packages/components/src/components/table-stateless/test/__snapshots__/snapshot.spec.tsx.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ exports[`kol-table-stateless-wc should render with _label="Table with horizontal
7777
</kol-table-stateless-wc>
7878
`;
7979

80-
exports[`kol-table-stateless-wc should render with _label="Table with only horizontal headers" _minWidth="400px" _headerCells={"horizontal":[[{"key":"header1","label":"Header 1","textAlign":"left"},{"key":"header2","label":"Header 2","textAlign":"center"}]],"vertical":[]} _data=[{"header1":"Cell 1.1","header2":"Cell 1.2"},{"header1":"Cell 2.1","header2":"Cell 2.2"}] 1`] = `
80+
exports[`kol-table-stateless-wc should render with _label="Table with only horizontal headers" _minWidth="400px" _headerCells={"horizontal":[[{"key":"header1","label":"Header 1","textAlign":"left","sortDirection":"ASC"},{"key":"header2","label":"Header 2","textAlign":"center"}]],"vertical":[]} _data=[{"header1":"Cell 1.1","header2":"Cell 1.2"},{"header1":"Cell 2.1","header2":"Cell 2.2"}] 1`] = `
8181
<kol-table-stateless-wc>
8282
<div class="kol-table">
8383
<kol-table-settings-wc></kol-table-settings-wc>
@@ -89,8 +89,8 @@ exports[`kol-table-stateless-wc should render with _label="Table with only horiz
8989
</caption>
9090
<thead class="kol-table__head">
9191
<tr class="kol-table__head-row">
92-
<th aria-sort="none" class="kol-table__cell kol-table__cell--align-left kol-table__cell--header kol-table__cell--none" data-sort="sort-undefined" scope="col">
93-
Header 1
92+
<th aria-sort="ascending" class="kol-table__cell kol-table__cell--align-left kol-table__cell--ascending kol-table__cell--header" data-sort="sort-ASC" scope="col">
93+
<kol-button-wc _ariadescription="kol-sort" _label="Header 1" class="kol-table__sort-button" exportparts="icon"></kol-button-wc>
9494
</th>
9595
<th aria-sort="none" class="kol-table__cell kol-table__cell--align-center kol-table__cell--header kol-table__cell--none" data-sort="sort-undefined" scope="col">
9696
Header 2

packages/components/src/components/table-stateless/test/snapshot.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ executeSnapshotTests<TableStatelessProps>(
3939
_headerCells: {
4040
horizontal: [
4141
[
42-
{ key: 'header1', label: 'Header 1', textAlign: 'left' },
42+
{ key: 'header1', label: 'Header 1', textAlign: 'left', sortDirection: 'ASC' },
4343
{ key: 'header2', label: 'Header 2', textAlign: 'center' },
4444
],
4545
],

packages/components/src/locales/de.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export default {
5858
'delete-selection': 'Auswahl entfernen',
5959
'filename-text': 'Datei auswählen oder hier ablegen...',
6060
'data-browse-text': 'Datei auswählen',
61+
sort: 'sortieren',
6162
'pagination-position-top': 'oben',
6263
'pagination-position-bottom': 'unten',
6364
};

packages/components/src/locales/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export default {
5858
'delete-selection': 'Delete selection',
5959
'filename-text': 'Choose a file or drop it here...',
6060
'data-browse-text': 'Browse',
61+
sort: 'Sort',
6162
'pagination-position-top': 'top',
6263
'pagination-position-bottom': 'bottom',
6364
};

0 commit comments

Comments
 (0)