Parse group from fluent file specified by macro attribute

finchie
Feb 14, 2024, 2:53 PM
OCR4YRQ2LXK3PXSWPEWCBED4DFVMXZIF4RS35XQZSJ2D2KEIB2VQC

Dependencies

  • [2] QSK7JRBA Add simple `attribute_path` function
  • [3] UOMQT7LT Add support for cardinal CLDR plural selectors
  • [4] 5TEX4MNU Split `fluent_embed` into `group` and `parse` modules
  • [5] XGNME3WR Move `Group::derive_enum` to new `crate::parse_macro` module
  • [*] O77KA6C4 Create `fluent_embed` crate

Change contents

  • replacement in fluent_embed/src/parse_macro.rs at line 53
    [2.45][2.45:107]()
    pub fn attribute_path(attribute: syn::Attribute) -> PathBuf {
    [2.45]
    [2.107]
    pub fn attribute_groups(attribute: syn::Attribute) -> Group {
  • replacement in fluent_embed/src/parse_macro.rs at line 57
    [2.258][2.258:327]()
    let supplied_path = PathBuf::from(path_literal.value());
    [2.258]
    [2.327]
    // Read the fluent file at the given path
    let manifest_root = std::env::var("CARGO_MANIFEST_DIR").unwrap();
    let resource_path = PathBuf::from(manifest_root).join(path_literal.value());
    let fluent_contents = std::fs::read_to_string(resource_path).unwrap();
    // Parse the file into a `Group`
    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 67
    [2.328][2.328:461]()
    // TODO: path should be relative to source file, not working directory
    supplied_path.canonicalize().unwrap()
    [2.328]
    [3.1589]
    group
  • replacement in fluent_embed/src/lib.rs at line 6
    [3.3509][2.546:598]()
    pub use parse_macro::{attribute_path, derive_enum};
    [3.3509]
    pub use parse_macro::{attribute_groups, derive_enum};