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

enhancement: Access to attributes #19

Open
85oski opened this issue Feb 13, 2025 · 6 comments
Open

enhancement: Access to attributes #19

85oski opened this issue Feb 13, 2025 · 6 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@85oski
Copy link

85oski commented Feb 13, 2025

Hi, I have this en.ftl file:

categories = Categories
    .main = Main page
    .about-me = About me

When I try to get the content of e.g. categories.main via t!("categories.main"), I get an error in the console saying that no message with this id was found (message id not found for key: 'categories.main').

Is there a way to get the content of this translation? Or maybe I'm doing it the wrong way? Thank you in advance

@marc2332
Copy link
Member

What is home supposed to be? Its not included in your en.ftl

@marc2332 marc2332 self-assigned this Feb 13, 2025
@marc2332 marc2332 added the help wanted Extra attention is needed label Feb 13, 2025
@85oski
Copy link
Author

85oski commented Feb 13, 2025

@marc2332 Sorry. I meant categories.main.

@marc2332
Copy link
Member

marc2332 commented Feb 13, 2025

@85oski I think your fluent code is just wrong, this works:

categories =
    { $cat ->
        [main] Main page
        [about-me] About me
       *[default] Other
    }
let mut cat = use_signal(|| "main");

rsx!(
    p { { t!("categories", cat: *cat.read()) } }
    button {
        onclick: move |_| cat.set("main"),
        "Main"
    }
    button {
        onclick: move |_| cat.set("about-me"),
        "About Me"
    }
)

@85oski
Copy link
Author

85oski commented Feb 13, 2025

@marc2332 I wanted to use this syntax: https://projectfluent.org/fluent/guide/attributes.html.

I wanted to create a navigation bar with an h1 header with the content t!("categories") (Categories) and a list with links to various subpages, i.e. t!("categories.main") (Main page) and t!("categories.about-me") (About me). Sample code:

rsx! {
        div {
            h1 { {t!("categories")} }
            ul {
                li {
                    Link {
                        to: todo!(),
                        {t!("categories.main")}
                    }
                }
                li {
                    Link {
                        to: todo!(),
                        {t!("categories.about-me")}
                    }
                }
            }
        }
    }

@marc2332
Copy link
Member

@marc2332 I wanted to use this syntax: https://projectfluent.org/fluent/guide/attributes.html.

I wanted to create a navigation bar with an h1 header with the content t!("categories") (Categories) and a list with links to various subpages, i.e. t!("categories.main") (Main page) and t!("categories.about-me") (About me). Sample code:

rsx! {
div {
h1 { {t!("categories")} }
ul {
li {
Link {
to: todo!(),
{t!("categories.main")}
}
}
li {
Link {
to: todo!(),
{t!("categories.about-me")}
}
}
}
}
}

We don't support an easy access to the attributes, but anyway, you are using the wrong abstraction. Attributes are not variants, and what you want is precisely variants, I suggest you code I provided above

@marc2332 marc2332 changed the title Trying to get attribute enhancement: Access to attributes Feb 13, 2025
@85oski
Copy link
Author

85oski commented Feb 13, 2025

@marc2332 Okay, thank you. I will try to use the solution you suggested.

@marc2332 marc2332 added the enhancement New feature or request label Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants