mirror of
https://github.com/spf13/cobra
synced 2024-11-24 22:57:12 +00:00
feat(i18n): translate command error and usage tip
This commit is contained in:
parent
ccbdd223d1
commit
6853f280ed
4 changed files with 10 additions and 2 deletions
|
@ -1096,7 +1096,7 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
|
||||||
}
|
}
|
||||||
if !c.SilenceErrors {
|
if !c.SilenceErrors {
|
||||||
c.PrintErrln(c.ErrPrefix(), err.Error())
|
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
|
return c, err
|
||||||
}
|
}
|
||||||
|
|
10
localizer.go
10
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 {
|
func i18nExclusiveFlagsValidationError() string {
|
||||||
return localizeMessage(&i18n.Message{
|
return localizeMessage(&i18n.Message{
|
||||||
ID: "ExclusiveFlagsValidationError",
|
ID: "ExclusiveFlagsValidationError",
|
||||||
|
@ -58,7 +66,7 @@ func localizeMessage(message *i18n.Message) string {
|
||||||
|
|
||||||
func loadTranslationFiles(bundle *i18n.Bundle, langs []string) {
|
func loadTranslationFiles(bundle *i18n.Bundle, langs []string) {
|
||||||
for _, lang := range langs {
|
for _, lang := range langs {
|
||||||
_, _ = bundle.LoadMessageFileFS(localeFS, fmt.Sprintf("translations/main.%s.toml", lang))
|
_, _ = bundle.LoadMessageFileFS(localeFS, fmt.Sprintf("translations/active.%s.toml", lang))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue