Skip to content

adsysd: load translations before building the commands - #1526

Open
maksimtech wants to merge 2 commits into
ubuntu:mainfrom
maksimtech:fix/i18n-before-command-construction
Open

maksimtech wants to merge 2 commits into
ubuntu:mainfrom
maksimtech:fix/i18n-before-command-construction

Conversation

@maksimtech

Copy link
Copy Markdown
Contributor

Summary

i18n.InitI18nDomain ran in run(), after client.New() / daemon.New() had already built the cobra commands. Every description going through gotext.Get() at construction time was captured in English, so --help ignored the user locale.

This moves the initialisation to the top of main(), before the commands are built.

Fixes #656

Testing

Written test-first: TestMainAppLocalizedHelp runs both adsysctl --help and adsysd --help with LANGUAGE=fr through the existing ADSYS_CALL_MAIN mechanism 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 to po/fr.po for that purpose.

go test ./cmd/adsysd passes with and without -race; golangci-lint reports no issue.

🤖 Generated with Claude Code

@maksimtech
maksimtech requested a review from a team as a code owner October 8, 2026 17:18
@denisonbarbosa

Copy link
Copy Markdown
Member

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-commenter

codecov-commenter commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.46%. Comparing base (82d1ee3) to head (a510caa).
⚠️ Report is 7 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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>
@maksimtech
maksimtech force-pushed the fix/i18n-before-command-construction branch from 70ab7f0 to 860e13b Compare October 15, 2026 18:22
@maksimtech

Copy link
Copy Markdown
Contributor Author

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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() to main().
  • 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

Comment thread cmd/adsysd/main_test.go
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")
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

Successfully merging this pull request may close these issues.

Unlocalized command line options

4 participants