perf(i18n): update translate function to use Cow to aovid allocate

This commit is contained in:
Tunglies
2025-12-30 18:32:19 +08:00
parent cf08628200
commit 9ce343fb45
2 changed files with 17 additions and 16 deletions

View File

@@ -65,8 +65,8 @@ pub fn set_locale(language: &str) {
}
#[inline]
pub fn translate(key: &str) -> String {
rust_i18n::t!(key).to_string()
pub fn translate(key: &str) -> Cow<'_, str> {
rust_i18n::t!(key)
}
#[macro_export]
@@ -78,7 +78,7 @@ macro_rules! t {
{
let mut _text = $crate::translate(&$key);
$(
_text = _text.replace(&format!("{{{}}}", stringify!($arg_name)), &$arg_value.to_string());
_text = _text.replace(&format!("{{{}}}", stringify!($arg_name)), &$arg_value);
)*
_text
}