l10n: Add full clap localization for help template #9327
+183
−91
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I chose to create a draft and not a PR because the changes are mainly to uucore but would need to be applied to all packages one by one.
Before doing this task, I prefer waiting for a validation on the changes of uucore.
It's my first PR ever so don't hesitate to correct me if my way of doing this is wrong or if you need me to add more documentation or testing etc.
This draft focus on making the clap localization system more complete :
--helpand--versionby using the locale id from uccore which would fix l10n: text for--help&--versionoptions is not localized #8923 and would also clean the many instances of manual writing of help and version texts.I also deleted the
configure_localized_command()function because it seems to be a legacy function that is used in some packages but is now replaced by.help_template(uucore::localized_help_template())(and with my draft, it would ultimately be replaced by.localize_help_template()).Caveats
The main problem is that my functions are position dependant in
uu_app()..localize_help_and_version()must be called after all arguments or it won't appear as the last options in the help text..localize_help_template(), there is no way to localize at compile time so it checks what type of argument is present and print the section title accordingly but for the checks to be valid, the arguments must be set before..help_localized(), if the default value is not set before calling the function then the default values won't be displayed.Not really a problem but could lead to incomprehensible bugs without knowing how it works.
Testing
I've arbitrarily chosen
split,truncateandwhoamias test for my localization system.Built with no error using
cargo build -p uu_split -p uu_truncate -p uu_whoami.Tested all 3 packages with french locale and it works.
Also tested with
LANG=en_USandLANG=zh_CNto check if english works and if the fallback was supported.Also ran
cargo nextest run -p uucore -p uu_split -p uu_truncate -p uu_whoami --no-fail-fastwith no fail.Result
Example with split :