From 6df5991a14bcfaab3ecc80f706d4b0facb253980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Sat, 17 Aug 2024 04:07:42 +0200 Subject: [PATCH 1/5] No default features --- CHANGELOG.md | 6 +++ book/src/install.md | 14 +++---- book/src/languages.md | 41 ++++++++++---------- book/src/leptos_fluent.md | 56 +++------------------------- examples/csr-minimal/Cargo.toml | 2 +- examples/ssr-hydrate-axum/Cargo.toml | 4 +- examples/system-gtk/Cargo.toml | 2 +- leptos-fluent/Cargo.toml | 2 +- 8 files changed, 41 insertions(+), 86 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31c583c9..0ec85fce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # CHANGELOG +## Unreleased - 0.2.0 + +### Breaking changes + +- The feature `json` is not enabled by default anymore. + ## 2024-08-17 - [0.1.17] ### New features diff --git a/book/src/install.md b/book/src/install.md index 0dfdd615..7b49abe8 100644 --- a/book/src/install.md +++ b/book/src/install.md @@ -19,20 +19,17 @@ fluent-templates = "0.10" ```toml [dependencies] -leptos-fluent = { version = "0.1", default-features = false } +leptos-fluent = "0.1" fluent-templates = { version = "0.10", default-features = false, features = [ "macros", "walkdir" ] } ``` -- Using `default-features = false` for `leptos-fluent` the `json` - default feature will not be enabled, so the `languages` parameter - of [`leptos_fluent!`] macro will not be available. -- Using `default-features = false` and `features = ["macros", "walkdir"]` - for `fluent-templates` ensures that the dependency tree is the minimal - possible because more dependencies are shared between `leptos-fluent` - and `fluent-templates`. +Using `default-features = false` and `features = ["macros", "walkdir"]` +for `fluent-templates` ensures that the dependency tree is the minimal +possible because more dependencies are shared between `leptos-fluent` +and `fluent-templates`. @@ -156,6 +153,5 @@ See the [GTK example](https://github.com/mondeja/leptos-fluent/tree/master/examp ``` [`fluent-templates`]: https://github.com/XAMPPRocky/fluent-templates -[`leptos_fluent!`]: https://mondeja.github.io/leptos-fluent/leptos_fluent.html [`cargo leptos`]: https://github.com/leptos-rs/cargo-leptos [`tracing`]: https://docs.rs/tracing/latest/tracing diff --git a/book/src/languages.md b/book/src/languages.md index 17a725cf..9d6e9c62 100644 --- a/book/src/languages.md +++ b/book/src/languages.md @@ -65,6 +65,24 @@ leptos_fluent! {{ ] ``` +### Languages file format + +In order to use a languages file, you must enable the feature for the file +format you want to use in the _Cargo.toml_ file: + +```toml +[dependencies] +leptos-fluent = { version = "*", features = ["json5"] } +``` + +Available features for languages file formats are: + +- `json`: JSON +- `yaml`: YAML +- `json5`: JSON5 + +### Languages file layout + The languages file must expose an array of arrays with the structure: ```json5 @@ -81,9 +99,9 @@ will be the same as in the file regardless of the alphabetical order of the names. ``` -The first in the languages file will used as the initial of the user when any -other initialization value is discovered. Use the same as the one configured -as `fallback_language` in `static_loader!`. +The first one in the languages file will used as the initial of the user when +no other initialization language is discovered. Use the same as the one +configured as `fallback_language` in `static_loader!`. ```rust static_loader! { @@ -110,22 +128,5 @@ pub fn App() -> impl IntoView { ] ``` -### File format - -By default, the `json` feature is enabled, which only allows to set the -languages file in JSON format. To use other formats, disable the feature -and enable another. - -```toml -[dependencies] -leptos-fluent = { version = "*", default-features = false, features = ["json5"] } -``` - -Available features for languages file formats are: - -- `json`: JSON (default) -- `yaml`: YAML -- `json5`: JSON5 - [ISO 639-1 code]: https://en.wikipedia.org/wiki/ISO_639-1 [`leptos_fluent!`]: https://mondeja.github.io/leptos-fluent/leptos_fluent.html diff --git a/book/src/leptos_fluent.md b/book/src/leptos_fluent.md index 59ffd635..3160ef04 100644 --- a/book/src/leptos_fluent.md +++ b/book/src/leptos_fluent.md @@ -179,6 +179,11 @@ leptos_fluent! {{ Path to a file containing the list of languages supported by the application. Must be relative to the _Cargo.toml_ file. +```admonish tip +In order to use this parameter a languages file feature must be enabled. +See [**4. Languages**](https://mondeja.github.io/leptos-fluent/languages.html) +``` + ```rust leptos_fluent! {{ locales: "./locales", @@ -188,56 +193,6 @@ leptos_fluent! {{ }} ``` -```admonish tip -See [**4. Languages**](https://mondeja.github.io/leptos-fluent/languages.html) -``` - -The languages file should contain an array of arrays where each inner array -contains a language identifier and a language name, respectively, at least. - -The language identifier should be a valid language tag, such as `en-US`, `en`, -`es-ES`, etc. By default, the languages file should be a JSON with a `.json` -extension because the `json` feature is enabled. For example: - -```json -[ - ["en-US", "English (United States)"], - ["es-ES", "Español (España)"] -] -``` - -Set `default-features = false` and enable the `yaml` or the `json5` feature -to use a YAML or JSON5 files. For example: - -```yaml -# locales/languages.yaml -- - en-US - - English (United States) -- - es-ES - - Español (España) -``` - -```json5 -// locales/languages.json5 -[ - ["en-US", "English (United States)"], - ["es-ES", "Español (España)"], -] -``` - -Define a third element in the inner array with the direction of the language, -to use it in the [`` attribute] (see [`sync_html_tag_dir`]). -For example: - -```json -[ - ["en-US", "English (United States)", "ltr"], - ["es-ES", "Español (España)", "auto"], - ["ar", "العربية", "rtl"], - ["it", "Italiano"] -] -``` - ### `check_translations` Check the translations at compile time. It is useful to ensure that all @@ -871,6 +826,5 @@ leptos_fluent! {{ [glob]: https://docs.rs/globwalk/latest/globwalk/fn.glob.html [URL parameter]: https://developer.mozilla.org/docs/Web/API/URLSearchParams [URL path]: https://developer.mozilla.org/docs/Web/API/URL/pathname -[`sync_html_tag_dir`]: #csr---sync_html_tag_dir [cookie]: https://developer.mozilla.org/docs/Web/HTTP/Cookies [Server function]: https://book.leptos.dev/server/25_server_functions.html diff --git a/examples/csr-minimal/Cargo.toml b/examples/csr-minimal/Cargo.toml index 1dc002f7..d5287076 100644 --- a/examples/csr-minimal/Cargo.toml +++ b/examples/csr-minimal/Cargo.toml @@ -10,7 +10,7 @@ path = "src/lib.rs" [dependencies] leptos = { version = "0.6", features = ["csr"] } -leptos-fluent = { path = "../../leptos-fluent", default-features = false } +leptos-fluent = { path = "../../leptos-fluent" } fluent-templates = { version = "0.10", default-features = false, features = [ "macros", "walkdir" diff --git a/examples/ssr-hydrate-axum/Cargo.toml b/examples/ssr-hydrate-axum/Cargo.toml index 07d3e913..0149a658 100644 --- a/examples/ssr-hydrate-axum/Cargo.toml +++ b/examples/ssr-hydrate-axum/Cargo.toml @@ -19,9 +19,7 @@ leptos = "0.6" leptos_meta = "0.6" leptos_axum = { version = "0.6", optional = true } leptos_router = "0.6" -leptos-fluent = { path = "../../leptos-fluent", features = [ - "yaml" -], default-features = false } +leptos-fluent = { path = "../../leptos-fluent", features = ["yaml"] } fluent-templates = { version = "0.10", default-features = false, features = [ "macros", "walkdir" diff --git a/examples/system-gtk/Cargo.toml b/examples/system-gtk/Cargo.toml index 052df965..d973c059 100644 --- a/examples/system-gtk/Cargo.toml +++ b/examples/system-gtk/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] leptos = { version = "0.6", features = ["csr"] } gtk = { version = "0.9", package = "gtk4" } -leptos-fluent = { path = "../../leptos-fluent", default-features = false, features = [ +leptos-fluent = { path = "../../leptos-fluent", features = [ "system", "tracing" ] } diff --git a/leptos-fluent/Cargo.toml b/leptos-fluent/Cargo.toml index ed61e68e..79a67504 100644 --- a/leptos-fluent/Cargo.toml +++ b/leptos-fluent/Cargo.toml @@ -30,7 +30,7 @@ directories = { version = "5", optional = true } tracing = { version = "0.1", optional = true } [features] -default = ["json"] +default = [] system = [ "dep:current_locale", "dep:directories", From 3f4e6f1a15c255707a17cc1d4603a2686be262e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Sat, 17 Aug 2024 04:09:46 +0200 Subject: [PATCH 2/5] Improve changelog entry --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ec85fce..4f41a2c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,9 @@ ### Breaking changes -- The feature `json` is not enabled by default anymore. +- The feature `json` is not enabled by default anymore. Now leptos-fluent + does not includes features by default, so you don't need to use + `default-features = false` in your `Cargo.toml` file. ## 2024-08-17 - [0.1.17] From cc2bac0953f87db97e9dc6f38303415a01a66e29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Sat, 17 Aug 2024 04:15:34 +0200 Subject: [PATCH 3/5] Fix error in example --- examples/csr-complete/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/csr-complete/Cargo.toml b/examples/csr-complete/Cargo.toml index 43e1e031..12b63771 100644 --- a/examples/csr-complete/Cargo.toml +++ b/examples/csr-complete/Cargo.toml @@ -10,7 +10,7 @@ path = "src/lib.rs" [dependencies] leptos = { version = "0.6", features = ["csr"] } -leptos-fluent = { path = "../../leptos-fluent" } +leptos-fluent = { path = "../../leptos-fluent", features = ["json"] } fluent-templates = { version = "0.10", default-features = false, features = [ "macros", "walkdir" From bd30bf78fa62738b84338ed0f09d91e82e825998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Sat, 17 Aug 2024 04:23:51 +0200 Subject: [PATCH 4/5] Fix test --- .../pass/compile_time_exprpath_target_predicate.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leptos-fluent-macros/tests/ui/leptos_fluent/pass/compile_time_exprpath_target_predicate.rs b/leptos-fluent-macros/tests/ui/leptos_fluent/pass/compile_time_exprpath_target_predicate.rs index 3e2ab2b6..30b4ef6b 100644 --- a/leptos-fluent-macros/tests/ui/leptos_fluent/pass/compile_time_exprpath_target_predicate.rs +++ b/leptos-fluent-macros/tests/ui/leptos_fluent/pass/compile_time_exprpath_target_predicate.rs @@ -15,7 +15,7 @@ pub fn App() -> impl IntoView { translations: [TRANSLATIONS], locales: "../../../../examples/csr-minimal/locales", #[cfg(all(not(target_os = "windows"), not(target_os = "macos")))] - languages: "../../../../examples/csr-complete/locales/languages.json", + cookie_name: "foo" }}; view! {

