Repository navigation
adsysd: load translations before building the commands - #1526
maksimtech wants to merge 2 commits into
Conversation
|
Hey, @maksimtech. Thanks for taking the time to contribute to adsys; we appreciate the help! The changes look good to me, but please make sure your commits are properly signed and verified. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1526 +/- ##
=======================================
Coverage 85.45% 85.46%
=======================================
Files 99 99
Lines 13213 13213
=======================================
+ Hits 11291 11292 +1
+ Misses 1919 1918 -1
Partials 3 3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
i18n was initialised in run(), after client.New() or daemon.New() had already built the cobra commands. Every description passed through gotext.Get() at construction time was therefore captured in English, and --help ignored the user locale. Initialise the translation domain first thing in main(), and cover it with a test running both binaries with LANGUAGE=fr. The French translation of the root command descriptions is added for that purpose. Fixes ubuntu#656 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
70ab7f0 to
860e13b
Compare
|
Thanks! The commits are now signed with my GPG key and show as Verified; I re-signed my other open PRs (#1521, #1522, #1523, #1525) the same way. About the red Code sanity check: it fails at govulncheck on GO-2026-6617 in golang.org/x/net v0.58.0 (fixed in v0.60.0), which fails on main as well since #1524, so the Tests job is skipped on these PRs. I kept the PRs focused and did not touch the dependency. |
There was a problem hiding this comment.
🟡 Changes recommended
The new test depends on embedded catalogs unavailable in clean Debian withmo builds.
1 open issue
What changed in this PR
Initializes translations before constructing ADSys commands so help descriptions respect the user’s locale, addressing #656.
Changes:
- Moves translation initialization from
run()tomain(). - Adds French help regression tests for both executables.
- Translates four French root-command descriptions.
| File | Description |
|---|---|
| po/fr.po | Adds French root-command translations. |
| cmd/adsysd/main.go | Loads translations before command construction. |
| cmd/adsysd/main_test.go | Checks localized client and daemon help. |
Review effort: Balanced
| cmd.Env = append(os.Environ(), "ADSYS_CALL_MAIN=1", "ADSYS_MAIN_ARGV0="+tc.argv0, "LANGUAGE=fr") | ||
| out, err := cmd.CombinedOutput() | ||
| require.NoError(t, err, "Main should not return an error: %s", out) | ||
| require.Contains(t, string(out), tc.wantHelp, "Help should be printed in the language selected by the environment") |

Summary
i18n.InitI18nDomainran inrun(), afterclient.New()/daemon.New()had already built the cobra commands. Every description going throughgotext.Get()at construction time was captured in English, so--helpignored the user locale.This moves the initialisation to the top of
main(), before the commands are built.Fixes #656
Testing
Written test-first:
TestMainAppLocalizedHelpruns bothadsysctl --helpandadsysd --helpwithLANGUAGE=frthrough the existingADSYS_CALL_MAINmechanism and expects the French root description. It failed before the change and passes after it. The French translations of the four root command strings were added topo/fr.pofor that purpose.go test ./cmd/adsysdpasses with and without-race; golangci-lint reports no issue.🤖 Generated with Claude Code