WIP: feat: translation support
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
See #483
This commit is contained in:
@ -2,6 +2,7 @@ package container
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@ -12,6 +13,7 @@ import (
|
||||
containerTypes "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/client"
|
||||
"coopcloud.tech/abra/pkg/i18n"
|
||||
)
|
||||
|
||||
// GetContainer retrieves a container. If noInput is false and the retrievd
|
||||
@ -26,7 +28,7 @@ func GetContainer(c context.Context, cl *client.Client, filters filters.Args, no
|
||||
|
||||
if len(containers) == 0 {
|
||||
filter := filters.Get("name")[0]
|
||||
return types.Container{}, fmt.Errorf("no containers matching the %v filter found?", filter)
|
||||
return types.Container{}, errors.New(i18n.G("no containers matching the %v filter found?", filter))
|
||||
}
|
||||
|
||||
if len(containers) > 1 {
|
||||
@ -35,19 +37,19 @@ func GetContainer(c context.Context, cl *client.Client, filters filters.Args, no
|
||||
containerName := strings.Join(container.Names, " ")
|
||||
trimmed := strings.TrimPrefix(containerName, "/")
|
||||
created := formatter.HumanDuration(container.Created)
|
||||
containersRaw = append(containersRaw, fmt.Sprintf("%s (created %v)", trimmed, created))
|
||||
containersRaw = append(containersRaw, i18n.G("%s (created %v)", trimmed, created))
|
||||
}
|
||||
|
||||
if noInput {
|
||||
err := fmt.Errorf("expected 1 container but found %v: %s", len(containers), strings.Join(containersRaw, " "))
|
||||
err := errors.New(i18n.G("expected 1 container but found %v: %s", len(containers), strings.Join(containersRaw, " ")))
|
||||
return types.Container{}, err
|
||||
}
|
||||
|
||||
log.Warnf("ambiguous container list received, prompting for input")
|
||||
log.Warnf(i18n.G("ambiguous container list received, prompting for input"))
|
||||
|
||||
var response string
|
||||
prompt := &survey.Select{
|
||||
Message: "which container are you looking for?",
|
||||
Message: i18n.G("which container are you looking for?"),
|
||||
Options: containersRaw,
|
||||
}
|
||||
|
||||
@ -64,7 +66,7 @@ func GetContainer(c context.Context, cl *client.Client, filters filters.Args, no
|
||||
}
|
||||
}
|
||||
|
||||
log.Fatal("failed to match chosen container")
|
||||
log.Fatal(i18n.G("failed to match chosen container"))
|
||||
}
|
||||
|
||||
return containers[0], nil
|
||||
@ -79,5 +81,6 @@ func GetContainerFromStackAndService(cl *client.Client, stack, service string) (
|
||||
if err != nil {
|
||||
return types.Container{}, err
|
||||
}
|
||||
|
||||
return container, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user