Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Messages and terms with the same names #371

Open
kgv opened this issue Sep 8, 2024 · 1 comment
Open

Messages and terms with the same names #371

kgv opened this issue Sep 8, 2024 · 1 comment
Labels
bug crate:fluent-bundle Issues related to fluent-bundle crate

Comments

@kgv
Copy link
Contributor

kgv commented Sep 8, 2024

For js implementation it is possible: context_test.js#L46
But for rs implementation it throws error:

let mut bundle = FluentBundle::new_concurrent(vec![langid!("en")]);
bundle
    .add_resource(
        FluentResource::try_new(
            "foo = Foo\\
                    -bar = Bar"
                .to_owned(),
        )
        .unwrap(),
    )
    .unwrap();
bundle.add_resource_overriding(
    FluentResource::try_new("-foo = Private Foo".to_owned()).unwrap(),
);
assert!(bundle.has_message("foo")); // assertion failed: bundle.has_message("foo")

Will this be implemented in fluent-rs?

@alerque
Copy link
Collaborator

alerque commented Sep 8, 2024

I'm somewhat surprised to find there are no fixtures anywhere that cover this. Has there been any discussion of that outside of the JS implementation? Does the reference implementation allow this as well as the production fluent.js one?

Also here is an MWE version slightly simplified from your example that just sets a message and a term in one go (and panics):

#!/usr/bin/env rust-script
//! ```cargo
//! [dependencies]
//! fluent = "0.16"
//! unic-langid = { version = "0.9", features = [ "macros" ] }
//! ```

use fluent::{FluentBundle, FluentResource};
use unic_langid::langid;

fn main() {
    let mut bundle = FluentBundle::new(vec![langid!("en")]);
    bundle
        .add_resource(FluentResource::try_new("foo = Foo\n-foo = Bar".to_owned()).unwrap())
        .unwrap();
    dbg!(bundle.get_message("foo"));
    //bundle.add_resource_overriding(FluentResource::try_new("-foo = Bar".to_owned()).unwrap());
    //assert!(bundle.has_message("foo"));
}

@alerque alerque added bug crate:fluent-bundle Issues related to fluent-bundle crate labels Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug crate:fluent-bundle Issues related to fluent-bundle crate
Projects
None yet
Development

No branches or pull requests

2 participants