From 6853f280edd64b528726ad8b703253dfe3792e73 Mon Sep 17 00:00:00 2001 From: Goutte Date: Tue, 4 Apr 2023 04:34:22 +0200 Subject: [PATCH] feat(i18n): translate command error and usage tip --- command.go | 2 +- localizer.go | 10 +++++++++- translations/{main.en.toml => active.en.toml} | 0 translations/{main.fr.toml => active.fr.toml} | 0 4 files changed, 10 insertions(+), 2 deletions(-) rename translations/{main.en.toml => active.en.toml} (100%) rename translations/{main.fr.toml => active.fr.toml} (100%) diff --git a/command.go b/command.go index 2fbe6c13..237d2238 100644 --- a/command.go +++ b/command.go @@ -1096,7 +1096,7 @@ func (c *Command) ExecuteC() (cmd *Command, err error) { } if !c.SilenceErrors { c.PrintErrln(c.ErrPrefix(), err.Error()) - c.PrintErrf("Run '%v --help' for usage.\n", c.CommandPath()) + c.PrintErrf(i18nRunHelpTip()+"\n", c.CommandPath()) } return c, err } diff --git a/localizer.go b/localizer.go index 037c407e..9a563ecc 100644 --- a/localizer.go +++ b/localizer.go @@ -35,6 +35,14 @@ func i18nError() string { }) } +func i18nRunHelpTip() string { + return localizeMessage(&i18n.Message{ + ID: "RunHelpTip", + Description: "tip shown when a command fails (command path)", + Other: "Run '%v --help' for usage.", + }) +} + func i18nExclusiveFlagsValidationError() string { return localizeMessage(&i18n.Message{ ID: "ExclusiveFlagsValidationError", @@ -58,7 +66,7 @@ func localizeMessage(message *i18n.Message) string { func loadTranslationFiles(bundle *i18n.Bundle, langs []string) { for _, lang := range langs { - _, _ = bundle.LoadMessageFileFS(localeFS, fmt.Sprintf("translations/main.%s.toml", lang)) + _, _ = bundle.LoadMessageFileFS(localeFS, fmt.Sprintf("translations/active.%s.toml", lang)) } } diff --git a/translations/main.en.toml b/translations/active.en.toml similarity index 100% rename from translations/main.en.toml rename to translations/active.en.toml diff --git a/translations/main.fr.toml b/translations/active.fr.toml similarity index 100% rename from translations/main.fr.toml rename to translations/active.fr.toml