Skip to content

Commit a0f1de0

Browse files
authored
Support language script subtags (#384)
1 parent 8820b05 commit a0f1de0

18 files changed

Lines changed: 575 additions & 245 deletions

File tree

CHANGELOG.md

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,76 @@
11
# CHANGELOG
22

3-
## Unreleased
3+
## 2025-12-25 - [0.3.0]
4+
5+
### Breaking changes
6+
7+
#### Removed functions to simplify API
8+
9+
The next deprecated functions and methods have been removed:
10+
11+
- `i18n` (use `expect_context::<leptos_fluent::I18n>()` instead)
12+
- `use_i18n` (use `use_context::<leptos_fluent::I18n>()` instead)
13+
- `expect_i18n` (use `expect_context::<leptos_fluent::I18n>()` instead)
14+
- `Language.is_active` (use `i18n.language.get() == lang` instead)
15+
- `Language.activate` (use `i18n.language.set(lang)` instead)
16+
- `tr_impl` (use `i18n.tr(id)` method instead)
17+
- `tr_with_args_impl` (use `i18n.tr_with_args(id, args)` method instead)
18+
19+
#### Removed options including `localstorage` and `sessionstorage`
20+
21+
The deprecated options variants including the terms `localstorage` and
22+
`sessionstorage` in their names have been removed. Use the new variants
23+
including `local_storage` and `session_storage`.
24+
25+
#### `Language.id` is now a `&'static str`
26+
27+
The type of the `id` field of the `Language` struct has been changed
28+
from `unic_langid::LanguageIdentifier` to `&'static str`. This simplifies
29+
the usage of the `Language` struct and avoids unnecessary conversions.
30+
31+
#### `*_translations` options are executed on all targets
32+
33+
The options `check_translations` and `fill_translations` of `leptos_fluent!`
34+
were executed only on non-SSR targets by default. Now they are executed
35+
on all targets, so you need to disable them for SSR builds to prevent
36+
showing the same errors both in server and client builds.
37+
38+
Use the `#[cfg(not(feature = "ssr"))]` attribute to disable them for SSR builds:
39+
40+
```rust
41+
leptos_fluent! {
42+
#[cfg(not(feature = "ssr"))]
43+
check_translations: true,
44+
}
45+
```
46+
47+
#### Removed features `hydrate` and `disable-unicode-isolating-marks`
48+
49+
The features `hydrate` and `disable-unicode-isolating-marks` have been
50+
removed and will throw an error if used.
51+
52+
#### Changed type of `Language.id` field
53+
54+
The type of the `id` field of the `Language` struct has been changed
55+
from `pub id: &'static fluent_templates::LanguageIdentifier`, to
56+
`pub id: &'static str`.
57+
58+
Use `fluent_templates::LanguageIdentifier::from_str(language.id)`
59+
to convert it back.
60+
61+
### New features
62+
63+
#### Language entries with script subtags
64+
65+
Add support for language entries with script subtags, automatically detecting
66+
script, flag and display name when using `sr-Latn`, `sr-Cyrl`, `zh-Hans`,
67+
`zh-Hant`, and similar BCP 47 tags.
68+
69+
Includes the addition of an `Option<&'static str>` `script` field to `Language`.
70+
71+
### Bug fixes
72+
73+
- The URL does not set the language on hydration when using `initial_language_from_url_param`.
474

575
## 2025-12-12 - [0.2.21]
676

@@ -924,6 +994,7 @@ version to `0.1` during installation.
924994

925995
- Added all ISO-639-1 and ISO-639-2 languages.
926996

997+
[0.3.0]: https://github.com/mondeja/leptos-fluent/compare/v0.2.21...v0.3.0
927998
[0.2.21]: https://github.com/mondeja/leptos-fluent/compare/v0.2.20...v0.2.21
928999
[0.2.20]: https://github.com/mondeja/leptos-fluent/compare/v0.2.19...v0.2.20
9291000
[0.2.19]: https://github.com/mondeja/leptos-fluent/compare/v0.2.18...v0.2.19

Cargo.lock

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

README.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

book/src/basic-usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ path = "src/lib.rs"
116116

117117
[dependencies]
118118
leptos = { version = "0.8", features = ["csr"] }
119-
leptos-fluent = "0.2"
119+
leptos-fluent = "0.3"
120120
console_error_panic_hook = "0.1"
121121

122122
# Using cargo-leptos

book/src/install.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ For client side rendering apps just install **leptos-fluent**:
1010

1111
```toml
1212
[dependencies]
13-
leptos-fluent = "0.2"
13+
leptos-fluent = "0.3"
1414
```
1515

1616
## SSR
@@ -20,7 +20,7 @@ For server side rendering apps install **leptos-fluent** and enable
2020

2121
```toml
2222
[dependencies]
23-
leptos-fluent = "0.2"
23+
leptos-fluent = "0.3"
2424
axum = { version = "0.8", optional = true }
2525

2626
[features]
@@ -43,7 +43,7 @@ applications. You need to install **leptos-fluent**, and enable the
4343

4444
```toml
4545
[dependencies]
46-
leptos-fluent = { version = "0.2", features = ["system"] }
46+
leptos-fluent = { version = "0.3", features = ["system"] }
4747
```
4848

4949
## Features
@@ -66,7 +66,7 @@ feature:
6666

6767
```toml
6868
[dependencies]
69-
leptos-fluent = { version = "0.2", features = ["nightly"] }
69+
leptos-fluent = { version = "0.3", features = ["nightly"] }
7070
```
7171

7272
## Language files
@@ -79,7 +79,7 @@ enabled:
7979

8080
```toml
8181
[dependencies]
82-
leptos-fluent = { version = "0.2", features = ["json5"] }
82+
leptos-fluent = { version = "0.3", features = ["json5"] }
8383
```
8484

8585
<!-- markdownlint-enable MD013 -->
@@ -113,7 +113,7 @@ To enable [`tracing`] support, add the `tracing` feature to **leptos-fluent**:
113113

114114
```toml
115115
[dependencies]
116-
leptos-fluent = { version = "0.2", features = ["tracing"] }
116+
leptos-fluent = { version = "0.3", features = ["tracing"] }
117117
fluent-templates = "0.13"
118118
```
119119

@@ -123,6 +123,7 @@ fluent-templates = "0.13"
123123
## Compatibility
124124

125125
| **leptos-fluent** | **leptos** |
126-
| ----------------- | ---------- |
127-
| 0.2 | 0.7 / 0.8 |
128-
| 0.1 | 0.6 |
126+
| :---------------: | :--------: |
127+
| 0.3 | 0.8 |
128+
| 0.2 | 0.7 / 0.8 |
129+
| 0.1 | 0.6 |

book/src/languages.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,18 @@ compile time:
2020
```rust
2121
let LANGUAGES = [
2222
leptos_fluent::Language {
23-
id: unic_langid::langid!("en"),
23+
id: "en",
2424
name: "English",
2525
dir: leptos_fluent::WritingDirection::Ltr,
26+
flag: Some("🇬🇧"),
27+
script: None,
2628
},
2729
leptos_fluent::Language {
28-
id: unic_langid::langid!("es-ES"),
30+
id: "es-ES",
2931
name: "Español (España)",
3032
dir: leptos_fluent::WritingDirection::Ltr,
33+
flag: Some("🇪🇸"),
34+
script: None,
3135
},
3236
]
3337
```
@@ -82,7 +86,7 @@ format you want to use in the _Cargo.toml_ file:
8286

8387
```toml
8488
[dependencies]
85-
leptos-fluent = { version = "0.2", features = ["json5"] }
89+
leptos-fluent = { version = "0.3", features = ["json5"] }
8690
```
8791

8892
Available features for languages file formats are:

examples/csr-minimal/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn LanguageSelector() -> impl IntoView {
5050
</fieldset>
5151
<pre>
5252
{move_tr!(
53-
if {i18n.language.get().id.to_string() == *"en"} {
53+
if {i18n.language.get().id == "en"} {
5454
"language-is-english"
5555
} else {
5656
"language-is-spanish"

leptos-fluent-macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "leptos-fluent-macros"
33
description = "Macros for leptos-fluent"
44
edition.workspace = true
5-
version = "0.2.21"
5+
version = "0.3.0"
66
rust-version = "1.79.0"
77
license = "MIT"
88
documentation.workspace = true

0 commit comments

Comments
 (0)