Skip to content

Commit

Permalink
Fix tr macros not extracted at returns in translations checker (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja authored Aug 27, 2024
1 parent 7b4d427 commit 0e7f335
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## 2024-08-27 - [0.1.21]

- Fix translation macros not extracted from some locations when a variable
binding is not used in translations checker.

## 2024-08-26 - [0.1.20]

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

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

[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
[0.1.18]: https://github.com/mondeja/leptos-fluent/compare/v0.1.17...v0.1.18
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.20"
version = "0.1.21"
license = "MIT"
documentation.workspace = true
repository.workspace = true
Expand Down
44 changes: 33 additions & 11 deletions leptos-fluent-macros/src/translations_checker/tr_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub(crate) fn gather_tr_macro_defs_from_rs_files(
(tr_macros, errors)
}
Err(error) => (
vec![],
Vec::new(),
vec![format!(
r#"Error parsing glob pattern "{}": {}"#,
glob_pattern, error,
Expand Down Expand Up @@ -302,19 +302,12 @@ impl<'ast> TranslationsMacrosVisitor {

impl<'ast> Visit<'ast> for TranslationsMacrosVisitor {
fn visit_macro(&mut self, node: &'ast syn::Macro) {
for token in node.tokens.clone() {
if let proc_macro2::TokenTree::Group(group) = token {
self.visit_maybe_macro_tokens_stream(&group.stream());
}
}

self.visit_maybe_macro_tokens_stream(&node.to_token_stream());
syn::visit::visit_macro(self, node);
}

fn visit_stmt_macro(&mut self, node: &'ast syn::StmtMacro) {
let stream = node.to_token_stream();
self.visit_maybe_macro_tokens_stream(&stream);

self.visit_maybe_macro_tokens_stream(&node.to_token_stream());
syn::visit::visit_stmt_macro(self, node);
}

Expand Down Expand Up @@ -570,7 +563,7 @@ mod tests {

let tr_macros = tr_macros_from_file_content(&content.to_string());

assert_eq!(tr_macros, vec![]);
assert_eq!(tr_macros, Vec::new());
}

#[test]
Expand Down Expand Up @@ -620,4 +613,33 @@ mod tests {
]
);
}

#[test]
fn at_return() {
let content = quote! {
pub fn foo() -> String {
tr!("now")
}

pub fn bar() -> String {
return move_tr!("after");
}

fn baz() -> String {
(tr!("before"), move_tr!("tomorrow"))
}
};

let tr_macros = tr_macros_from_file_content(&content.to_string());

assert_eq!(
tr_macros,
vec![
tr_macro!("tr", "now", Vec::new()),
tr_macro!("move_tr", "after", Vec::new()),
tr_macro!("tr", "before", Vec::new()),
tr_macro!("move_tr", "tomorrow", 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.20"
version = "0.1.21"
license = "MIT"
documentation.workspace = true
repository.workspace = true
Expand Down

0 comments on commit 0e7f335

Please sign in to comment.