Skip to content

Commit

Permalink
cmd/incus: Translate all strings
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <[email protected]>
  • Loading branch information
stgraber committed Oct 5, 2023
1 parent 4d29f25 commit f01ca9e
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 41 deletions.
6 changes: 3 additions & 3 deletions cmd/incus/admin_recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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")
Expand Down
14 changes: 7 additions & 7 deletions cmd/incus/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"] == "" {
Expand All @@ -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 {
Expand All @@ -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"))
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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]
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/incus/console_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/incus/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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{
Expand Down
12 changes: 6 additions & 6 deletions cmd/incus/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand All @@ -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!"))
Expand Down
10 changes: 5 additions & 5 deletions cmd/incus/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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())
}
}

Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions cmd/incus/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/incus/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/incus/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions cmd/incus/storage_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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!"))
Expand Down Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion cmd/incus/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/incus/utils_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f01ca9e

Please sign in to comment.