fluent-rs icon indicating copy to clipboard operation
fluent-rs copied to clipboard

Why is this line hardcoded to a path?

Open Elsie19 opened this issue 11 months ago • 4 comments

https://github.com/projectfluent/fluent-rs/blob/f2033ce8340e09000ad9efccd6215b3fa5c23496/fluent-resmgr/src/resource_manager.rs#L174

It seems that if I try to change the path in my program to something like this:

.
├── broken
│   └── resources
│       ├── en-US
│       │   └── test.ftl
│       └── pl
├── Cargo.lock
├── Cargo.toml
└── src
    └── main.rs

I get this:

thread 'main' panicked at /home/henry/.cargo/registry/src/index.crates.io-6f17d22bba15001f/fluent-resmgr-0.0.7/src/resource_manager.rs:175:56:
called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

With this code:

use fluent_fallback::Localization;
use fluent_resmgr::ResourceManager;
use unic_langid::langid;

fn main() {
    let res_mgr = ResourceManager::new("./broken/resources/{locale}/".into());

    let loc = Localization::with_env(
        vec!["test.ftl".into()],
        true,
        vec![langid!("en-US")],
        res_mgr,
    );
    let bundles = loc.bundles();

    let mut errors = vec![];
    let value = bundles
        .format_value_sync("hello-world", None, &mut errors)
        .expect("Failed to format a value");

    println!("{}", value.unwrap());
}

Elsie19 avatar Dec 07 '24 01:12 Elsie19

I have been confused about this too. Wonder why this path is hardcoded. They already receive the path where sources can be found.

pvshvp-oss avatar Feb 10 '25 18:02 pvshvp-oss

It does look like some of the setup for the crate tests is leaking into the crate itself. If anybody has a suggestion/PR to fix this I'd facilitate it. So far I've only had time to look and confirm that this seems like an issue that should be fixed.

alerque avatar Feb 17 '25 12:02 alerque

This appears to be a symptom of the bundle generator only being mocked up, see #281 and the todo!() code in the module.

alerque avatar May 23 '25 09:05 alerque

My PR at #387 should minimally deal with this specific hard coding issue my actually re-using the path spec used to create the resource manager in the iterator. This stops short of actually implementing the stream or iterator ration methods as mentioned in #281, but it does remove the hard coded spec.

Your MWE does have one problem though, you are not including the expected field in your example. Changing it like this works for me in a sample project using [patch.crates-io] to use the Git branch instead of a released version.

-let res_mgr = ResourceManager::new("./broken/resources/{locale}/".into());
+let res_mgr = ResourceManager::new("./broken/resources/{locale}/{res_id}".into());

alerque avatar May 23 '25 10:05 alerque