From 39588c7f908b7a560524f270b50ebc7b29238f75 Mon Sep 17 00:00:00 2001 From: Yurii Hulyk Date: Sat, 21 Nov 2026 21:01:35 +0000 Subject: [PATCH 1/3] feat: prototype Rake internationalisation Refs #21, #100, #101, #102, #104 and #105. --- Cargo.lock | 257 +++++++++++ crates/rake-cli/src/cdp/accessibility.rs | 4 + crates/rake-cli/src/cdp/benchmark.rs | 1 + crates/rake-cli/src/cdp/capabilities.rs | 2 +- crates/rake-cli/src/cdp/captures.rs | 1 + crates/rake-cli/src/cdp/dom.rs | 2 + crates/rake-cli/src/cdp/semantic.rs | 9 +- crates/rake-cli/src/terminal.rs | 90 +++- crates/rake-protocol/src/inspection.rs | 11 + crates/rake-view-syntax/src/view.rs | 27 ++ .../rake-view-syntax/src/view/inspection.rs | 6 +- crates/rake-view-syntax/src/view/tests.rs | 23 + crates/rake/Cargo.toml | 15 +- crates/rake/src/inspection.rs | 7 +- crates/rake/src/inspection/disabled.rs | 1 + crates/rake/src/inspection/view.rs | 29 +- .../rake/src/inspection/view/accessibility.rs | 1 + crates/rake/src/lib.rs | 2 + crates/rake/src/locale/formatting.rs | 135 ++++++ crates/rake/src/locale/mod.rs | 405 ++++++++++++++++++ crates/rake/src/locale/tests.rs | 90 ++++ crates/rake/src/locale/text.rs | 133 ++++++ docs/future/internationalisation-prototype.md | 199 +++++++++ docs/future/internationalisation.md | 2 + examples/inspector/tests/connection.rs | 1 + examples/inspector/tests/model.rs | 1 + examples/view/Cargo.toml | 3 + examples/view/locales/LICENSE-UNICODE | 39 ++ examples/view/locales/en.ftl | 17 + examples/view/locales/icu.postcard | Bin 0 -> 4734 bytes examples/view/locales/pt-PT.ftl | 17 + examples/view/src/lib.rs | 48 ++- examples/view/src/locale_demo.rs | 298 +++++++++++++ 33 files changed, 1847 insertions(+), 29 deletions(-) create mode 100644 crates/rake/src/locale/formatting.rs create mode 100644 crates/rake/src/locale/mod.rs create mode 100644 crates/rake/src/locale/tests.rs create mode 100644 crates/rake/src/locale/text.rs create mode 100644 docs/future/internationalisation-prototype.md create mode 100644 examples/view/locales/LICENSE-UNICODE create mode 100644 examples/view/locales/en.ftl create mode 100644 examples/view/locales/icu.postcard create mode 100644 examples/view/locales/pt-PT.ftl create mode 100644 examples/view/src/locale_demo.rs diff --git a/Cargo.lock b/Cargo.lock index 5f3ba100..f642c978 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -997,6 +997,16 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd17eb909a8c6a894926bfcc3400a4bb0e732f5a57d37b1f14e8b29e329bace8" +[[package]] +name = "calendrical_calculations" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5abbd6eeda6885048d357edc66748eea6e0268e3dd11f326fff5bd248d779c26" +dependencies = [ + "core_maths", + "displaydoc", +] + [[package]] name = "calloop" version = "0.14.5" @@ -1216,6 +1226,15 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "cobs" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa961b519f0b462e3a3b4a34b64d119eeaca1d59af726fe450bbba07a9fc0a1" +dependencies = [ + "thiserror 2.0.21", +] + [[package]] name = "cocoa" version = "0.25.0" @@ -2444,6 +2463,17 @@ version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48" +[[package]] +name = "fixed_decimal" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2214fb00f669ee96bee5bb29dfb1ddabe058b2bc426817efc79afa03c9bc55ae" +dependencies = [ + "displaydoc", + "smallvec", + "writeable", +] + [[package]] name = "fixedbitset" version = "0.5.7" @@ -2479,6 +2509,41 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8bf7cc16383c4b8d58b9905a8509f02926ce3058053c056376248d958c9df1e8" +[[package]] +name = "fluent-bundle" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01203cb8918f5711e73891b347816d932046f95f54207710bda99beaeb423bf4" +dependencies = [ + "fluent-langneg", + "fluent-syntax", + "intl-memoizer", + "intl_pluralrules", + "rustc-hash 2.1.3", + "self_cell", + "smallvec", + "unic-langid", +] + +[[package]] +name = "fluent-langneg" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eebbe59450baee8282d71676f3bfed5689aeab00b27545e83e5f14b1195e8b0" +dependencies = [ + "unic-langid", +] + +[[package]] +name = "fluent-syntax" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54f0d287c53ffd184d04d8677f590f4ac5379785529e5e08b1c8083acdd5c198" +dependencies = [ + "memchr", + "thiserror 2.0.21", +] + [[package]] name = "fluent-uri" version = "0.1.4" @@ -4248,6 +4313,21 @@ dependencies = [ "cc", ] +[[package]] +name = "icu_calendar" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a68ffb801cc7acb8dcae62da7c692c47934698d2dd4f479ddee1eb442763dea1" +dependencies = [ + "calendrical_calculations", + "displaydoc", + "icu_locale_core", + "icu_provider", + "serde", + "tinystr", + "zerovec", +] + [[package]] name = "icu_collections" version = "2.4.0" @@ -4262,6 +4342,47 @@ dependencies = [ "zerovec", ] +[[package]] +name = "icu_datetime" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c338aa7ebff734470e216a4196fa84b123a366cc786c445741b6f5647412c3c" +dependencies = [ + "displaydoc", + "fixed_decimal", + "icu_calendar", + "icu_decimal", + "icu_locale_core", + "icu_pattern", + "icu_plurals", + "icu_provider", + "icu_time", + "potential_utf", + "serde", + "smallvec", + "tinystr", + "writeable", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_decimal" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1150ad5e272740670464934ee76facda43ef2e11f85c27b7ba76ccb33edf2d05" +dependencies = [ + "displaydoc", + "fixed_decimal", + "icu_locale_core", + "icu_pattern", + "icu_plurals", + "icu_provider", + "serde", + "writeable", + "zerovec", +] + [[package]] name = "icu_locale_core" version = "2.4.0" @@ -4316,6 +4437,32 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "20f0088bfb7441f7a37fa0c9e20cb1e9cba1cac6b9ce8cd2a6dc44294f8e8cbc" +[[package]] +name = "icu_pattern" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc43ce0e76ee8cb0482dc6e2dbb9b76278e8038f45daabf2a2877577e2ceb18f" +dependencies = [ + "displaydoc", + "either", + "serde", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_plurals" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ef046647b445acf95ce0f8083fa292467d3df649959fa9a20f3f8abfd957c5d" +dependencies = [ + "displaydoc", + "fixed_decimal", + "icu_provider", + "serde", + "zerovec", +] + [[package]] name = "icu_properties" version = "2.4.0" @@ -4345,6 +4492,7 @@ checksum = "413099315636c588ee8f011190b329b971a09a8fae9d157e01dcae8379468514" dependencies = [ "displaydoc", "icu_locale_core", + "postcard", "serde", "stable_deref_trait", "writeable", @@ -4354,6 +4502,20 @@ dependencies = [ "zerovec", ] +[[package]] +name = "icu_provider_blob" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61ef59e2bab24a70e7b25d8025861b7c3b2de2982a6e6f64c1ca19e44e554889" +dependencies = [ + "icu_provider", + "postcard", + "serde", + "writeable", + "zerotrie", + "zerovec", +] + [[package]] name = "icu_segmenter" version = "2.4.0" @@ -4377,6 +4539,23 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "913a7d294ad056474749152107309fdee3ec17d2482d1ab70fdc61a81c64b9a3" +[[package]] +name = "icu_time" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17d45ee651f21433b1c6352311f2ad9b5253c26be0e25d9a0869cb8247b8cfde" +dependencies = [ + "calendrical_calculations", + "displaydoc", + "icu_calendar", + "icu_locale_core", + "icu_provider", + "serde", + "writeable", + "zerotrie", + "zerovec", +] + [[package]] name = "idea" version = "0.5.1" @@ -4566,6 +4745,25 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "intl-memoizer" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "310da2e345f5eb861e7a07ee182262e94975051db9e4223e909ba90f392f163f" +dependencies = [ + "type-map", + "unic-langid", +] + +[[package]] +name = "intl_pluralrules" +version = "7.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "078ea7b7c29a2b4df841a7f6ac8775ff6074020c6776d48491ce2268e068f972" +dependencies = [ + "unic-langid", +] + [[package]] name = "inventory" version = "0.3.25" @@ -4991,6 +5189,9 @@ name = "litemap" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" +dependencies = [ + "serde_core", +] [[package]] name = "litrs" @@ -6850,6 +7051,16 @@ dependencies = [ "thiserror 1.0.69", ] +[[package]] +name = "postcard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5431b3dcfdf6d1985c87d11f267a171c0dec0a8cd544c6727b747d36365f1fca" +dependencies = [ + "cobs", + "serde", +] + [[package]] name = "potential_utf" version = "0.1.6" @@ -7146,12 +7357,21 @@ dependencies = [ "blocking", "console_error_panic_hook", "event-listener", + "fixed_decimal", + "fluent-bundle", "foreign-types", "futures", "gpui-fast", "gpui-fast-platform", "gpui-pre", "gpui-pre-platform", + "icu_calendar", + "icu_datetime", + "icu_decimal", + "icu_locale_core", + "icu_plurals", + "icu_provider", + "icu_provider_blob", "image", "js-sys", "libc", @@ -7179,6 +7399,7 @@ dependencies = [ "schemars 1.2.3", "serde", "serde_json", + "sys-locale", "tempfile", "thiserror 2.0.21", "tracing", @@ -7192,6 +7413,7 @@ dependencies = [ "web-time", "windows 0.62.2", "windows-sys 0.61.2", + "writeable", ] [[package]] @@ -8985,6 +9207,9 @@ name = "smallvec" version = "1.16.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0d5d4b1981b8bbbb7aed204cae5726d683d5d6ac7e74ec54122ea28f315e7c8" +dependencies = [ + "serde", +] [[package]] name = "smol" @@ -10060,6 +10285,15 @@ dependencies = [ "cipher", ] +[[package]] +name = "type-map" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb30dbbd9036155e74adad6812e9898d03ec374946234fbcebd5dfc7b9187b90" +dependencies = [ + "rustc-hash 2.1.3", +] + [[package]] name = "typed-path" version = "0.12.4" @@ -10116,6 +10350,24 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" +[[package]] +name = "unic-langid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28ba52c9b05311f4f6e62d5d9d46f094bd6e84cb8df7b3ef952748d752a7d05" +dependencies = [ + "unic-langid-impl", +] + +[[package]] +name = "unic-langid-impl" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce1bf08044d4b7a94028c93786f8566047edc11110595914de93362559bc658" +dependencies = [ + "tinystr", +] + [[package]] name = "unicase" version = "2.10.0" @@ -11686,6 +11938,9 @@ name = "writeable" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" +dependencies = [ + "either", +] [[package]] name = "wyz" @@ -12164,6 +12419,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f" dependencies = [ "displaydoc", + "litemap", + "serde_core", "yoke", "zerofrom", "zerovec", diff --git a/crates/rake-cli/src/cdp/accessibility.rs b/crates/rake-cli/src/cdp/accessibility.rs index 1de8daac..dac90835 100644 --- a/crates/rake-cli/src/cdp/accessibility.rs +++ b/crates/rake-cli/src/cdp/accessibility.rs @@ -71,6 +71,10 @@ pub(super) fn node( result["name"] = json!({"type":"string","value":label}); } + if let Some(key) = &a11y.message_key { + result["messageKey"] = json!(key); + } + if let Some(description) = &a11y.description { result["description"] = json!({"type":"string","value":description}); } diff --git a/crates/rake-cli/src/cdp/benchmark.rs b/crates/rake-cli/src/cdp/benchmark.rs index e86b99cf..a4f2a3de 100644 --- a/crates/rake-cli/src/cdp/benchmark.rs +++ b/crates/rake-cli/src/cdp/benchmark.rs @@ -47,6 +47,7 @@ pub(super) fn capture(count: usize) -> Snapshot { status: Status::Captured, capture: "one".into(), router_revision: 0, + locale: None, omitted: 0, coverage: "generated benchmark boundaries".into(), elements: (0..count) diff --git a/crates/rake-cli/src/cdp/capabilities.rs b/crates/rake-cli/src/cdp/capabilities.rs index 30717e12..f0c5400e 100644 --- a/crates/rake-cli/src/cdp/capabilities.rs +++ b/crates/rake-cli/src/cdp/capabilities.rs @@ -41,7 +41,7 @@ pub(super) fn describe( json!({ "version":1,"runtimeId":info.runtime_id,"platform":info.platform,"methods":methods, "errorContractVersion":1, - "agentQuery":{"filters":["nodeId","stableId","id","role","name","text","textContains","textContent","textContentContains","bounds","enabled","visible"],"snapshotOptions":["limit","offset","expectedRevision","rootNodeId"],"textContent":"captured rendered text; a boundary owns its text or aggregates descendants; private input values are excluded"}, + "agentQuery":{"filters":["nodeId","stableId","id","role","name","messageKey","text","textContains","textContent","textContentContains","bounds","enabled","visible"],"snapshotOptions":["limit","offset","expectedRevision","rootNodeId"],"textContent":"captured rendered text; a boundary owns its text or aggregates descendants; private input values are excluded"}, "sourceRead":{"supported":sources && inspection && native,"transport":"snapshot source.url HTTP GET"}, "nativeWindowsAvailable":native,"nativeError":native_error, "limits":{"evidenceBytes":921600,"evidenceTreeNodes":64,"capturedTextBytes":16777216,"snapshotNodes":256,"waitHandles":32,"waitTimeoutMs":30000,"requestTimeoutMs":2000,"textBytes":16384,"imageBytes":768000,"messageBytes":1048576}, diff --git a/crates/rake-cli/src/cdp/captures.rs b/crates/rake-cli/src/cdp/captures.rs index 89828605..575c7676 100644 --- a/crates/rake-cli/src/cdp/captures.rs +++ b/crates/rake-cli/src/cdp/captures.rs @@ -66,6 +66,7 @@ mod tests { status: Status::Captured, capture: capture.into(), router_revision: 0, + locale: None, omitted: 0, coverage: "x".repeat(bytes), elements: vec![], diff --git a/crates/rake-cli/src/cdp/dom.rs b/crates/rake-cli/src/cdp/dom.rs index 631df66d..73b8cf34 100644 --- a/crates/rake-cli/src/cdp/dom.rs +++ b/crates/rake-cli/src/cdp/dom.rs @@ -1475,6 +1475,7 @@ mod tests { label: Some("Save".into()), name: None, name_source: None, + message_key: Some("save".into()), states: Default::default(), description: None, disabled: false, @@ -1508,6 +1509,7 @@ mod tests { assert_eq!(node["role"]["value"], "button"); assert_eq!(node["name"]["value"], "Save"); + assert_eq!(node["messageKey"], "save"); assert_eq!(node["ignored"], false); let root = dom .accessibility("Accessibility.getRootAXNode", &json!({})) diff --git a/crates/rake-cli/src/cdp/semantic.rs b/crates/rake-cli/src/cdp/semantic.rs index 112a6727..f415b127 100644 --- a/crates/rake-cli/src/cdp/semantic.rs +++ b/crates/rake-cli/src/cdp/semantic.rs @@ -166,6 +166,7 @@ pub(super) struct Selector { pub id: Option, pub role: Option, pub name: Option, + pub message_key: Option, pub text_contains: Option, pub text: Option, pub text_content: Option, @@ -377,6 +378,10 @@ pub(super) fn project( .name .as_ref() .is_some_and(|v| name != Some(v.as_str())) + || selector + .message_key + .as_ref() + .is_some_and(|key| ax.and_then(|a| a.message_key.as_ref()) != Some(key)) || selector .text_contains .as_ref() @@ -403,7 +408,7 @@ pub(super) fn project( elements.push(json!({"nodeId":node,"stableId":element.stable_id,"id":element.semantic_id, "parentId":element.parent.as_deref().and_then(|p|dom.node_id(p)),"type":element.display_name(), - "role":role,"name":name.map(prefix),"nameTruncated":name.is_some_and(|n|n.len()>512),"text":element.text.as_deref().map(prefix), + "role":role,"name":name.map(prefix),"messageKey":ax.and_then(|a|a.message_key.as_deref()),"nameTruncated":name.is_some_and(|n|n.len()>512),"text":element.text.as_deref().map(prefix), "textContent":prefix(content.text(index)),"textContentTruncated":content.text(index).len()>512,"textContentComplete":content.complete(index), "textTruncated":element.text.as_ref().is_some_and(|t|t.len()>512),"bounds":element.layout, "visibleBounds":element.content_mask,"visible":visible,"enabled":enabled, @@ -414,7 +419,7 @@ pub(super) fn project( Ok( json!({"windowId":presentation.window,"frameSequence":presentation.frame,"revision":revision,"rootNodeId":root,"queryComplete":query_complete, "elements":elements,"totalMatches":matches,"offset":offset,"hasMore":matches>offset+limit, - "omitted":presentation.tree.omitted,"coverage":presentation.tree.coverage, + "locale":presentation.tree.locale,"omitted":presentation.tree.omitted,"coverage":presentation.tree.coverage, "visibilitySemantics":"sampled layout, clipping and accessibility; final occlusion is unavailable"}), ) } diff --git a/crates/rake-cli/src/terminal.rs b/crates/rake-cli/src/terminal.rs index 5c8ec10a..59c5706a 100644 --- a/crates/rake-cli/src/terminal.rs +++ b/crates/rake-cli/src/terminal.rs @@ -22,7 +22,7 @@ rake highlight ID|none [--generation CAPTURE] [--instance UUID|application-id] rake inspect pick [--instance UUID|application-id] rake instances [--json] rake ctl [--instance UUID|application-id] [--json] [--timeout SECONDS] - inspect tree | inspect element ELEMENT_ID | inspect pick | inspect mode on|off [--lease-ms MS] + inspect tree | inspect message-key KEY [--role ROLE] [--window WINDOW] | inspect element ELEMENT_ID | inspect pick | inspect mode on|off [--lease-ms MS] inspect focus|scroll ELEMENT_ID [--generation CAPTURE] | inspect source ELEMENT_ID [--style INDEX|--handler INDEX] info | schema | snapshot | events [--follow] quit [--jobs wait|cancel] | quit status @@ -544,6 +544,24 @@ pub(super) fn run(mut args: Vec) -> Result<()> { args[1] = "element".into(); } + let message_key = if args.first().is_some_and(|arg| arg == "inspect") + && args.get(1).is_some_and(|arg| arg == "message-key") + { + let role = option(&mut args, "--role")?; + let window = option(&mut args, "--window")? + .map(|window| window.parse()) + .transpose()?; + + if args.len() != 3 { + return Err("inspect message-key requires one Fluent message identifier".into()); + } + + args[1] = "tree".into(); + Some((args.remove(2), role, window)) + } else { + None + }; + let (mut message, follow) = parse_message(args)?; let candidates: Vec<_> = instances @@ -564,6 +582,76 @@ pub(super) fn run(mut args: Vec) -> Result<()> { _ => return Err("ambiguous instance; select a RuntimeId using --instance".into()), }; + if let Some((key, role, window)) = message_key { + let mut offset = 0; + let mut pin = None; + let mut result: Option = None; + + loop { + let page = if let Some(window) = window { + let Reply::InspectionWindow(page) = query( + instance, + Query::InspectWindow { + window, + presentation: pin.take(), + offset, + }, + timeout, + )? + else { + return Err("unexpected window inspection reply".into()); + }; + + pin = Some(page.presentation); + page.page + } else { + let Reply::ElementPage(page) = query( + instance, + Query::InspectTreePage { + generation: pin.take(), + offset, + }, + timeout, + )? + else { + return Err("unexpected tree inspection reply".into()); + }; + + pin = Some(page.snapshot.capture.clone()); + page + }; + let mut tree = page.snapshot; + + tree.elements.retain(|element| { + element.accessibility.as_ref().is_some_and(|accessibility| { + accessibility.message_key.as_deref() == Some(key.as_str()) + && role.as_ref().is_none_or(|role| { + accessibility + .role + .as_ref() + .is_some_and(|value| value.eq_ignore_ascii_case(role)) + }) + }) + }); + + match &mut result { + Some(result) => result.elements.extend(tree.elements), + None => result = Some(tree), + } + + match page.next { + Some(next) if next > offset => offset = next, + Some(_) => return Err("inspection pagination did not advance".into()), + None => { + return print( + &Reply::Elements(result.ok_or("missing inspection page")?), + compact, + ); + } + } + } + } + if let Message::Command(Command::HighlightElement { id: Some(id), generation, diff --git a/crates/rake-protocol/src/inspection.rs b/crates/rake-protocol/src/inspection.rs index 34d5e7a3..b9e84e2f 100644 --- a/crates/rake-protocol/src/inspection.rs +++ b/crates/rake-protocol/src/inspection.rs @@ -335,6 +335,9 @@ pub struct Snapshot { pub capture: String, /// Router revision at the start of the captured render, not a live revision. pub router_revision: u64, + /// Resolved application locale when the tree was captured. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub locale: Option, /// Captured boundaries in depth-first order. pub elements: Vec, /// Inspected boundaries omitted by count/byte limits. Opaque descendants are uncounted. @@ -494,6 +497,13 @@ pub struct Accessibility { /// `label`, `text`, or `contents`; absent on older runtimes or unknown names. #[serde(default, skip_serializing_if = "Option::is_none")] pub name_source: Option, + /// Fluent message identifier for this label or control. + #[serde( + default, + rename = "messageKey", + skip_serializing_if = "Option::is_none" + )] + pub message_key: Option, /// Actual AccessKit states; never editable text or password values. #[serde(default, skip_serializing_if = "serde_json::Map::is_empty")] pub states: serde_json::Map, @@ -527,6 +537,7 @@ impl Accessibility { && self.label == other.label && self.name == other.name && self.name_source == other.name_source + && self.message_key == other.message_key && self.states == other.states && self.description == other.description && self.disabled == other.disabled diff --git a/crates/rake-view-syntax/src/view.rs b/crates/rake-view-syntax/src/view.rs index 4cef0a3c..94377551 100644 --- a/crates/rake-view-syntax/src/view.rs +++ b/crates/rake-view-syntax/src/view.rs @@ -1070,6 +1070,33 @@ impl Element { for (position, attribute) in self.attributes.iter().enumerate() { let value = attribute.expression()?; + if attribute.name == "message-key" { + let valid = if let Expr::Lit(syn::ExprLit { + lit: syn::Lit::Str(key), + .. + }) = value + { + let key = key.value(); + let mut bytes = key.bytes(); + bytes + .next() + .is_some_and(|first| first.is_ascii_alphabetic()) + && bytes + .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'_')) + } else { + false + }; + + if !valid { + return Err(syn::Error::new( + attribute.span, + "message-key expects a literal Fluent message identifier", + )); + } + + continue; + } + if self.resolved == Tag::Svg && !matches!( attribute.name.as_str(), diff --git a/crates/rake-view-syntax/src/view/inspection.rs b/crates/rake-view-syntax/src/view/inspection.rs index 9c90ca51..30e2d5e5 100644 --- a/crates/rake-view-syntax/src/view/inspection.rs +++ b/crates/rake-view-syntax/src/view/inspection.rs @@ -115,7 +115,11 @@ impl Element { let node = syn::Ident::new("__rake_inspection_element", Span::mixed_site()); let mut inspected = quote_spanned!(self.tag.span()=> #rake::__private::view_inspect(#node, #definition, #named)); - for (attribute, method) in [("focus", "focus_handle"), ("scroll", "scroll_handle")] { + for (attribute, method) in [ + ("focus", "focus_handle"), + ("scroll", "scroll_handle"), + ("message-key", "message_key"), + ] { if let Some(value) = self.attribute(attribute) { let value = value.expression().expect("validated handle"); let method = syn::Ident::new(method, value.span()); diff --git a/crates/rake-view-syntax/src/view/tests.rs b/crates/rake-view-syntax/src/view/tests.rs index f4ab2199..68687d8e 100644 --- a/crates/rake-view-syntax/src/view/tests.rs +++ b/crates/rake-view-syntax/src/view/tests.rs @@ -746,3 +746,26 @@ fn file_drag_over_classes_merge_with_the_external_paths_payload() { assert!(expanded.contains(".opacity(0.5")); assert!(expanded.contains(".border_2()")); } + +#[test] +fn preserves_explicit_translation_and_lowers_message_key() { + let output = expand( + r#""#, + ) + .unwrap(); + let tokens = output.to_string(); + + syn::parse2::(output).unwrap(); + assert!( + tokens.contains(r#"rake :: t ! (cx , "inbox-count" , count = n)"#), + "{tokens}" + ); + assert!( + tokens.contains(r#". message_key ("inbox-count")"#), + "{tokens}" + ); + assert!(expand(r#" + + + +
+ + if cfg!(not(target_family = "wasm")) { + + } + +
+ {kit} + + } + } +} + +pub(super) fn application() -> rake::App { + rake::App::new("com.example.rake.view") + .control(rake::control::ControlConfig::FromEnvironment) + .theme(Colors::dark()) + .theme(rake::theme::Semantic::dark()) + .routes(Pages) + .initial(Page::Inbox) +} + +#[cfg(all(test, feature = "i18n-icu", feature = "view-test-support"))] +mod tests { + use super::*; + + #[gpui::test] + fn formats_and_switches_using_the_public_api(cx: &mut gpui::TestAppContext) { + cx.update(|cx| { + install(cx).unwrap(); + let amount = "1234.50".parse().unwrap(); + + locale::set_mode(cx, explicit("en-GB").unwrap()).unwrap(); + assert_eq!(locale::current(cx).unwrap().to_string(), "en"); + assert_eq!(locale::format_number(cx, &amount).unwrap(), "1,234.50"); + assert_eq!( + locale::format_date(cx, 2026, 11, 21).unwrap(), + "Nov 21, 2026" + ); + + locale::set_mode(cx, explicit("pt-BR").unwrap()).unwrap(); + assert_eq!(locale::current(cx).unwrap().to_string(), "pt-PT"); + assert_eq!(locale::format_number(cx, &amount).unwrap(), "1234,50"); + assert_eq!(locale::format_date(cx, 2026, 11, 21).unwrap(), "21/11/2026"); + assert!(locale::format_date(cx, 2026, 2, 29).is_err()); + + for (count, category, text) in [ + (1, locale::PluralCategory::One, "Uma mensagem"), + (2, locale::PluralCategory::Other, "mensagens"), + ] { + assert_eq!( + locale::plural_category(cx, &count.into()).unwrap(), + category + ); + assert!( + rake::t!(cx, "inbox-count", count = count) + .as_str() + .contains(text) + ); + } + + assert_eq!( + rake::t!(cx, "inbox-count", count = "uma").as_str(), + "inbox-count" + ); + assert_eq!(rake::t!(cx, "inbox-count").as_str(), "inbox-count"); + assert!(locale::set_mode(cx, explicit("ja").unwrap()).is_err()); + assert!(explicit("pt-@").is_err()); + locale::redetect(cx).unwrap(); + assert_eq!(locale::current(cx).unwrap().to_string(), "pt-PT"); + }); + } +} From 2971b61eb142ad7474e161886421835df3c79c82 Mon Sep 17 00:00:00 2001 From: Yurii Hulyk Date: Sat, 21 Nov 2026 22:08:56 +0000 Subject: [PATCH 2/3] style: apply CI statement spacing --- crates/rake-cli/src/terminal.rs | 5 +++++ crates/rake-view-syntax/src/view.rs | 1 + crates/rake-view-syntax/src/view/tests.rs | 1 + 3 files changed, 7 insertions(+) diff --git a/crates/rake-cli/src/terminal.rs b/crates/rake-cli/src/terminal.rs index 59c5706a..c1d17800 100644 --- a/crates/rake-cli/src/terminal.rs +++ b/crates/rake-cli/src/terminal.rs @@ -548,6 +548,7 @@ pub(super) fn run(mut args: Vec) -> Result<()> { && args.get(1).is_some_and(|arg| arg == "message-key") { let role = option(&mut args, "--role")?; + let window = option(&mut args, "--window")? .map(|window| window.parse()) .transpose()?; @@ -557,6 +558,7 @@ pub(super) fn run(mut args: Vec) -> Result<()> { } args[1] = "tree".into(); + Some((args.remove(2), role, window)) } else { None @@ -603,6 +605,7 @@ pub(super) fn run(mut args: Vec) -> Result<()> { }; pin = Some(page.presentation); + page.page } else { let Reply::ElementPage(page) = query( @@ -618,8 +621,10 @@ pub(super) fn run(mut args: Vec) -> Result<()> { }; pin = Some(page.snapshot.capture.clone()); + page }; + let mut tree = page.snapshot; tree.elements.retain(|element| { diff --git a/crates/rake-view-syntax/src/view.rs b/crates/rake-view-syntax/src/view.rs index 94377551..54145529 100644 --- a/crates/rake-view-syntax/src/view.rs +++ b/crates/rake-view-syntax/src/view.rs @@ -1078,6 +1078,7 @@ impl Element { { let key = key.value(); let mut bytes = key.bytes(); + bytes .next() .is_some_and(|first| first.is_ascii_alphabetic()) diff --git a/crates/rake-view-syntax/src/view/tests.rs b/crates/rake-view-syntax/src/view/tests.rs index 68687d8e..7b87ed6b 100644 --- a/crates/rake-view-syntax/src/view/tests.rs +++ b/crates/rake-view-syntax/src/view/tests.rs @@ -755,6 +755,7 @@ fn preserves_explicit_translation_and_lowers_message_key() { "#, ) .unwrap(); + let tokens = output.to_string(); syn::parse2::(output).unwrap(); From 5bad999166df4fd66f765d9872bd8ea95cc121c9 Mon Sep 17 00:00:00 2001 From: Yurii Hulyk Date: Sat, 21 Nov 2026 22:48:10 +0000 Subject: [PATCH 3/3] fix(locale): map pt-PT to Kit's pt-BR before English Kit 0.9 ships Portuguese only as pt-BR; a regional sibling is closer to the user's language than English, per review. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- crates/rake/src/locale/mod.rs | 22 +++++++++++++------ crates/rake/src/locale/tests.rs | 11 ++++++++++ docs/future/internationalisation-prototype.md | 17 ++++++++------ 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/crates/rake/src/locale/mod.rs b/crates/rake/src/locale/mod.rs index 5db2b661..900be7df 100644 --- a/crates/rake/src/locale/mod.rs +++ b/crates/rake/src/locale/mod.rs @@ -354,18 +354,26 @@ fn system_locales() -> Vec { .collect() } -#[cfg(all(feature = "kit", not(target_family = "wasm")))] -fn sync_kit(locale: &Locale) { +/// Picks Kit's catalogue: exact tag, bare language, then a regional sibling such as +/// `pt-BR` for `pt-PT`, and English only when Kit has no catalogue in that language. +#[cfg(any(all(feature = "kit", not(target_family = "wasm")), test))] +fn kit_locale(locale: &Locale) -> &'static str { // shortcut: Kit 0.9's supported tags are pinned here until Kit exposes the catalogue list. const SUPPORTED: &[&str] = &["en", "pt-BR", "ru", "zh-CN", "zh-HK", "zh-TW", "it"]; let exact = locale.id.to_string(); let language = locale.id.language.as_str(); - let kit_locale = [exact.as_str(), language] - .into_iter() - .find(|tag| SUPPORTED.contains(tag)) - .unwrap_or("en"); - crate::kit::component::set_locale(kit_locale); + let find = |matches: &dyn Fn(&str) -> bool| SUPPORTED.iter().copied().find(|tag| matches(tag)); + + find(&|tag| tag == exact) + .or_else(|| find(&|tag| tag == language)) + .or_else(|| find(&|tag| tag.split('-').next() == Some(language))) + .unwrap_or("en") +} + +#[cfg(all(feature = "kit", not(target_family = "wasm")))] +fn sync_kit(locale: &Locale) { + crate::kit::component::set_locale(kit_locale(locale)); } #[cfg(not(all(feature = "kit", not(target_family = "wasm"))))] diff --git a/crates/rake/src/locale/tests.rs b/crates/rake/src/locale/tests.rs index dea2def2..e88c0d80 100644 --- a/crates/rake/src/locale/tests.rs +++ b/crates/rake/src/locale/tests.rs @@ -88,3 +88,14 @@ fn falls_back_for_missing_messages_and_displays_keys_on_errors() { assert!(translated.as_str().contains("Inês")); assert_eq!(translated.message_key(), "with-argument"); } + +#[test] +fn kit_uses_a_regional_sibling_before_english() { + let kit = |tag: &str| kit_locale(&tag.parse().unwrap()); + + assert_eq!(kit("pt-PT"), "pt-BR"); + assert_eq!(kit("pt"), "pt-BR"); + assert_eq!(kit("zh-TW"), "zh-TW"); + assert_eq!(kit("en-GB"), "en"); + assert_eq!(kit("fr"), "en"); +} diff --git a/docs/future/internationalisation-prototype.md b/docs/future/internationalisation-prototype.md index 60cbb031..0d0d6930 100644 --- a/docs/future/internationalisation-prototype.md +++ b/docs/future/internationalisation-prototype.md @@ -4,8 +4,8 @@ This slice exercises [the design for #21](internationalisation.md) with English and European Portuguese. The normal view example opens the original counter. Enable `i18n-icu` to open the inbox with Fluent, cardinal plurals, decimal formatting and Gregorian civil dates. The counter remains reachable from the -inbox. Enable `kit` on native to see both the Kit-owned English fallback and a -placeholder supplied by the app in the selected language. +inbox. Enable `kit` on native to see both Kit-owned copy and a placeholder supplied by +the app in the selected language. ## Implementation and evidence @@ -37,7 +37,8 @@ placeholder supplied by the app in the selected language. “Choose a folder”. Kit 0.9 has neither a `pt-PT` nor a `pt` catalogue. That gap covers Select, Calendar, list search, attachment actions and the other Kit-owned copy in the pinned catalogue. Its Portuguese translations are tagged - `pt-BR`. Separately, the source asks for `Combobox.placeholder` while the + `pt-BR`. After review, the adapter maps `pt-PT` to Kit's `pt-BR` rather than + English; that change was not re-captured at runtime. Separately, the source asks for `Combobox.placeholder` while the catalogue entry is spelled `ComboBox.placeholder`. This source mismatch was observed without exercising Combobox at runtime. @@ -193,7 +194,9 @@ and carries the [Unicode license](../../examples/view/locales/LICENSE-UNICODE). coverage. The resolved locale is captured with the tree. Native platform screen-reader speech and language announcements were outside verification. - **#105** Retain the feature-gated one-way Kit adapter. The prototype pins the - Kit locale list and falls back to English if there is no exact or language - match. Prefer a Kit-supported catalogue inventory and audit cached strings in - other controls. The window wrapper and the existing counter retain their - current English copy. RTL layout remains in #103 and #106. + Kit locale list and tries the exact tag, the bare language, then a regional + sibling such as `pt-BR` for `pt-PT`, falling back to English only when Kit + has no catalogue in that language. Prefer a Kit-supported catalogue inventory + and audit cached strings in other controls. The window wrapper and the + existing counter retain their current English copy. RTL layout remains in + #103 and #106.