From 52f02ad9b9822aacdbb8b92fc76c3c132e0e9a71 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Sat, 30 Aug 2025 10:46:09 +0200 Subject: [PATCH] translate: support usage translations See https://git.coopcloud.tech/toolshed/abra/issues/628 --- cli/run.go | 31 +++++++++++++++- pkg/i18n/locales/abra.pot | 68 ++++++++++++++++++++++++----------- pkg/i18n/locales/es.po | 76 ++++++++++++++++++++++++++++----------- 3 files changed, 134 insertions(+), 41 deletions(-) diff --git a/cli/run.go b/cli/run.go index 01b490bd..97287103 100644 --- a/cli/run.go +++ b/cli/run.go @@ -19,6 +19,35 @@ import ( "github.com/spf13/cobra/doc" ) +var ( + // translators: `abra` usage template. please translate only words like + // "Aliases" and "Example" and nothing inside the {{ ... }} + usageTemplate = i18n.G(`Usage:{{if .Runnable}} + {{.UseLine}}{{end}}{{if .HasAvailableSubCommands}} + {{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}} + +Aliases: + {{.NameAndAliases}}{{end}}{{if .HasExample}} + +Examples: +{{.Example}}{{end}}{{if .HasAvailableSubCommands}} + +Available Commands:{{range .Commands}}{{if (or .IsAvailableCommand (eq .Name "help"))}} + {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}} + +Flags: +{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}} + +Global Flags: +{{.InheritedFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasHelpSubCommands}} + +Additional help topics:{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}} + {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}} + +Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}} +`) +) + func Run(version, commit string) { rootCmd := &cobra.Command{ // translators: `abra` binary name @@ -35,7 +64,6 @@ func Run(version, commit string) { i18n.G("server"), i18n.G("upgrade"), }, - PersistentPreRunE: func(cmd *cobra.Command, args []string) error { dirs := []map[string]os.FileMode{ {config.ABRA_DIR: 0764}, @@ -78,6 +106,7 @@ func Run(version, commit string) { } rootCmd.CompletionOptions.DisableDefaultCmd = true + rootCmd.SetUsageTemplate(usageTemplate) manCommand := &cobra.Command{ // translators: `man` command diff --git a/pkg/i18n/locales/abra.pot b/pkg/i18n/locales/abra.pot index 7ffbb978..01f5f422 100644 --- a/pkg/i18n/locales/abra.pot +++ b/pkg/i18n/locales/abra.pot @@ -7,7 +7,7 @@ msgid "" msgstr "Project-Id-Version: \n" "Report-Msgid-Bugs-To: EMAIL\n" - "POT-Creation-Date: 2025-08-29 16:31+0200\n" + "POT-Creation-Date: 2025-08-30 10:45+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -43,7 +43,7 @@ msgid " # fetch from recipe catalogue\n" " abra recipe fetch gitea --ssh" msgstr "" -#: ./cli/run.go:88 +#: ./cli/run.go:117 msgid " # generate the man pages into /usr/local/share/man/man1\n" " abra_path=$(which abra) # pass abra absolute path to sudo below\n" " sudo $abra_path man\n" @@ -826,7 +826,7 @@ msgid "Generate labels for the main recipe service.\n" msgstr "" #. translators: Short description for `man` command -#: ./cli/run.go:87 +#: ./cli/run.go:116 msgid "Generate manpage" msgstr "" @@ -1232,7 +1232,7 @@ msgid "The Co-op Cloud auto-updater πŸ€– πŸš€" msgstr "" #. translators: Short description for `abra` binary -#: ./cli/run.go:27 +#: ./cli/run.go:56 msgid "The Co-op Cloud command-line utility belt πŸŽ©πŸ‡" msgstr "" @@ -1425,6 +1425,34 @@ msgstr "" msgid "Upgrade recipe image tags" msgstr "" +#. translators: `abra` usage template. please translate only words like +#. "Aliases" and "Example" and nothing inside the {{ ... }} +#: ./cli/run.go:25 +msgid "Usage:{{if .Runnable}}\n" + " {{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}\n" + " {{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}}\n" + "\n" + "Aliases:\n" + " {{.NameAndAliases}}{{end}}{{if .HasExample}}\n" + "\n" + "Examples:\n" + "{{.Example}}{{end}}{{if .HasAvailableSubCommands}}\n" + "\n" + "Available Commands:{{range .Commands}}{{if (or .IsAvailableCommand (eq .Name \"help\"))}}\n" + " {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}\n" + "\n" + "Flags:\n" + "{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}}\n" + "\n" + "Global Flags:\n" + "{{.InheritedFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasHelpSubCommands}}\n" + "\n" + "Additional help topics:{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}}\n" + " {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}}\n" + "\n" + "Use \"{{.CommandPath}} [command] --help\" for more information about a command.{{end}}\n" +msgstr "" + #: ./cli/recipe/release.go:320 msgid "Use release note in release/next?" msgstr "" @@ -1523,7 +1551,7 @@ msgid "aborting as requested" msgstr "" #. translators: `abra` binary name -#: ./cli/run.go:25 +#: ./cli/run.go:54 msgid "abra [cmd] [args] [flags]" msgstr "" @@ -1531,7 +1559,7 @@ msgstr "" msgid "abra app labels 1312.net" msgstr "" -#: ./cli/run.go:71 +#: ./cli/run.go:99 #, c-format msgid "abra version: %s, commit: %s, lang: %s" msgstr "" @@ -1600,7 +1628,7 @@ msgstr "" msgid "ambiguous service list received, prompting for input" msgstr "" -#: ./cli/run.go:30 +#: ./cli/run.go:59 msgid "app" msgstr "" @@ -1657,7 +1685,7 @@ msgstr "" msgid "attempting to scale %s to 1" msgstr "" -#: ./cli/run.go:31 +#: ./cli/run.go:60 msgid "autocomplete" msgstr "" @@ -1817,7 +1845,7 @@ msgstr "" msgid "cannot use [version] and --latest together" msgstr "" -#: ./cli/run.go:32 +#: ./cli/run.go:61 msgid "catalogue" msgstr "" @@ -2273,7 +2301,7 @@ msgstr "" msgid "domain name for app" msgstr "" -#: ./cli/run.go:112 +#: ./cli/run.go:141 msgid "don't forget to run 'sudo mandb'" msgstr "" @@ -3180,12 +3208,12 @@ msgstr "" msgid "malformed version pin specification: %s" msgstr "" -#: ./cli/run.go:33 +#: ./cli/run.go:62 msgid "man" msgstr "" #. translators: `man` command -#: ./cli/run.go:84 +#: ./cli/run.go:113 msgid "man [flags]" msgstr "" @@ -3635,7 +3663,7 @@ msgstr "" msgid "polling undeploy status" msgstr "" -#: ./cli/run.go:137 +#: ./cli/run.go:166 msgid "prefer offline & filesystem access" msgstr "" @@ -3760,7 +3788,7 @@ msgstr "" msgid "readme: %s, " msgstr "" -#: ./cli/app/list.go:298 ./cli/app/list.go:305 ./cli/run.go:34 +#: ./cli/app/list.go:298 ./cli/app/list.go:305 ./cli/run.go:63 msgid "recipe" msgstr "" @@ -4157,7 +4185,7 @@ msgstr "" msgid "secrets are %s shown again, please save them %s" msgstr "" -#: ./cli/app/list.go:321 ./cli/app/list.go:328 ./cli/app/new.go:328 ./cli/app/new.go:335 ./cli/run.go:35 +#: ./cli/app/list.go:321 ./cli/app/list.go:328 ./cli/app/new.go:328 ./cli/app/new.go:335 ./cli/run.go:64 msgid "server" msgstr "" @@ -4273,7 +4301,7 @@ msgstr "" msgid "show apps of a specific server" msgstr "" -#: ./cli/run.go:121 ./cli/updater/updater.go:499 +#: ./cli/run.go:150 ./cli/updater/updater.go:499 msgid "show debug messages" msgstr "" @@ -4547,7 +4575,7 @@ msgstr "" msgid "tmpfs options are incompatible with type volume" msgstr "" -#: ./cli/run.go:129 ./cli/updater/updater.go:507 +#: ./cli/run.go:158 ./cli/updater/updater.go:507 msgid "toggle non-interactive mode" msgstr "" @@ -4623,7 +4651,7 @@ msgstr "" msgid "unable to convert to JSON: %s" msgstr "" -#: ./cli/run.go:51 +#: ./cli/run.go:79 #, c-format msgid "unable to create %s: %s" msgstr "" @@ -4712,7 +4740,7 @@ msgstr "" msgid "unable to parse '%s' value as bool: %s" msgstr "" -#: ./cli/run.go:104 +#: ./cli/run.go:133 #, c-format msgid "unable to proceed, %s does not exist?" msgstr "" @@ -4891,7 +4919,7 @@ msgstr "" msgid "updating %s to %s in %s" msgstr "" -#: ./cli/run.go:36 +#: ./cli/run.go:65 msgid "upgrade" msgstr "" diff --git a/pkg/i18n/locales/es.po b/pkg/i18n/locales/es.po index 13c94f48..f11c2499 100644 --- a/pkg/i18n/locales/es.po +++ b/pkg/i18n/locales/es.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: EMAIL\n" -"POT-Creation-Date: 2025-08-29 16:31+0200\n" +"POT-Creation-Date: 2025-08-30 10:45+0200\n" "PO-Revision-Date: 2025-08-29 08:00+0000\n" "Last-Translator: chasqui \n" "Language-Team: Spanish