-
Notifications
You must be signed in to change notification settings - Fork 32
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
Compile time checks #63
Labels
enhancement
New feature or request
Comments
This was referenced Oct 1, 2024
Can we implement this by parsing all the Rust source code, and for the macro invocation, check if its This should work for code like: t!("translation key"); However, usages like: use rust_i18n::t as the_t_macro;
the_t_macro!("translation key"); and let translation_key = "translation key";
rust_i18n::t!(translation_key); need us to do more things with the AST. |
I gave this a go today, in Topgrade's locale file checker: $ ./topgrade_i18n_locale_file_checker --locale-file ../topgrade/locales/app.yml --rust-src-to-check ../topgrade/src
Errors Found:
UseOfKeysDoNotExist
file '../topgrade/src/self_update.rs' / line '52' / column '27' / key 'Respawning...'
file '../topgrade/src/steps/os/windows.rs' / line '202' / column '21' / key 'Could not find Topgrade in any WSL disribution'
file '../topgrade/src/steps/os/windows.rs' / line '209' / column '20' / key 'Windows Update'
file '../topgrade/src/main.rs' / line '488' / column '19' / key '\n(R)eboot\n(S)hell\n(Q)uit' It works well, though I am not sure if we can do this in |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I didn't find any information about compile-time checks. If message in locale file is missing then string passed to macro will be displayed:
rust-i18n/crates/macro/src/lib.rs
Lines 183 to 186 in ba2c7cb
Will it be hard to create a separate macro or add option for
t!()
to make sure the message I use exists in the locale file at compile time (like sqlxquery!
does)? This can be tricky, so maybe an easier way is to create xtask (or test) to check that all the messages I'm using in the code are defined. This way it can be easily integrated with CI.All I want to achieve is if my app has passed CI, the locale files will have the appropriate content and the user won't see "en.wron_mesag".
Probably internationalization-rs can be used to see how they achieve compile time verification (using build.rs).
The text was updated successfully, but these errors were encountered: