Skip to content

Commit 26bd772

Browse files
committed
added i18n
closes #49
1 parent 2edda7d commit 26bd772

File tree

16 files changed

+227
-46
lines changed

16 files changed

+227
-46
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
- editable
3737
- generic
3838
- getter
39+
- i18n
3940
- paginated_rest_datasource
4041
- pagination
4142
- selectable

.idea/leptos-struct-table.iml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Changelog
22

3-
## [Unreleased]
3+
## [0.10.3] - 2024-08-05
44

55
### Features 🚀
66

7+
- Added i18n support via the `"i18n"` feature which uses `leptos-i18n`. See the `i18n` example for usage.
78
- Added row reader to `TableComponent`
9+
- Added `default_th_sorting_style` to make it easier to write a custom thead cell render component.
810

911
## [0.10.2] - 2024-06-07
1012

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "leptos-struct-table"
3-
version = "0.10.2"
3+
version = "0.10.3"
44
edition = "2021"
55
authors = ["Marc-Stefan Cassola"]
66
categories = ["gui", "web-programming"]
@@ -13,7 +13,7 @@ repository = "https://github.com/Synphonyte/leptos-struct-table"
1313

1414
[dependencies]
1515
leptos = { version = "0.6" }
16-
leptos-struct-table-macro = { version = "0.11.0" }
16+
leptos-struct-table-macro = { version = "0.11.1", path = "../leptos-struct-table-macro" }
1717
leptos-use = "0.10"
1818
rust_decimal = { version = "1.35", optional = true }
1919
chrono = { version = "0.4", optional = true }
@@ -29,6 +29,7 @@ chrono = ["dep:chrono"]
2929
uuid = ["dep:uuid"]
3030
rust_decimal = ["dep:rust_decimal"]
3131
time = ["dep:time"]
32+
i18n = ["leptos-struct-table-macro/i18n"]
3233

3334
[package.metadata."docs.rs"]
3435
all-features = true

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ See:
154154
## Classes Customization
155155

156156
Classes can be easily customized by using the `classes_provider` attribute on the struct.
157-
You can specify any type that implements the trait [`TableClassesProvider`]. Please see the documentation for that trait for more information.
157+
You can specify any type that implementats the trait [`TableClassesProvider`]. Please see the documentation for that trait for more information.
158158
You can also look at [`TailwindClassesPreset`] for an example how this can be implemented.
159159

160160
Example:
@@ -344,6 +344,14 @@ The following options are available. Check their docs for more details.
344344

345345
Please have a look at the [pagination example](https://github.com/Synphonyte/leptos-struct-table/tree/master/examples/pagination/src/main.rs) for more information on how to use pagination.
346346

347+
## I18n
348+
349+
To translate the column titles of the table using `leptos-i18n` you can enable the `"i18n"`
350+
feature. The field names of the struct are used as keys.
351+
352+
Please have a look at the
353+
[i18n example](https://github.com/Synphonyte/leptos-struct-table/tree/master/examples/i18n).
354+
347355
## Contribution
348356

349357
All contributions are welcome. Please open an issue or a pull request if you have any ideas or problems.
@@ -352,9 +360,9 @@ All contributions are welcome. Please open an issue or a pull request if you hav
352360

353361
## Leptos Compatibility
354362

355-
| Crate version | Compatible Leptos version |
356-
|---------------------|---------------------------|
357-
| <= 0.2 | 0.3 |
358-
| 0.3 | 0.4 |
359-
| 0.4, 0.5, 0.6 | 0.5 |
360-
| 0.7, 0.8, 0.9, 0.10 | 0.6 |
363+
| Crate version | Compatible Leptos version |
364+
|---------------|---------------------------|
365+
| <= 0.2 | 0.3 |
366+
| 0.3 | 0.4 |
367+
| 0.4, 0.5, 0.6 | 0.5 |
368+
| 0.7 0.11 | 0.6 |

examples/custom_renderers_svg/src/renderers.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,7 @@ pub fn SvgHeadCellRenderer<F>(
117117
where
118118
F: Fn(TableHeadEvent) + 'static,
119119
{
120-
let style = move || {
121-
let sort = match sort_direction.get() {
122-
ColumnSort::Ascending => "--sort-icon: '▲';",
123-
ColumnSort::Descending => "--sort-icon: '▼';",
124-
ColumnSort::None => "--sort-icon: '';",
125-
};
126-
127-
let priority = match sort_priority.get() {
128-
Some(priority) => format!("--sort-priority: '{}';", priority + 1),
129-
None => "--sort-priority: '';".to_string(),
130-
};
131-
132-
format!("{} {}", sort, &priority)
133-
};
120+
let style = default_th_sorting_style(sort_priority, sort_direction);
134121

135122
let transform = transform_from_index(index, 0);
136123

examples/i18n/Cargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "i18n"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
leptos = { version = "0.6", features = ["csr"] }
8+
leptos-struct-table = { path = "../..", features = ["chrono", "uuid", "time", "i18n"] }
9+
leptos_i18n = { version = "0.3", features = ["csr"] }
10+
chrono = { version = "0.4", features = [] }
11+
console_error_panic_hook = "0.1"
12+
time = { version = "0.3" }
13+
uuid = { version = "1.8", features = ["v4"] }
14+
console_log = "1"
15+
log = "0.4"
16+
17+
[dev-dependencies]
18+
wasm-bindgen = "0.2"
19+
wasm-bindgen-test = "0.3.0"
20+
web-sys = "0.3"
21+
22+
[package.metadata.leptos-i18n]
23+
default = "en"
24+
locales = ["en", "de"]

examples/i18n/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
A simple table example showing how to integrate leptos-i18n to translate the titles.
2+
3+
If you don't have it installed already, install [Trunk](https://trunkrs.dev/)
4+
as well as the wasm32-unknown-unknown target:
5+
6+
```bash
7+
cargo install trunk
8+
rustup target add wasm32-unknown-unknown
9+
```
10+
11+
Then, to run this example, execute in a terminal:
12+
13+
```bash
14+
trunk serve --open
15+
```

examples/i18n/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head></head>
4+
<body></body>
5+
</html>

examples/i18n/locales/de.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"id": "ID",
3+
"title": "Titel",
4+
"author": "Autor",
5+
"publish_date": "Veröffentlichungsdatum",
6+
"read_date": "Lesedatum",
7+
"description": "Beschreibung",
8+
"click_to_change_lang": "Klicken um Sprache zu ändern"
9+
}

0 commit comments

Comments
 (0)