From 52033e700ae7622df95868761d289bcb2d0b5305 Mon Sep 17 00:00:00 2001 From: Ykong <66518156+yk0n9@users.noreply.github.com> Date: Tue, 20 Aug 2024 19:46:57 +0800 Subject: [PATCH] Fix lazy init always "en" (#88) close #87 --------- Co-authored-by: KKRainbow Co-authored-by: Jason Lee --- crates/macro/src/lib.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/macro/src/lib.rs b/crates/macro/src/lib.rs index 378f291..16bb25b 100644 --- a/crates/macro/src/lib.rs +++ b/crates/macro/src/lib.rs @@ -292,7 +292,12 @@ fn generate_code( let default_locale = if let Some(default_locale) = args.default_locale { quote! { - rust_i18n::set_locale(#default_locale); + use std::ops::Deref; + if #default_locale != rust_i18n::locale().deref() { + rust_i18n::set_locale(rust_i18n::locale().deref()); + } else { + rust_i18n::set_locale(#default_locale); + } } } else { quote! {}