From 8e863c9b03b42391d094ef0fad6660e5f7e96f0a Mon Sep 17 00:00:00 2001 From: MXWXZ Date: Fri, 22 Nov 2024 11:30:09 +0800 Subject: [PATCH] v0.4.10 --- CHANGELOG.md | 4 ++++ README.md | 2 +- actix-cloud/Cargo.toml | 2 +- actix-cloud/src/i18n.rs | 6 +++--- examples/i18n/src/main.rs | 2 +- examples/response/src/main.rs | 2 +- 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13baa51..0da7770 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 0.4.10 +## Changes +1. `Locale::new` support `Into` instead of `String`. + # 0.4.9 ## New 1. New feature `serde` to add `Serialize`, `Deserialize` for supported structs. diff --git a/README.md b/README.md index 45e0fc0..82887a3 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ We use `rust-i18n-support` from [rust-i18n](https://crates.io/crates/rust-i18n) Load locale: ``` -let locale = Locale::new(String::from("en-US")).add_locale(i18n!("locale")); +let locale = Locale::new("en-US").add_locale(i18n!("locale")); ``` Translate: diff --git a/actix-cloud/Cargo.toml b/actix-cloud/Cargo.toml index 37af773..9797662 100644 --- a/actix-cloud/Cargo.toml +++ b/actix-cloud/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-cloud" -version = "0.4.9" +version = "0.4.10" edition = "2021" authors = ["MXWXZ "] description = "Actix Cloud is an all-in-one web framework based on Actix Web." diff --git a/actix-cloud/src/i18n.rs b/actix-cloud/src/i18n.rs index 391bbc8..5326166 100644 --- a/actix-cloud/src/i18n.rs +++ b/actix-cloud/src/i18n.rs @@ -7,7 +7,7 @@ pub use actix_cloud_codegen::i18n; /// ```no_run /// use actix_cloud::{i18n::{i18n, Locale},t}; /// -/// let mut locale = Locale::new(String::from("en-US")).add_locale(i18n!("locale")); +/// let mut locale = Locale::new("en-US").add_locale(i18n!("locale")); /// /// // Get default locale's text /// t!(locale, "greeting"); @@ -76,10 +76,10 @@ pub struct Locale { } impl Locale { - pub fn new(default: String) -> Self { + pub fn new>(default: S) -> Self { Self { locale: HashMap::new(), - default, + default: default.into(), } } diff --git a/examples/i18n/src/main.rs b/examples/i18n/src/main.rs index a95532e..a3913b4 100644 --- a/examples/i18n/src/main.rs +++ b/examples/i18n/src/main.rs @@ -7,7 +7,7 @@ use actix_cloud::{ #[actix_cloud::main] async fn main() -> io::Result<()> { - let locale = Locale::new(String::from("en-US")).add_locale(i18n!("locale")); + let locale = Locale::new("en-US").add_locale(i18n!("locale")); println!("Default: {}", t!(locale, "hello.world")); println!("Translated: {}", t!(locale, "hello.world", "zh-CN")); diff --git a/examples/response/src/main.rs b/examples/response/src/main.rs index 04e8dc6..8a00099 100644 --- a/examples/response/src/main.rs +++ b/examples/response/src/main.rs @@ -48,7 +48,7 @@ async fn main() -> io::Result<()> { let (logger, _guard) = LoggerBuilder::new().start(); // Init locale. - let locale = Locale::new(String::from("en-US")).add_locale(i18n!("locale")); + let locale = Locale::new("en-US").add_locale(i18n!("locale")); // Init state. let state = GlobalState {