Skip to content

Commit 32f8714

Browse files
committed
Add translation support for sorting in UI components
1 parent d4c544c commit 32f8714

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
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/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)