Skip to content

Commit

Permalink
Fix translations checker not detecting macros inside macro calls (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja authored Sep 24, 2024
1 parent 6d68b55 commit 0dc3e7f
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## 2024-09-24 - [0.1.22]

### Bug fixes

- Fix translations checker not detecting translation macros inside macro
calls (regression from v0.1.21).

## 2024-08-27 - [0.1.21]

### Bug fixes
Expand Down Expand Up @@ -507,6 +514,7 @@ version to `0.1` during installation.

- Added all ISO-639-1 and ISO-639-2 languages.

[0.1.22]: https://github.com/mondeja/leptos-fluent/compare/v0.1.21...v0.1.22
[0.1.21]: https://github.com/mondeja/leptos-fluent/compare/v0.1.20...v0.1.21
[0.1.20]: https://github.com/mondeja/leptos-fluent/compare/v0.1.19...v0.1.20
[0.1.19]: https://github.com/mondeja/leptos-fluent/compare/v0.1.18...v0.1.19
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion leptos-fluent-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "leptos-fluent-macros"
description = "Macros for leptos-fluent"
edition.workspace = true
version = "0.1.21"
version = "0.1.22"
license = "MIT"
documentation.workspace = true
repository.workspace = true
Expand Down
41 changes: 41 additions & 0 deletions leptos-fluent-macros/src/translations_checker/tr_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@ impl<'ast> TranslationsMacrosVisitor {
impl<'ast> Visit<'ast> for TranslationsMacrosVisitor {
fn visit_macro(&mut self, node: &'ast syn::Macro) {
self.visit_maybe_macro_tokens_stream(&node.to_token_stream());
for token in node.tokens.clone() {
if let proc_macro2::TokenTree::Group(group) = token {
self.visit_maybe_macro_tokens_stream(&group.stream());
}
}
syn::visit::visit_macro(self, node);
}

Expand Down Expand Up @@ -642,4 +647,40 @@ mod tests {
]
);
}

#[test]
fn tr_in_move_tr_params() {
let content = quote! {
#[component]
fn App() -> impl IntoView {
let download_svg_msg =
move_tr!("download-filetype", {"filetype" => tr!("svg")});
let download_colored_svg_msg =
move_tr!("download-filetype", {"filetype" => tr!("colored-svg")});
let download_pdf_msg =
move_tr!("download-filetype", {"filetype" => tr!("pdf")});
let download_jpg_msg =
move_tr!("download-filetype", {"filetype" => tr!("jpg")});
let download_png_msg =
move_tr!("download-filetype", {"filetype" => tr!("png")});
}
};
let tr_macros = tr_macros_from_file_content(&content.to_string());

assert_eq!(
tr_macros,
vec![
tr_macro!(
"move_tr",
"download-filetype",
vec!["filetype".to_string()]
),
tr_macro!("tr", "svg", Vec::new()),
tr_macro!("tr", "colored-svg", Vec::new()),
tr_macro!("tr", "pdf", Vec::new()),
tr_macro!("tr", "jpg", Vec::new()),
tr_macro!("tr", "png", Vec::new()),
]
);
}
}
2 changes: 1 addition & 1 deletion leptos-fluent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "leptos-fluent"
description = "Fluent framework for internationalization of Leptos applications"
edition.workspace = true
version = "0.1.21"
version = "0.1.22"
license = "MIT"
documentation.workspace = true
repository.workspace = true
Expand Down

0 comments on commit 0dc3e7f

Please sign in to comment.