Skip to content

Commit

Permalink
Rename feature log-missing to log-miss-tr
Browse files Browse the repository at this point in the history
  • Loading branch information
varphone committed Jan 28, 2024
1 parent f8d816a commit d9a6d89
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion crates/macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ rust-i18n = { path = "../.." }
proc-macro = true

[features]
log-missing = []
log-miss-tr = []
20 changes: 13 additions & 7 deletions crates/macro/src/tr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,18 @@ impl Tr {
Ok(())
}

#[cfg(feature = "log-miss-tr")]
fn log_missing() -> proc_macro2::TokenStream {
quote! {
log::log!(target: "rust-i18n", log::Level::Warn, "missing: {} => {:?} @ {}:{}", msg_key, msg_val, file!(), line!());
}
}

#[cfg(not(feature = "log-miss-tr"))]
fn log_missing() -> proc_macro2::TokenStream {
quote! {}
}

fn into_token_stream(self) -> proc_macro2::TokenStream {
let (msg_key, msg_val) = if self.minify_key && self.msg.val.is_expr_lit_str() {
let msg_val = self.msg.val.to_string().unwrap();
Expand Down Expand Up @@ -416,13 +428,7 @@ impl Tr {
quote! { format!(#sepecifiers, #value) }
})
.collect();
let logging = if cfg!(feature = "log-missing") {
quote! {
log::log!(target: "rust-i18n", log::Level::Warn, "missing: {} => {:?} @ {}:{}", msg_key, msg_val, file!(), line!());
}
} else {
quote! {}
};
let logging = Self::log_missing();
if self.args.is_empty() {
quote! {
{
Expand Down
3 changes: 1 addition & 2 deletions examples/app-egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ log = { version = "0.4", optional = true }
rust-i18n = { path = "../.." }

[features]
default = ["log-missing"]
log-missing = ["env_logger", "log", "rust-i18n/log-missing"]
log-miss-tr = ["env_logger", "log", "rust-i18n/log-miss-tr"]

[package.metadata.i18n]
available-locales = ["en", "fr", "ja", "ko", "zh", "zh-CN"]
Expand Down
1 change: 1 addition & 0 deletions examples/app-egui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ rust_i18n::i18n!(
);

fn main() -> Result<(), eframe::Error> {
#[cfg(feature = "log-miss-tr")]
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default().with_inner_size([320.0, 240.0]),
Expand Down
2 changes: 1 addition & 1 deletion examples/app-minify-key/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ log = { version = "0.4", optional = true }
rust-i18n = { path = "../.." }

[features]
log-missing = ["env_logger", "log", "rust-i18n/log-missing"]
log-miss-tr = ["env_logger", "log", "rust-i18n/log-miss-tr"]

[package.metadata.i18n]
available-locales = ["en", "zh-CN"]
Expand Down
6 changes: 3 additions & 3 deletions examples/app-minify-key/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ rust_i18n::i18n!(
minify_key_thresh = 4
);

#[cfg(feature = "log-missing")]
#[cfg(feature = "log-miss-tr")]
fn set_logger() {
env_logger::builder()
.filter_level(log::LevelFilter::Debug)
.parse_default_env()
.init();
}

#[cfg(not(feature = "log-missing"))]
#[cfg(not(feature = "log-miss-tr"))]
fn set_logger() {}

fn main() {
Expand Down Expand Up @@ -76,7 +76,7 @@ fn main() {
}
println!();

if cfg!(feature = "log-missing") {
if cfg!(feature = "log-miss-tr") {
println!("Translates runtime strings and logs when a lookup is missing:");
for locale in &locales {
let msg = "Foo Bar".to_string();
Expand Down

0 comments on commit d9a6d89

Please sign in to comment.