Foo

} From 79e4c86717a4ed3d1d24700e2d276af0971ae3a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Sat, 17 Aug 2024 04:29:27 +0200 Subject: [PATCH 5/5] Fix docs --- README.md | 2 +- book/src/install.md | 2 +- leptos-fluent/README.md | 2 +- leptos-fluent/src/lib.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c3b3a0fd..e27871d0 100644 --- a/README.md +++ b/README.md @@ -243,7 +243,7 @@ fn LanguageSelector() -> impl IntoView { - **Axum integration**: `axum` - **Nightly toolchain**: `nightly` - **Desktop applications**: `system` -- **JSON languages file**: `json` (enabled by default) +- **JSON languages file**: `json` - **YAML languages file**: `yaml` - **JSON5 languages file**: `json5` - **Tracing support**: `tracing` diff --git a/book/src/install.md b/book/src/install.md index 7b49abe8..37db99cc 100644 --- a/book/src/install.md +++ b/book/src/install.md @@ -82,7 +82,7 @@ See the [GTK example](https://github.com/mondeja/leptos-fluent/tree/master/examp - **Axum integration**: `axum` - **Nightly toolchain**: `nightly` - **Desktop applications**: `system` -- **JSON languages file**: `json` (enabled by default) +- **JSON languages file**: `json` - **YAML languages file**: `yaml` - **JSON5 languages file**: `json5` - **Tracing support**: `tracing` diff --git a/leptos-fluent/README.md b/leptos-fluent/README.md index c3b3a0fd..e27871d0 100644 --- a/leptos-fluent/README.md +++ b/leptos-fluent/README.md @@ -243,7 +243,7 @@ fn LanguageSelector() -> impl IntoView { - **Axum integration**: `axum` - **Nightly toolchain**: `nightly` - **Desktop applications**: `system` -- **JSON languages file**: `json` (enabled by default) +- **JSON languages file**: `json` - **YAML languages file**: `yaml` - **JSON5 languages file**: `json5` - **Tracing support**: `tracing` diff --git a/leptos-fluent/src/lib.rs b/leptos-fluent/src/lib.rs index f9360ddf..077441f8 100644 --- a/leptos-fluent/src/lib.rs +++ b/leptos-fluent/src/lib.rs @@ -241,7 +241,7 @@ //! - **Axum integration**: `axum` //! - **Nightly toolchain**: `nightly` //! - **Desktop applications**: `system` -//! - **JSON languages file**: `json` (enabled by default) +//! - **JSON languages file**: `json` //! - **YAML languages file**: `yaml` //! - **JSON5 languages file**: `json5` //! - **Tracing support**: `tracing`