feat(i18n): translate more user-facing messages

This commit is contained in:
Goutte 2023-04-04 10:33:43 +02:00
parent 0abea784c4
commit ca6ece94df
4 changed files with 202 additions and 12 deletions

View file

@ -759,7 +759,7 @@ func (c *Command) findSuggestions(arg string) string {
}
suggestionsString := ""
if suggestions := c.SuggestionsFor(arg); len(suggestions) > 0 {
suggestionsString += "\n\nDid you mean this?\n"
suggestionsString += "\n\n" + i18nDidYouMeanThis() + "\n"
for _, s := range suggestions {
suggestionsString += fmt.Sprintf("\t%v\n", s)
}
@ -880,7 +880,7 @@ func (c *Command) execute(a []string) (err error) {
}
if len(c.Deprecated) > 0 {
c.Printf("Command %q is deprecated, %s\n", c.Name(), c.Deprecated)
c.Printf(i18nCommandDeprecatedWarning()+"\n", c.Name(), c.Deprecated)
}
// initialize help and version flag at the last point possible to allow for user
@ -1165,7 +1165,7 @@ func (c *Command) ValidateRequiredFlags() error {
})
if len(missingFlagNames) > 0 {
return fmt.Errorf(`required flag(s) "%s" not set`, strings.Join(missingFlagNames, `", "`))
return fmt.Errorf(i18nFlagNotSetError(len(missingFlagNames)), strings.Join(missingFlagNames, `", "`))
}
return nil
}
@ -1189,9 +1189,9 @@ func (c *Command) checkCommandGroups() {
func (c *Command) InitDefaultHelpFlag() {
c.mergePersistentFlags()
if c.Flags().Lookup("help") == nil {
usage := "help for "
usage := i18nHelpFor() + " "
if c.Name() == "" {
usage += "this command"
usage += i18nThisCommand()
} else {
usage += c.Name()
}
@ -1211,9 +1211,9 @@ func (c *Command) InitDefaultVersionFlag() {
c.mergePersistentFlags()
if c.Flags().Lookup("version") == nil {
usage := "version for "
usage := i18nVersionFor() + " "
if c.Name() == "" {
usage += "this command"
usage += i18nThisCommand()
} else {
usage += c.Name()
}
@ -1236,10 +1236,9 @@ func (c *Command) InitDefaultHelpCmd() {
if c.helpCommand == nil {
c.helpCommand = &Command{
Use: "help [command]",
Short: "Help about any command",
Long: `Help provides help for any command in the application.
Simply type ` + c.Name() + ` help [path to command] for full details.`,
Use: fmt.Sprintf("help [%s]", i18nCommand()),
Short: i18nCommandHelpShort(),
Long: fmt.Sprintf(i18nCommandHelpLong(), c.Name()+fmt.Sprintf(" help [%s]", i18nPathToCommand())),
ValidArgsFunction: func(c *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
var completions []string
cmd, _, e := c.Root().Find(args)
@ -1262,7 +1261,7 @@ Simply type ` + c.Name() + ` help [path to command] for full details.`,
Run: func(c *Command, args []string) {
cmd, _, e := c.Root().Find(args)
if cmd == nil || e != nil {
c.Printf("Unknown help topic %#q\n", args)
c.Printf(i18nCommandHelpUnknownTopicError()+"\n", args)
CheckErr(c.Root().Usage())
} else {
cmd.InitDefaultHelpFlag() // make possible 'help' flag to be shown

View file

@ -140,6 +140,87 @@ func i18nForInfoAboutCommand() string {
})
}
func i18nCommand() string {
return localizeMessage(&i18n.Message{
ID: "Command",
Description: "lowercase",
Other: "command",
})
}
func i18nPathToCommand() string {
return localizeMessage(&i18n.Message{
ID: "PathToCommand",
Description: "lowercase",
Other: "path to command",
})
}
func i18nCommandHelpShort() string {
return localizeMessage(&i18n.Message{
ID: "CommandHelpShort",
Description: "short help for command help",
Other: "Help about any command",
})
}
func i18nCommandHelpLong() string {
return localizeMessage(&i18n.Message{
ID: "CommandHelpLong",
Description: "long help for command help (cmd example)",
Other: `Help provides help for any command in the application.
Simply type %s for full details.`,
})
}
func i18nCommandHelpUnknownTopicError() string {
return localizeMessage(&i18n.Message{
ID: "CommandHelpUnknownTopicError",
Description: "shown when help topic is unknown (args)",
Other: "Unknown help topic %#q",
})
}
func i18nHelpFor() string {
return localizeMessage(&i18n.Message{
ID: "HelpFor",
Description: "lowercase, beginning of sentence",
Other: "help for",
})
}
func i18nVersionFor() string {
return localizeMessage(&i18n.Message{
ID: "VersionFor",
Description: "lowercase, beginning of sentence",
Other: "version for",
})
}
func i18nThisCommand() string {
return localizeMessage(&i18n.Message{
ID: "ThisCommand",
Description: "lowercase, end of sentence, used when command name is undefined",
Other: "this command",
})
}
func i18nDidYouMeanThis() string {
return localizeMessage(&i18n.Message{
ID: "DidYouMeanThis",
Description: "shown as suggestion",
Other: "Did you mean this?",
})
}
func i18nCommandDeprecatedWarning() string {
return localizeMessage(&i18n.Message{
ID: "CommandDeprecatedWarning",
Description: "printed when a deprecated command is executed (cmd, deprecation message)",
Other: "Command %q is deprecated, %s",
})
}
func i18nError() string {
return localizeMessage(&i18n.Message{
ID: "Error",
@ -224,6 +305,15 @@ func i18nExclusiveFlagsValidationError() string {
})
}
func i18nFlagNotSetError(amountFlags int) string {
return localizeMessageWithPlural(&i18n.Message{
ID: "FlagNotSetError",
Description: "error shown when required flags are not set (flags)",
Other: "required flags \"%s\" are not set",
One: "required flag \"%s\" is not set",
}, amountFlags)
}
// … lots more translations here
func localizeMessage(message *i18n.Message) string {

View file

@ -1,3 +1,27 @@
[Command]
description = "lowercase"
other = "command"
[CommandDeprecatedWarning]
description = "printed when a deprecated command is executed (cmd, deprecation message)"
other = "Command %q is deprecated, %s"
[CommandHelpLong]
description = "long help for command help (cmd example)"
other = "Help provides help for any command in the application.\nSimply type %s for full details."
[CommandHelpShort]
description = "short help for command help"
other = "Help about any command"
[CommandHelpUnknownTopicError]
description = "shown when help topic is unknown (args)"
other = "Unknown help topic %#q"
[DidYouMeanThis]
description = "shown as suggestion"
other = "Did you mean this?"
[Error]
description = "prefix of error messages"
other = "Error"
@ -11,10 +35,19 @@ other = "accepts %d args, received %d"
description = "error shown when multiple exclusive flags are provided (group flags, offending flags)"
other = "if any flags in the group [%v] are set none of the others can be; %v were all set"
[FlagNotSetError]
description = "error shown when required flags are not set (flags)"
one = "required flag \"%s\" is not set"
other = "required flags \"%s\" are not set"
[ForInfoAboutCommand]
description = "end of a sentence"
other = "for more information about a command"
[HelpFor]
description = "lowercase, beginning of sentence"
other = "help for"
[LegacyArgsValidationError]
description = "error shown when args are not understood (subcmd, cmd, suggestion)"
other = "unknown command %q for %q%s"
@ -37,6 +70,10 @@ other = "unknown command %q for %q"
description = "error shown when arg is invalid (arg, cmd, suggestion)"
other = "invalid argument %q for %q%s"
[PathToCommand]
description = "lowercase"
other = "path to command"
[RangeArgsValidationError]
description = "error shown when arg count is not in range (expected min, expected max, actual amount)"
one = "accepts between %d and %d arg, received %d"
@ -78,6 +115,14 @@ other = "Global Flags"
description = "title of the section in the usage template"
other = "Usage"
[ThisCommand]
description = "lowercase, end of sentence, used when command name is undefined"
other = "this command"
[Use]
description = "beginning of a sentence like 'Use <this> to do <that>'"
other = "Use"
[VersionFor]
description = "lowercase, beginning of sentence"
other = "version for"

View file

@ -1,3 +1,33 @@
[Command]
description = "lowercase"
hash = "sha1-c90bde9bb93ee6452afbe579d55cd32ba0159c8d"
other = "commande"
[CommandDeprecatedWarning]
description = "printed when a deprecated command is executed (cmd, deprecation message)"
hash = "sha1-e8b974a255eafe86d4a4fe15a0e79aaab345354c"
other = "La commande %q est dépréciée, %s"
[CommandHelpLong]
description = "long help for command help (cmd example)"
hash = "sha1-dc993d9f12d54910147c477318fa82c8210b6669"
other = "Help fournit de l'aide pour n'importe quelle commande de l'application.\nTapez '%s' pour obtenir une aide détaillée."
[CommandHelpShort]
description = "short help for command help"
hash = "sha1-5bab4a463f36ea8e33681f523445bbd614e9891c"
other = "Obtenir de l'aide au sujet d'une commande"
[CommandHelpUnknownTopicError]
description = "shown when help topic is unknown (args)"
hash = "sha1-d3b6cb615eee5770e0e8e62fbf7a3293502dd7a8"
other = "Sujet d'aide %#q inconnu"
[DidYouMeanThis]
description = "shown as suggestion"
hash = "sha1-eb9504fe384499caafe690853204c7fb7ac8b531"
other = "Vouliez-vous dire ceci ?"
[Error]
description = "prefix of error messages"
hash = "sha1-7dcb56355a3ddc7ff7e5ccd6522507999ca7f238"
@ -14,11 +44,22 @@ description = "error shown when multiple exclusive flags are provided (group fla
hash = "sha1-221b98bada52cfc2932f9aa5142b653b46baded6"
other = "les options [%v] sont exclusives, mais les options %v ont été fournies"
[FlagNotSetError]
description = "error shown when required flags are not set (flags)"
hash = "sha1-f5340c4bfceb0066ec70944b57e6458b6f8cc97b"
one = "l'option requise \"%s\" n'est pas présente"
other = "les options requises \"%s\" ne sont pas présentes"
[ForInfoAboutCommand]
description = "end of a sentence"
hash = "sha1-923f6d48908b3a6981fb5504b0e5078700a312c0"
other = "pour plus d'information au sujet d'une commande"
[HelpFor]
description = "lowercase, beginning of sentence"
hash = "sha1-18fbe8d2780935dbe6a71f998821c22f283cbd25"
other = "aide pour"
[LegacyArgsValidationError]
description = "error shown when args are not understood (subcmd, cmd, suggestion)"
hash = "sha1-c601c68bdcb9687109e793112b789b1858953b15"
@ -46,6 +87,11 @@ description = "error shown when arg is invalid (arg, cmd, suggestion)"
hash = "sha1-60b40e5782dd252c78ef3d585065cb99197ec22e"
other = "argument %q invalide pour %q%s"
[PathToCommand]
description = "lowercase"
hash = "sha1-7dcca04d5dcb7ff289a5483bea3e4f1e4119c1f4"
other = "commande"
[RangeArgsValidationError]
description = "error shown when arg count is not in range (expected min, expected max, actual amount)"
hash = "sha1-aa81e0aee17a3439b479cdf47169eb194706cd14"
@ -97,7 +143,17 @@ description = "title of the section in the usage template"
hash = "sha1-5fdae7bd171315a453063384887ee4300363cf20"
other = "Usage"
[ThisCommand]
description = "lowercase, end of sentence, used when command name is undefined"
hash = "sha1-5cfa4629fdf18b89471b3d07a0d051a8a10afe70"
other = "cette commande"
[Use]
description = "beginning of a sentence like 'Use <this> to do <that>'"
hash = "sha1-f42c92acc9934eec952161dfa338a95ec0f02b75"
other = "Utilisez"
[VersionFor]
description = "lowercase, beginning of sentence"
hash = "sha1-e7f03028ab18076d111cd3343a24bbd8113d5431"
other = "version de"