Skip to content

Add localization support#362

Draft
mjcr99 wants to merge 4 commits intomainfrom
macano/add-localization-support
Draft

Add localization support#362
mjcr99 wants to merge 4 commits intomainfrom
macano/add-localization-support

Conversation

@mjcr99
Copy link
Contributor

@mjcr99 mjcr99 commented Feb 26, 2026

Description

Hi team, this PR implements the required changes to fully support localization, following are the key aspects covered:

  • snapcore/go-gettext has been chosen to implement the localization support.
  • Printable strings have been wrapped to allow the extraction of the rhc.pot file.
  • New rhc.pot file has been added.

* Card ID - CCT-151

Signed-off-by: mjcr99 <macano@redhat.com>
Assisted-By: Claude Code
@mjcr99 mjcr99 requested a review from m-horky February 26, 2026 11:50
facts, err := canonical_facts.GetCanonicalFacts()
if err != nil {
return cli.Exit(fmt.Errorf("cannot generate canonical facts: %v", err), 1)
return cli.Exit(fmt.Errorf(localization.TF("cannot generate canonical facts: %v", err)), 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can't be passing strings with variables already filled in, the string wouldn't match.

return cli.Exit(fmt.Errorf(localization.TF("cannot generate canonical facts: %v"), err), 1)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adressed in this commit: 8c6aabf

@m-horky
Copy link
Collaborator

m-horky commented Feb 27, 2026

Also please unlink CCT-148 from this PR/commit(s), we're doing it separately.

…its traslability

* Card ID - CCT-151

Signed-off-by: mjcr99 <macano@redhat.com>
Assisted-By: Claude Code
* Card ID - CCT-151

.pot file has been extracted using the following command:
xgettext --keyword=T --keyword=TF --keyword=TN:1,2 --keyword=TNF:1,2 \
	 --keyword=TC:1c,2 --keyword=TCF:1c,2 \
	 -o po/rhc.pot $(find cmd internal -type f -name "*.go" ! -name "*test*")

Signed-off-by: mjcr99 <macano@redhat.com>
* Card ID: CCT-151

After implementing localization support with go-gettext, the build was
failing with "non-constant format string" errors. Go's static analysis
tools (go vet) require format strings in functions like fmt.Errorf and
fmt.Printf to be compile-time constants, but localization.TF() returns
strings at runtime.

This commit fixes the issue by adjusting how translated strings are used:

- Replace fmt.Errorf(localization.TF(...)) with errors.New(localization.TF(...))
 Since TF() already handles formatting via fmt.Sprintf internally, we
 don't need fmt.Errorf's formatting capabilities. Using errors.New with
 the pre-formatted string avoids the constant requirement.

- Replace fmt.Printf(localization.TF(...)) with fmt.Print(localization.TF(...))
Similarly, TF() returns an already-formatted string, so we use Print
instead of Printf to avoid the format string validation.

- Replace ui.Printf(localization.TF(...)) with ui.Printf("%s", localization.TF(...))
Add an explicit format specifier to satisfy the constant requirement.
This approach is minimally invasive and preserves the T(), TF(), TN(),
and other localization function signatures unchanged, ensuring that
xgettext-based .pot file extraction continues to work correctly.

Signed-off-by: mjcr99 <macano@redhat.com>
Assisted-By: Claude Code
@mjcr99 mjcr99 force-pushed the macano/add-localization-support branch from 0794e0b to 8c6aabf Compare February 27, 2026 09:37
@mjcr99 mjcr99 requested a review from m-horky February 27, 2026 10:19
@mjcr99 mjcr99 marked this pull request as draft February 27, 2026 15:40
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.

2 participants