Support using glob paths in `localize` macro

finchie
Feb 18, 2024, 8:58 AM
VNSHGQYNPGKGGPYNVP4Z2RWD7JCSDJVYAADD6UXWBYL6ZRXKLE4AC

Dependencies

  • [2] HJMYJDC7 Simplify `fluent_embed::group` module
  • [3] XEEXWJLG Add simple end-to-end test for selectors
  • [4] XGNME3WR Move `Group::derive_enum` to new `crate::parse_macro` module
  • [5] 5TEX4MNU Split `fluent_embed` into `group` and `parse` modules
  • [6] OCR4YRQ2 Parse group from fluent file specified by macro attribute
  • [7] QSK7JRBA Add simple `attribute_path` function
  • [8] 5FIVUZYF Unify `fluent_embed` macro API as `localize()`
  • [*] O77KA6C4 Create `fluent_embed` crate
  • [*] 56F2YE6H Use `prettyplease` to format macro output
  • [*] UKFEFT6L Create basic `Output` proc-macro
  • [*] SHNZZSZG Create `cli_macros` shim crate

Change contents

  • replacement in fluent_embed/src/parse_macro.rs at line 55
    [4.45][4.291:353]()
    pub fn attribute_groups(path_literal: syn::LitStr) -> Group {
    [4.45]
    [4.353]
    pub fn attribute_groups(path_literal: syn::LitStr) -> Vec<Group> {
  • replacement in fluent_embed/src/parse_macro.rs at line 58
    [4.469][3.0:82]()
    let resource_path = PathBuf::from(&manifest_root).join(path_literal.value());
    [4.469]
    [3.82]
    let attribute_glob = path_literal.value();
    let mut groups = Vec::new();
    let glob = wax::Glob::new(&attribute_glob).unwrap();
    for potential_entry in glob.walk(&manifest_root) {
    // TODO: this assumes that the locale is the first capture
    let entry = potential_entry.unwrap();
    let captured_locale = entry.matched().get(1).unwrap();
    dbg!(captured_locale);
  • replacement in fluent_embed/src/parse_macro.rs at line 69
    [3.83][4.550:625](),[4.550][4.550:625]()
    let fluent_contents = std::fs::read_to_string(resource_path).unwrap();
    [3.83]
    [4.63]
    // Parse the file into a `Group`
    let fluent_contents = std::fs::read_to_string(entry.into_path()).unwrap();
    let resource = fluent_syntax::parser::parse(fluent_contents).unwrap();
    let group = Group::from_resource(resource);
  • replacement in fluent_embed/src/parse_macro.rs at line 74
    [4.64][4.626:786]()
    // Parse the file into a `Group`
    let resource = fluent_syntax::parser::parse(fluent_contents).unwrap();
    let group = Group::from_resource(resource);
    [4.64]
    [4.368]
    groups.push(group);
    }
  • replacement in fluent_embed/src/parse_macro.rs at line 77
    [4.369][4.787:797]()
    group
    [4.369]
    [4.797]
    groups
  • replacement in fluent_embed/src/parse_macro.rs at line 85
    [4.941][4.941:1021]()
    let group = attribute_groups(path);
    derive_enum(group, ident, variants)
    [4.941]
    [4.1605]
    let groups = attribute_groups(path);
    derive_enum(groups[0].clone(), ident, variants)
  • replacement in fluent_embed/src/group.rs at line 3
    [4.3691][4.3691:3708]()
    #[derive(Debug)]
    [4.3691]
    [2.735]
    #[derive(Clone, Debug)]
  • edit in fluent_embed/Cargo.toml at line 15
    [10.1578]
    [11.238]
    wax = "0.6.0"
  • replacement in cli_macros/tests/selectors.rs at line 7
    [3.341][3.341:376]()
    #[localize("tests/selectors.ftl")]
    [3.341]
    [3.376]
    #[localize("tests/locale/**/selectors.ftl")]
  • file addition: locale (d--r------)
    [3.101]
  • file addition: en-US (d--r------)
    [0.971]
  • file move: selectors.ftl (----------)selectors.ftl (----------)
    [0.990]
    [3.1152]
  • edit in Cargo.lock at line 6
    [13.1106]
    [13.1106]
    name = "aho-corasick"
    version = "1.1.2"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
    dependencies = [
    "memchr",
    ]
    [[package]]
  • edit in Cargo.lock at line 23
    [13.1226]
    [13.1226]
    ]
    [[package]]
    name = "const_format"
    version = "0.2.32"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "e3a214c7af3d04997541b18d432afaff4c455e79e2029079647e72fc2bd27673"
    dependencies = [
    "const_format_proc_macros",
    ]
    [[package]]
    name = "const_format_proc_macros"
    version = "0.2.32"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "c7f6ff08fd20f4f299298a28e2dfa8a8ba1036e6cd2460ac1de7b425d76f2500"
    dependencies = [
    "proc-macro2",
    "quote",
    "unicode-xid",
  • edit in Cargo.lock at line 55
    [13.1475]
    [13.1475]
    [[package]]
    name = "either"
    version = "1.10.0"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a"
  • edit in Cargo.lock at line 92
    [10.1986]
    [10.1986]
    "wax",
  • edit in Cargo.lock at line 184
    [13.3668]
    [13.3668]
    ]
    [[package]]
    name = "itertools"
    version = "0.11.0"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57"
    dependencies = [
    "either",
  • edit in Cargo.lock at line 200
    [13.3861]
    [13.3861]
    [[package]]
    name = "memchr"
    version = "2.7.1"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
    [[package]]
    name = "minimal-lexical"
    version = "0.2.1"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
    [[package]]
    name = "nom"
    version = "7.1.3"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
    dependencies = [
    "memchr",
    "minimal-lexical",
    ]
  • edit in Cargo.lock at line 233
    [12.4501]
    [11.301]
    name = "pori"
    version = "0.0.0"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "a4a63d338dec139f56dacc692ca63ad35a6be6a797442479b55acd611d79e906"
    dependencies = [
    "nom",
    ]
    [[package]]
  • edit in Cargo.lock at line 267
    [12.4944]
    [12.4944]
    ]
    [[package]]
    name = "regex"
    version = "1.10.3"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15"
    dependencies = [
    "aho-corasick",
    "memchr",
    "regex-automata",
    "regex-syntax",
    ]
    [[package]]
    name = "regex-automata"
    version = "0.4.5"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd"
    dependencies = [
    "aho-corasick",
    "memchr",
    "regex-syntax",
    ]
    [[package]]
    name = "regex-syntax"
    version = "0.8.2"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
    [[package]]
    name = "same-file"
    version = "1.0.6"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
    dependencies = [
    "winapi-util",
  • edit in Cargo.lock at line 402
    [10.2913]
    [13.5238]
    [[package]]
    name = "unicode-xid"
    version = "0.2.4"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
    [[package]]
    name = "walkdir"
    version = "2.4.0"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee"
    dependencies = [
    "same-file",
    "winapi-util",
    ]
    [[package]]
    name = "wax"
    version = "0.6.0"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "8d12a78aa0bab22d2f26ed1a96df7ab58e8a93506a3e20adb47c51a93b4e1357"
    dependencies = [
    "const_format",
    "itertools",
    "nom",
    "pori",
    "regex",
    "thiserror",
    "walkdir",
    ]
    [[package]]
    name = "winapi"
    version = "0.3.9"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
    dependencies = [
    "winapi-i686-pc-windows-gnu",
    "winapi-x86_64-pc-windows-gnu",
    ]
    [[package]]
    name = "winapi-i686-pc-windows-gnu"
    version = "0.4.0"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
    [[package]]
    name = "winapi-util"
    version = "0.1.6"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596"
    dependencies = [
    "winapi",
    ]
  • edit in Cargo.lock at line 460
    [13.5251]
    [13.5251]
    name = "winapi-x86_64-pc-windows-gnu"
    version = "0.4.0"
    source = "registry+https://github.com/rust-lang/crates.io-index"
    checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
    [[package]]