Skip to content

Commit 0e7f335

Browse files
authored
Fix tr macros not extracted at returns in translations checker (#237)
1 parent 7b4d427 commit 0e7f335

File tree

5 files changed

+43
-15
lines changed

5 files changed

+43
-15
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG
22

3+
## 2024-08-27 - [0.1.21]
4+
5+
- Fix translation macros not extracted from some locations when a variable
6+
binding is not used in translations checker.
7+
38
## 2024-08-26 - [0.1.20]
49

510
### Bug fixes
@@ -500,6 +505,7 @@ version to `0.1` during installation.
500505

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

508+
[0.1.21]: https://github.com/mondeja/leptos-fluent/compare/v0.1.20...v0.1.21
503509
[0.1.20]: https://github.com/mondeja/leptos-fluent/compare/v0.1.19...v0.1.20
504510
[0.1.19]: https://github.com/mondeja/leptos-fluent/compare/v0.1.18...v0.1.19
505511
[0.1.18]: https://github.com/mondeja/leptos-fluent/compare/v0.1.17...v0.1.18

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

leptos-fluent-macros/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "leptos-fluent-macros"
33
description = "Macros for leptos-fluent"
44
edition.workspace = true
5-
version = "0.1.20"
5+
version = "0.1.21"
66
license = "MIT"
77
documentation.workspace = true
88
repository.workspace = true

leptos-fluent-macros/src/translations_checker/tr_macros.rs

+33-11
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub(crate) fn gather_tr_macro_defs_from_rs_files(
3838
(tr_macros, errors)
3939
}
4040
Err(error) => (
41-
vec![],
41+
Vec::new(),
4242
vec![format!(
4343
r#"Error parsing glob pattern "{}": {}"#,
4444
glob_pattern, error,
@@ -302,19 +302,12 @@ impl<'ast> TranslationsMacrosVisitor {
302302

303303
impl<'ast> Visit<'ast> for TranslationsMacrosVisitor {
304304
fn visit_macro(&mut self, node: &'ast syn::Macro) {
305-
for token in node.tokens.clone() {
306-
if let proc_macro2::TokenTree::Group(group) = token {
307-
self.visit_maybe_macro_tokens_stream(&group.stream());
308-
}
309-
}
310-
305+
self.visit_maybe_macro_tokens_stream(&node.to_token_stream());
311306
syn::visit::visit_macro(self, node);
312307
}
313308

314309
fn visit_stmt_macro(&mut self, node: &'ast syn::StmtMacro) {
315-
let stream = node.to_token_stream();
316-
self.visit_maybe_macro_tokens_stream(&stream);
317-
310+
self.visit_maybe_macro_tokens_stream(&node.to_token_stream());
318311
syn::visit::visit_stmt_macro(self, node);
319312
}
320313

@@ -570,7 +563,7 @@ mod tests {
570563

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

573-
assert_eq!(tr_macros, vec![]);
566+
assert_eq!(tr_macros, Vec::new());
574567
}
575568

576569
#[test]
@@ -620,4 +613,33 @@ mod tests {
620613
]
621614
);
622615
}
616+
617+
#[test]
618+
fn at_return() {
619+
let content = quote! {
620+
pub fn foo() -> String {
621+
tr!("now")
622+
}
623+
624+
pub fn bar() -> String {
625+
return move_tr!("after");
626+
}
627+
628+
fn baz() -> String {
629+
(tr!("before"), move_tr!("tomorrow"))
630+
}
631+
};
632+
633+
let tr_macros = tr_macros_from_file_content(&content.to_string());
634+
635+
assert_eq!(
636+
tr_macros,
637+
vec![
638+
tr_macro!("tr", "now", Vec::new()),
639+
tr_macro!("move_tr", "after", Vec::new()),
640+
tr_macro!("tr", "before", Vec::new()),
641+
tr_macro!("move_tr", "tomorrow", Vec::new()),
642+
]
643+
);
644+
}
623645
}

leptos-fluent/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "leptos-fluent"
33
description = "Fluent framework for internationalization of Leptos applications"
44
edition.workspace = true
5-
version = "0.1.20"
5+
version = "0.1.21"
66
license = "MIT"
77
documentation.workspace = true
88
repository.workspace = true

0 commit comments

Comments
 (0)