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

Make declare_locales! public #163

Open
Baptistemontan opened this issue Nov 9, 2024 · 0 comments
Open

Make declare_locales! public #163

Baptistemontan opened this issue Nov 9, 2024 · 0 comments

Comments

@Baptistemontan
Copy link
Owner

Baptistemontan commented Nov 9, 2024

This crate internally use a macro called declare_locales! which permit the declaration of translations directly in the code,
this macro was developed for the only need of unit tests and doctests, as those can't have configuration files (they probably could, but that is NOT convenient).

Basically instead of

# Cargo.toml
[package.metadata.leptos-i18n]
default = "en"
locales = ["en", "fr"]
{
    "key": "value"
}

you can have

declare_locales! {
    default: "en",
    locales: ["en", "fr"],
    en: {
        key: "value",
    },
    fr: {
        key: "value",
    },
}

and will produce the expected i18n module.

For now I'm not confortable "stabilizing" it, as some arguments are added when needed such as path wich let you set the path to the leptos_i18n crate, this is usefull for unit tests so it can be set as path: crate, or the interpolate_display argument to allow the output of the interpolate_display feature even if it is not enabled. I want the freedom to modify it as much as I want to accomodate tests.

But if some people are interested in using this macro let me know here, I would consider making it public.

For now if you want/need to use it, it is available with #[doc(hidden)] at leptos_i18n::declare_locales. But remember, it is still a "private"/internal item, and no guarantees are made with it. If you want to see some example of it's usage, you can check the macro.rs module and the doctests there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant