Skip to content

Commit 048e912

Browse files
committed
fix(localization): detect SwiftUI wrapper callsites
1 parent ecabc0b commit 048e912

2 files changed

Lines changed: 18 additions & 12 deletions

File tree

grapha-swift/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ fn source_contains_l10n_markers(source: &[u8]) -> bool {
344344
|| bytes_contains(source, b"NSLocalizedString")
345345
|| bytes_contains(source, b"LocalizedStringKey")
346346
|| bytes_contains(source, b"Text(\"")
347+
|| bytes_contains(source, b"Text(.")
347348
|| bytes_contains(source, b"Localizable")
348349
}
349350

@@ -800,6 +801,9 @@ mod marker_tests {
800801
#[test]
801802
fn localization_and_asset_markers_still_match_common_cases() {
802803
assert!(source_contains_l10n_markers(br#"Text("hello")"#));
804+
assert!(source_contains_l10n_markers(
805+
br#"Text(.accountForgetPassword)"#
806+
));
803807
assert!(source_contains_l10n_markers(
804808
br#"NSLocalizedString("hello", comment: "")"#
805809
));

grapha/src/query/origin.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -319,18 +319,21 @@ fn choose_preferred_origin<'a>(
319319
current: &'a OriginPath,
320320
candidate: &'a OriginPath,
321321
) -> &'a OriginPath {
322-
origin_specificity_rank(candidate)
322+
let candidate_ordering = origin_specificity_rank(candidate)
323323
.cmp(&origin_specificity_rank(current))
324324
.then_with(|| {
325325
candidate
326326
.confidence
327327
.partial_cmp(&current.confidence)
328328
.unwrap_or(std::cmp::Ordering::Equal)
329329
})
330-
.then_with(|| current.api.name.cmp(&candidate.api.name).reverse())
331-
.is_gt()
332-
.then_some(candidate)
333-
.unwrap_or(current)
330+
.then_with(|| current.api.name.cmp(&candidate.api.name).reverse());
331+
332+
if candidate_ordering.is_gt() {
333+
candidate
334+
} else {
335+
current
336+
}
334337
}
335338

336339
fn merge_equivalent_origins(origins: Vec<OriginPath>) -> Vec<OriginPath> {
@@ -641,14 +644,13 @@ fn notes_for(
641644
.iter()
642645
.rev()
643646
.find(|node| is_origin_terminal(node))
647+
&& let Some(kind) = terminal_kind(terminal_node)
644648
{
645-
if let Some(kind) = terminal_kind(terminal_node) {
646-
notes.push(format!(
647-
"reached {} terminal {}",
648-
terminal_kind_to_string(&kind),
649-
terminal_node.name
650-
));
651-
}
649+
notes.push(format!(
650+
"reached {} terminal {}",
651+
terminal_kind_to_string(&kind),
652+
terminal_node.name
653+
));
652654
}
653655
if let Some(candidate) = field_candidates.first() {
654656
notes.push(format!("candidate field path {}", candidate));

0 commit comments

Comments
 (0)