WIP: feat: translation support
Some checks failed
continuous-integration/drone/push Build is failing

See #483
This commit is contained in:
2025-08-19 11:22:52 +02:00
parent 5cf6048ecb
commit a31ec51c24
71 changed files with 804 additions and 796 deletions

View File

@ -2,6 +2,7 @@ package service
import (
"context"
"errors"
"fmt"
"strings"
@ -12,6 +13,7 @@ import (
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/client"
"github.com/leonelquinteros/gotext"
)
// GetService retrieves a service container based on a label. If prompt is true
@ -25,7 +27,7 @@ func GetServiceByLabel(c context.Context, cl *client.Client, label string, promp
}
if len(services) == 0 {
return swarm.Service{}, fmt.Errorf("no services deployed?")
return swarm.Service{}, errors.New(gotext.Get("no services deployed?"))
}
var matchingServices []swarm.Service
@ -36,7 +38,7 @@ func GetServiceByLabel(c context.Context, cl *client.Client, label string, promp
}
if len(matchingServices) == 0 {
return swarm.Service{}, fmt.Errorf("no services deployed matching label '%s'?", label)
return swarm.Service{}, errors.New(gotext.Get("no services deployed matching label '%s'?", label))
}
if len(matchingServices) > 1 {
@ -48,15 +50,15 @@ func GetServiceByLabel(c context.Context, cl *client.Client, label string, promp
}
if !prompt {
err := fmt.Errorf("expected 1 service but found %v: %s", len(matchingServices), strings.Join(servicesRaw, " "))
err := errors.New(gotext.Get("expected 1 service but found %v: %s", len(matchingServices), strings.Join(servicesRaw, " ")))
return swarm.Service{}, err
}
log.Warnf("ambiguous service list received, prompting for input")
log.Warnf(gotext.Get("ambiguous service list received, prompting for input"))
var response string
prompt := &survey.Select{
Message: "which service are you looking for?",
Message: gotext.Get("which service are you looking for?"),
Options: servicesRaw,
}
@ -72,7 +74,7 @@ func GetServiceByLabel(c context.Context, cl *client.Client, label string, promp
}
}
log.Fatal("failed to match chosen service")
log.Fatal(gotext.Get("failed to match chosen service"))
}
return matchingServices[0], nil
@ -90,7 +92,7 @@ func GetService(c context.Context, cl *client.Client, filters filters.Args, prom
if len(services) == 0 {
filter := filters.Get("name")[0]
return swarm.Service{}, fmt.Errorf("no services matching the %v filter found?", filter)
return swarm.Service{}, errors.New(gotext.Get("no services matching the %v filter found?", filter))
}
if len(services) != 1 {
@ -98,19 +100,19 @@ func GetService(c context.Context, cl *client.Client, filters filters.Args, prom
for _, service := range services {
serviceName := service.Spec.Name
created := formatter.HumanDuration(service.CreatedAt.Unix())
servicesRaw = append(servicesRaw, fmt.Sprintf("%s (created %v)", serviceName, created))
servicesRaw = append(servicesRaw, gotext.Get("%s (created %v)", serviceName, created))
}
if !prompt {
err := fmt.Errorf("expected 1 service but found %v: %s", len(services), strings.Join(servicesRaw, " "))
err := errors.New(gotext.Get("expected 1 service but found %v: %s", len(services), strings.Join(servicesRaw, " ")))
return swarm.Service{}, err
}
log.Warnf("ambiguous service list received, prompting for input")
log.Warnf(gotext.Get("ambiguous service list received, prompting for input"))
var response string
prompt := &survey.Select{
Message: "which service are you looking for?",
Message: gotext.Get("which service are you looking for?"),
Options: servicesRaw,
}
@ -126,7 +128,7 @@ func GetService(c context.Context, cl *client.Client, filters filters.Args, prom
}
}
log.Fatal("failed to match chosen service")
log.Fatal(gotext.Get("failed to match chosen service"))
}
return services[0], nil