From f01ca9e8b1d4c8ef567a632f79278ee98d3b23f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= Date: Thu, 5 Oct 2023 01:21:51 -0400 Subject: [PATCH] cmd/incus: Translate all strings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Graber --- cmd/incus/admin_recover.go | 6 +++--- cmd/incus/cluster.go | 14 +++++++------- cmd/incus/console_windows.go | 2 +- cmd/incus/create.go | 4 ++-- cmd/incus/export.go | 12 ++++++------ cmd/incus/file.go | 10 +++++----- cmd/incus/image.go | 6 +++--- cmd/incus/move.go | 2 +- cmd/incus/publish.go | 2 +- cmd/incus/storage_volume.go | 16 ++++++++-------- cmd/incus/utils.go | 2 +- cmd/incus/utils_properties.go | 6 +++--- 12 files changed, 41 insertions(+), 41 deletions(-) diff --git a/cmd/incus/admin_recover.go b/cmd/incus/admin_recover.go index 528f4586c94..794069f67e4 100644 --- a/cmd/incus/admin_recover.go +++ b/cmd/incus/admin_recover.go @@ -62,7 +62,7 @@ func (c *cmdAdminRecover) Run(cmd *cobra.Command, args []string) error { fmt.Println(i18n.G("This server currently has the following storage pools:")) for _, existingPool := range existingPools { - fmt.Printf(" - %s (backend=%q, source=%q)\n", existingPool.Name, existingPool.Driver, existingPool.Config["source"]) + fmt.Printf(" - "+i18n.G("%s (backend=%q, source=%q)")+"\n", existingPool.Name, existingPool.Driver, existingPool.Config["source"]) } unknownPools := make([]api.StoragePoolsPost, 0, len(existingPools)) @@ -150,11 +150,11 @@ func (c *cmdAdminRecover) Run(cmd *cobra.Command, args []string) error { fmt.Println(i18n.G("The recovery process will be scanning the following storage pools:")) for _, p := range existingPools { - fmt.Printf(" - EXISTING: %q (backend=%q, source=%q)\n", p.Name, p.Driver, p.Config["source"]) + fmt.Printf(" - "+i18n.G("EXISTING: %q (backend=%q, source=%q)")+"\n", p.Name, p.Driver, p.Config["source"]) } for _, p := range unknownPools { - fmt.Printf(" - NEW: %q (backend=%q, source=%q)\n", p.Name, p.Driver, p.Config["source"]) + fmt.Printf(" - "+i18n.G("NEW: %q (backend=%q, source=%q)")+"\n", p.Name, p.Driver, p.Config["source"]) } proceed, err := c.global.asker.AskBool(i18n.G("Would you like to continue with scanning for lost volumes?")+" (yes/no) [default=yes]: ", "yes") diff --git a/cmd/incus/cluster.go b/cmd/incus/cluster.go index b91cdd89116..8805e45e350 100644 --- a/cmd/incus/cluster.go +++ b/cmd/incus/cluster.go @@ -641,7 +641,7 @@ func (c *cmdClusterEnable) Run(cmd *cobra.Command, args []string) error { // Check if the server is available on the network. server, _, err := resource.server.GetServer() if err != nil { - return fmt.Errorf("Failed to retrieve current server config: %w", err) + return fmt.Errorf(i18n.G("Failed to retrieve current server config: %w"), err) } if server.Config["core.https_address"] == "" && server.Config["cluster.https_address"] == "" { @@ -651,7 +651,7 @@ func (c *cmdClusterEnable) Run(cmd *cobra.Command, args []string) error { // Check if already enabled currentCluster, etag, err := resource.server.GetCluster() if err != nil { - return fmt.Errorf("Failed to retrieve current cluster config: %w", err) + return fmt.Errorf(i18n.G("Failed to retrieve current cluster config: %w"), err) } if currentCluster.Enabled { @@ -664,12 +664,12 @@ func (c *cmdClusterEnable) Run(cmd *cobra.Command, args []string) error { req.Enabled = true op, err := resource.server.UpdateCluster(req, etag) if err != nil { - return fmt.Errorf("Failed to configure cluster: %w", err) + return fmt.Errorf(i18n.G("Failed to configure cluster: %w"), err) } err = op.Wait() if err != nil { - return fmt.Errorf("Failed to configure cluster: %w", err) + return fmt.Errorf(i18n.G("Failed to configure cluster: %w"), err) } fmt.Println(i18n.G("Clustering enabled")) @@ -839,7 +839,7 @@ func (c *cmdClusterAdd) Run(cmd *cobra.Command, args []string) error { opAPI := op.Get() joinToken, err := opAPI.ToClusterJoinToken() if err != nil { - return fmt.Errorf("Failed converting token operation to join token: %w", err) + return fmt.Errorf(i18n.G("Failed converting token operation to join token: %w"), err) } if !c.global.flagQuiet { @@ -1195,7 +1195,7 @@ func (c *cmdClusterEvacuateAction) Run(cmd *cobra.Command, args []string) error // Parse remote. resources, err := c.global.ParseServers(args[0]) if err != nil { - return fmt.Errorf("Failed to parse servers: %w", err) + return fmt.Errorf(i18n.G("Failed to parse servers: %w"), err) } resource := resources[0] @@ -1222,7 +1222,7 @@ func (c *cmdClusterEvacuateAction) Run(cmd *cobra.Command, args []string) error op, err := resource.server.UpdateClusterMemberState(resource.name, state) if err != nil { - return fmt.Errorf("Failed to update cluster member state: %w", err) + return fmt.Errorf(i18n.G("Failed to update cluster member state: %w"), err) } var format string diff --git a/cmd/incus/console_windows.go b/cmd/incus/console_windows.go index d49dfc8c479..6085b3a38b7 100644 --- a/cmd/incus/console_windows.go +++ b/cmd/incus/console_windows.go @@ -22,7 +22,7 @@ func (c *cmdConsole) controlSocketHandler(control *websocket.Conn) { // won't work quite correctly. err := c.sendTermSize(control) if err != nil { - fmt.Printf("error setting term size %s\n", err) + fmt.Printf(i18n.G("Error setting term size %s")+"\n", err) } } diff --git a/cmd/incus/create.go b/cmd/incus/create.go index d84323a2cf1..39a8250a582 100644 --- a/cmd/incus/create.go +++ b/cmd/incus/create.go @@ -173,7 +173,7 @@ func (c *cmdCreate) create(conf *config.Config, args []string) (incus.InstanceSe if c.flagNetwork != "" { network, _, err := d.GetNetwork(c.flagNetwork) if err != nil { - return nil, "", fmt.Errorf("Failed loading network %q: %w", c.flagNetwork, err) + return nil, "", fmt.Errorf(i18n.G("Failed loading network %q: %w"), c.flagNetwork, err) } // Prepare the instance's NIC device entry. @@ -224,7 +224,7 @@ func (c *cmdCreate) create(conf *config.Config, args []string) (incus.InstanceSe if c.flagStorage != "" { _, _, err := d.GetStoragePool(c.flagStorage) if err != nil { - return nil, "", fmt.Errorf("Failed loading storage pool %q: %w", c.flagStorage, err) + return nil, "", fmt.Errorf(i18n.G("Failed loading storage pool %q: %w"), c.flagStorage, err) } devicesMap["root"] = map[string]string{ diff --git a/cmd/incus/export.go b/cmd/incus/export.go index 5dc049de4c5..46568efdd14 100644 --- a/cmd/incus/export.go +++ b/cmd/incus/export.go @@ -77,7 +77,7 @@ func (c *cmdExport) Run(cmd *cobra.Command, args []string) error { op, err := d.CreateInstanceBackup(name, req) if err != nil { - return fmt.Errorf("Create instance backup: %w", err) + return fmt.Errorf(i18n.G("Create instance backup: %w"), err) } // Watch the background operation @@ -110,12 +110,12 @@ func (c *cmdExport) Run(cmd *cobra.Command, args []string) error { uStr := op.Get().Resources["backups"][0] u, err := url.Parse(uStr) if err != nil { - return fmt.Errorf("Invalid URL %q: %w", uStr, err) + return fmt.Errorf(i18n.G("Invalid URL %q: %w"), uStr, err) } backupName, err := url.PathUnescape(path.Base(u.EscapedPath())) if err != nil { - return fmt.Errorf("Invalid backup name segment in path %q: %w", u.EscapedPath(), err) + return fmt.Errorf(i18n.G("Invalid backup name segment in path %q: %w"), u.EscapedPath(), err) } defer func() { @@ -162,7 +162,7 @@ func (c *cmdExport) Run(cmd *cobra.Command, args []string) error { if err != nil { _ = os.Remove(targetName) progress.Done("") - return fmt.Errorf("Fetch instance backup file: %w", err) + return fmt.Errorf(i18n.G("Fetch instance backup file: %w"), err) } // Detect backup file type and rename file accordingly @@ -179,13 +179,13 @@ func (c *cmdExport) Run(cmd *cobra.Command, args []string) error { err = os.Rename(targetName, name+ext) if err != nil { - return fmt.Errorf("Failed to rename export file: %w", err) + return fmt.Errorf(i18n.G("Failed to rename export file: %w"), err) } } err = target.Close() if err != nil { - return fmt.Errorf("Failed to close export file: %w", err) + return fmt.Errorf(i18n.G("Failed to close export file: %w"), err) } progress.Done(i18n.G("Backup exported successfully!")) diff --git a/cmd/incus/file.go b/cmd/incus/file.go index 9d4b42d0109..8918831af61 100644 --- a/cmd/incus/file.go +++ b/cmd/incus/file.go @@ -367,7 +367,7 @@ func (c *cmdFilePull) Run(cmd *cobra.Command, args []string) error { i++ if i > 255 { - return fmt.Errorf("Too many links") + return fmt.Errorf(i18n.G("Too many links")) } // Update link target for next iteration. @@ -1159,7 +1159,7 @@ func (c *cmdFileMount) sshSFTPServer(ctx context.Context, instName string, resou return nil, nil } - return nil, fmt.Errorf("Password rejected for %q", c.User()) + return nil, fmt.Errorf(i18n.G("Password rejected for %q"), c.User()) } } @@ -1186,12 +1186,12 @@ func (c *cmdFileMount) sshSFTPServer(ctx context.Context, instName string, resou return fmt.Errorf(i18n.G("Failed to listen for connection: %w"), err) } - fmt.Printf("SSH SFTP listening on %v\n", listener.Addr()) + fmt.Printf(i18n.G("SSH SFTP listening on %v")+"\n", listener.Addr()) if config.PasswordCallback != nil { - fmt.Printf("Login with username %q and password %q\n", authUser, authPass) + fmt.Printf(i18n.G("Login with username %q and password %q")+"\n", authUser, authPass) } else { - fmt.Println("Login without username and password") + fmt.Println(i18n.G("Login without username and password")) } for { diff --git a/cmd/incus/image.go b/cmd/incus/image.go index 3f17074e1ec..4861f5830e4 100644 --- a/cmd/incus/image.go +++ b/cmd/incus/image.go @@ -987,9 +987,9 @@ func (c *cmdImageInfo) Run(cmd *cobra.Command, args []string) error { if info.UpdateSource != nil { fmt.Println(i18n.G("Source:")) - fmt.Printf(" Server: %s\n", info.UpdateSource.Server) - fmt.Printf(" Protocol: %s\n", info.UpdateSource.Protocol) - fmt.Printf(" Alias: %s\n", info.UpdateSource.Alias) + fmt.Printf(" "+i18n.G("Server: %s")+"\n", info.UpdateSource.Server) + fmt.Printf(" "+i18n.G("Protocol: %s")+"\n", info.UpdateSource.Protocol) + fmt.Printf(" "+i18n.G("Alias: %s")+"\n", info.UpdateSource.Alias) } if len(info.Profiles) == 0 { diff --git a/cmd/incus/move.go b/cmd/incus/move.go index 4054d304848..002d246fbbb 100644 --- a/cmd/incus/move.go +++ b/cmd/incus/move.go @@ -226,7 +226,7 @@ func (c *cmdMove) Run(cmd *cobra.Command, args []string) error { del.flagForceProtected = true err = del.Run(cmd, args[:1]) if err != nil { - return fmt.Errorf("Failed to delete original instance after copying it: %w", err) + return fmt.Errorf(i18n.G("Failed to delete original instance after copying it: %w"), err) } return nil diff --git a/cmd/incus/publish.go b/cmd/incus/publish.go index eb6180b4a79..ac6aefc6455 100644 --- a/cmd/incus/publish.go +++ b/cmd/incus/publish.go @@ -222,7 +222,7 @@ func (c *cmdPublish) Run(cmd *cobra.Command, args []string) error { if c.flagExpiresAt != "" { expiresAt, err := time.Parse(time.RFC3339, c.flagExpiresAt) if err != nil { - return fmt.Errorf("Invalid expiration date: %w", err) + return fmt.Errorf(i18n.G("Invalid expiration date: %w"), err) } req.ExpiresAt = expiresAt diff --git a/cmd/incus/storage_volume.go b/cmd/incus/storage_volume.go index 7cbcea87896..b73bbd0c01a 100644 --- a/cmd/incus/storage_volume.go +++ b/cmd/incus/storage_volume.go @@ -384,7 +384,7 @@ func (c *cmdStorageVolumeCopy) Run(cmd *cobra.Command, args []string) error { } if srcIsSnapshot && c.flagVolumeOnly { - return fmt.Errorf("Cannot set --volume-only when copying a snapshot") + return fmt.Errorf(i18n.G("Cannot set --volume-only when copying a snapshot")) } // If the volume is in local storage, set the target to its location (or provide a helpful error @@ -508,7 +508,7 @@ func (c *cmdStorageVolumeCopy) Run(cmd *cobra.Command, args []string) error { if err != nil { progress.Done("") - return fmt.Errorf("Failed deleting source volume after copy: %w", err) + return fmt.Errorf(i18n.G("Failed deleting source volume after copy: %w"), err) } } progress.Done(finalMsg) @@ -2571,7 +2571,7 @@ func (c *cmdStorageVolumeExport) Run(cmd *cobra.Command, args []string) error { op, err := d.CreateStoragePoolVolumeBackup(name, volName, req) if err != nil { - return fmt.Errorf("Failed to create storage volume backup: %w", err) + return fmt.Errorf(i18n.G("Failed to create storage volume backup: %w"), err) } // Watch the background operation @@ -2604,12 +2604,12 @@ func (c *cmdStorageVolumeExport) Run(cmd *cobra.Command, args []string) error { uStr := op.Get().Resources["backups"][0] u, err := url.Parse(uStr) if err != nil { - return fmt.Errorf("Invalid URL %q: %w", uStr, err) + return fmt.Errorf(i18n.G("Invalid URL %q: %w"), uStr, err) } backupName, err := url.PathUnescape(path.Base(u.EscapedPath())) if err != nil { - return fmt.Errorf("Invalid backup name segment in path %q: %w", u.EscapedPath(), err) + return fmt.Errorf(i18n.G("Invalid backup name segment in path %q: %w"), u.EscapedPath(), err) } defer func() { @@ -2650,7 +2650,7 @@ func (c *cmdStorageVolumeExport) Run(cmd *cobra.Command, args []string) error { if err != nil { _ = os.Remove(targetName) progress.Done("") - return fmt.Errorf("Failed to fetch storage volume backup file: %w", err) + return fmt.Errorf(i18n.G("Failed to fetch storage volume backup file: %w"), err) } progress.Done(i18n.G("Backup exported successfully!")) @@ -2734,12 +2734,12 @@ func (c *cmdStorageVolumeImport) Run(cmd *cobra.Command, args []string) error { } else { // Validate type flag if !util.ValueInSlice(c.flagType, []string{"backup", "iso"}) { - return fmt.Errorf("Import type needs to be \"backup\" or \"iso\"") + return fmt.Errorf(i18n.G("Import type needs to be \"backup\" or \"iso\"")) } } if c.flagType == "iso" && volName == "" { - return fmt.Errorf("Importing ISO images requires a volume name to be set") + return fmt.Errorf(i18n.G("Importing ISO images requires a volume name to be set")) } progress := cli.ProgressRenderer{ diff --git a/cmd/incus/utils.go b/cmd/incus/utils.go index a34f04ed50a..1da81b18a25 100644 --- a/cmd/incus/utils.go +++ b/cmd/incus/utils.go @@ -410,7 +410,7 @@ func textEditor(inPath string, inContent []byte) ([]byte, error) { } } if editor == "" { - return []byte{}, fmt.Errorf("No text editor found, please set the EDITOR environment variable") + return []byte{}, fmt.Errorf(i18n.G("No text editor found, please set the EDITOR environment variable")) } } } diff --git a/cmd/incus/utils_properties.go b/cmd/incus/utils_properties.go index 3e7c92fb763..301e928c688 100644 --- a/cmd/incus/utils_properties.go +++ b/cmd/incus/utils_properties.go @@ -44,7 +44,7 @@ func stringToBoolHookFunc() mapstructure.DecodeHookFunc { case "0", "f", "false": return false, nil default: - return false, fmt.Errorf("Invalid boolean value: %s", str) + return false, fmt.Errorf(i18n.G("Invalid boolean value: %s"), str) } } } @@ -92,12 +92,12 @@ func getFieldByJsonTag(obj any, tag string) (any, error) { } if v.Kind() != reflect.Struct { - return nil, fmt.Errorf("Expected a struct, got a %v", v.Kind()) + return nil, fmt.Errorf(i18n.G("Expected a struct, got a %v"), v.Kind()) } ok, res := getFromStruct(v, tag) if !ok { - return nil, fmt.Errorf("The property with tag %q does not exist", tag) + return nil, fmt.Errorf(i18n.G("The property with tag %q does not exist"), tag) } return res, nil