feat: translation support
All checks were successful
continuous-integration/drone/push Build is passing

See #483
This commit is contained in:
2025-08-19 11:22:52 +02:00
parent 5cf6048ecb
commit 4e205cf13e
108 changed files with 11217 additions and 1645 deletions

View File

@ -17,7 +17,6 @@ package commandconn
import (
"bytes"
"context"
"fmt"
"io"
"net"
"os"
@ -27,6 +26,7 @@ import (
"syscall"
"time"
"coopcloud.tech/abra/pkg/i18n"
"coopcloud.tech/abra/pkg/log"
"github.com/pkg/errors"
exec "golang.org/x/sys/execabs"
@ -46,7 +46,7 @@ func New(ctx context.Context, cmd string, args ...string) (net.Conn, error) {
)
c.cmd = exec.CommandContext(ctx, cmd, args...)
// we assume that args never contains sensitive information
log.Debugf("commandconn: starting %s with %v", cmd, args)
log.Debug(i18n.G("commandconn: starting %s with %v", cmd, args))
c.cmd.Env = os.Environ()
c.cmd.SysProcAttr = &syscall.SysProcAttr{}
setPdeathsig(c.cmd)
@ -62,7 +62,7 @@ func New(ctx context.Context, cmd string, args ...string) (net.Conn, error) {
c.cmd.Stderr = &stderrWriter{
stderrMu: &c.stderrMu,
stderr: &c.stderr,
debugPrefix: fmt.Sprintf("commandconn (%s):", cmd),
debugPrefix: i18n.G("commandconn (%s):", cmd),
}
c.localAddr = dummyAddr{network: "dummy", s: "dummy-0"}
c.remoteAddr = dummyAddr{network: "dummy", s: "dummy-1"}
@ -138,7 +138,7 @@ func (c *commandConn) kill() error {
return nil
}
}
return errors.Wrapf(werr, "commandconn: failed to wait")
return errors.Wrap(werr, i18n.G("commandconn: failed to wait"))
}
func (c *commandConn) onEOF(eof error) error {
@ -159,7 +159,7 @@ func (c *commandConn) onEOF(eof error) error {
c.stderrMu.Lock()
stderr := c.stderr.String()
c.stderrMu.Unlock()
return errors.Errorf("command %v did not exit after %v: stderr=%q", c.cmd.Args, eof, stderr)
return errors.New(i18n.G("command %v did not exit after %v: stderr=%q", c.cmd.Args, eof, stderr))
}
}
c.cmdMutex.Unlock()
@ -169,7 +169,7 @@ func (c *commandConn) onEOF(eof error) error {
c.stderrMu.Lock()
stderr := c.stderr.String()
c.stderrMu.Unlock()
return errors.Errorf("command %v has exited with %v, please make sure the URL is valid, and Docker 18.09 or later is installed on the remote host: stderr=%s", c.cmd.Args, werr, stderr)
return errors.New(i18n.G("command %v has exited with %v, please make sure the URL is valid, and Docker 18.09 or later is installed on the remote host: stderr=%s", c.cmd.Args, werr, stderr))
}
func ignorableCloseError(err error) bool {
@ -236,7 +236,7 @@ func (c *commandConn) Write(p []byte) (int, error) {
func (c *commandConn) Close() error {
var err error
if err = c.CloseRead(); err != nil {
log.Warnf("commandConn.Close: CloseRead: %v", err)
log.Warnf(i18n.G("commandConn.Close: CloseRead: %v", err))
}
if err = c.CloseWrite(); err != nil {
// muted because https://github.com/docker/compose/issues/8544
@ -252,15 +252,15 @@ func (c *commandConn) RemoteAddr() net.Addr {
return c.remoteAddr
}
func (c *commandConn) SetDeadline(t time.Time) error {
log.Debugf("unimplemented call: SetDeadline(%v)", t)
log.Debug(i18n.G("unimplemented call: SetDeadline(%v)", t))
return nil
}
func (c *commandConn) SetReadDeadline(t time.Time) error {
log.Debugf("unimplemented call: SetReadDeadline(%v)", t)
log.Debug(i18n.G("unimplemented call: SetReadDeadline(%v)", t))
return nil
}
func (c *commandConn) SetWriteDeadline(t time.Time) error {
log.Debugf("unimplemented call: SetWriteDeadline(%v)", t)
log.Debug(i18n.G("unimplemented call: SetWriteDeadline(%v)", t))
return nil
}

View File

@ -6,6 +6,7 @@ import (
"net"
"net/url"
"coopcloud.tech/abra/pkg/i18n"
"github.com/docker/cli/cli/connhelper"
"github.com/docker/cli/cli/connhelper/ssh"
"github.com/docker/cli/cli/context/docker"
@ -34,7 +35,7 @@ func getConnectionHelper(daemonURL string, sshFlags []string) (*connhelper.Conne
case "ssh":
ctxConnDetails, err := ssh.ParseURL(daemonURL)
if err != nil {
return nil, errors.Wrap(err, "ssh host connection is not valid")
return nil, errors.Wrap(err, i18n.G("ssh host connection is not valid"))
}
return &connhelper.ConnectionHelper{

View File

@ -6,6 +6,7 @@ import (
"fmt"
"io"
"coopcloud.tech/abra/pkg/i18n"
"coopcloud.tech/abra/pkg/log"
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
@ -39,7 +40,7 @@ func RunExec(dockerCli command.Cli, client *apiclient.Client, containerID string
execID := response.ID
if execID == "" {
return nil, errors.New("exec ID empty")
return nil, errors.New(i18n.G("exec ID empty"))
}
if execOptions.Detach {
@ -104,12 +105,12 @@ func interactiveExec(ctx context.Context, dockerCli command.Cli, client *apiclie
if execOpts.Tty && dockerCli.In().IsTerminal() {
if err := MonitorTtySize(ctx, client, dockerCli, execID, true); err != nil {
fmt.Fprintln(dockerCli.Err(), "Error monitoring TTY size:", err)
fmt.Fprintln(dockerCli.Err(), i18n.G("Error monitoring TTY size:"), err)
}
}
if err := <-errCh; err != nil {
log.Debugf("Error hijack: %s", err)
log.Debug(i18n.G("Error hijack: %s", err))
return out, err
}

View File

@ -2,11 +2,12 @@ package container // https://github.com/docker/cli/blob/master/cli/command/conta
import (
"context"
"fmt"
"errors"
"io"
"runtime"
"sync"
"coopcloud.tech/abra/pkg/i18n"
"coopcloud.tech/abra/pkg/log"
"github.com/docker/cli/cli/command"
"github.com/docker/docker/api/types"
@ -39,7 +40,7 @@ type hijackedIOStreamer struct {
func (h *hijackedIOStreamer) stream(ctx context.Context) error {
restoreInput, err := h.setupInput()
if err != nil {
return fmt.Errorf("unable to setup input stream: %s", err)
return errors.New(i18n.G("unable to setup input stream: %s", err))
}
defer restoreInput()
@ -78,7 +79,7 @@ func (h *hijackedIOStreamer) setupInput() (restore func(), err error) {
}
if err := setRawTerminal(h.streams); err != nil {
return nil, fmt.Errorf("unable to set IO streams as raw terminal: %s", err)
return nil, errors.New(i18n.G("unable to set IO streams as raw terminal: %s", err))
}
// Use sync.Once so we may call restore multiple times but ensure we
@ -96,7 +97,7 @@ func (h *hijackedIOStreamer) setupInput() (restore func(), err error) {
if h.detachKeys != "" {
customEscapeKeys, err := term.ToBytes(h.detachKeys)
if err != nil {
log.Warnf("invalid detach escape keys, using default: %s", err)
log.Warnf(i18n.G("invalid detach escape keys, using default: %s", err))
} else {
escapeKeys = customEscapeKeys
}
@ -128,10 +129,10 @@ func (h *hijackedIOStreamer) beginOutputStream(restoreInput func()) <-chan error
_, err = stdcopy.StdCopy(h.outputStream, h.errorStream, h.resp.Reader)
}
log.Debug("[hijack] End of stdout")
log.Debug(i18n.G("[hijack] end of stdout"))
if err != nil {
log.Debugf("Error receiveStdout: %s", err)
log.Debug(i18n.G("error receiveStdout: %s", err))
}
outputDone <- err
@ -152,7 +153,7 @@ func (h *hijackedIOStreamer) beginInputStream(restoreInput func()) (doneC <-chan
// messages will be in normal type.
restoreInput()
log.Debug("[hijack] End of stdin")
log.Debug(i18n.G("[hijack] End of stdin"))
if _, ok := err.(term.EscapeError); ok {
detached <- err
@ -163,12 +164,12 @@ func (h *hijackedIOStreamer) beginInputStream(restoreInput func()) (doneC <-chan
// This error will also occur on the receive
// side (from stdout) where it will be
// propagated back to the caller.
log.Debugf("Error sendStdin: %s", err)
log.Debug(i18n.G("error sendStdin: %s", err))
}
}
if err := h.resp.CloseWrite(); err != nil {
log.Debugf("Couldn't send EOF: %s", err)
log.Debug(i18n.G("couldn't send EOF: %s", err))
}
close(inputDone)

View File

@ -8,6 +8,7 @@ import (
"runtime"
"time"
"coopcloud.tech/abra/pkg/i18n"
"coopcloud.tech/abra/pkg/log"
"github.com/docker/cli/cli/command"
"github.com/docker/docker/api/types/container"
@ -35,7 +36,7 @@ func resizeTtyTo(ctx context.Context, client client.ContainerAPIClient, id strin
}
if err != nil {
log.Debugf("Error resize: %s\r", err)
log.Debug(fmt.Sprintf("%s\r", i18n.G("error resize: %s", err)))
}
return err
}
@ -62,7 +63,7 @@ func initTtySize(ctx context.Context, client *apiclient.Client, cli command.Cli,
}
}
if err != nil {
fmt.Fprintln(cli.Err(), "failed to resize tty, using default size")
fmt.Fprintln(cli.Err(), i18n.G("failed to resize tty, using default size"))
}
}()
}

View File

@ -8,6 +8,7 @@ import (
"strings"
"time"
"coopcloud.tech/abra/pkg/i18n"
composetypes "github.com/docker/cli/cli/compose/types"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types"
@ -39,7 +40,7 @@ func ParseSecrets(client client.SecretAPIClient, requestedSecrets []*swarmtypes.
for _, secret := range requestedSecrets {
if _, exists := secretRefs[secret.File.Name]; exists {
return nil, errors.Errorf("duplicate secret target for %s not allowed", secret.SecretName)
return nil, errors.New(i18n.G("duplicate secret target for %s not allowed", secret.SecretName))
}
secretRef := new(swarmtypes.SecretReference)
*secretRef = *secret
@ -68,7 +69,7 @@ func ParseSecrets(client client.SecretAPIClient, requestedSecrets []*swarmtypes.
for _, ref := range secretRefs {
id, ok := foundSecrets[ref.SecretName]
if !ok {
return nil, errors.Errorf("secret not found: %s", ref.SecretName)
return nil, errors.New(i18n.G("secret not found: %s", ref.SecretName))
}
// set the id for the ref to properly assign in swarm
@ -118,7 +119,7 @@ func ParseConfigs(client client.ConfigAPIClient, requestedConfigs []*swarmtypes.
}
if _, exists := configRefs[config.File.Name]; exists {
return nil, errors.Errorf("duplicate config target for %s not allowed", config.ConfigName)
return nil, errors.New(i18n.G("duplicate config target for %s not allowed", config.ConfigName))
}
configRefs[config.File.Name] = configRef
@ -149,7 +150,7 @@ func ParseConfigs(client client.ConfigAPIClient, requestedConfigs []*swarmtypes.
for _, ref := range configRefs {
id, ok := foundConfigs[ref.ConfigName]
if !ok {
return nil, errors.Errorf("config not found: %s", ref.ConfigName)
return nil, errors.New(i18n.G("config not found: %s", ref.ConfigName))
}
// set the id for the ref to properly assign in swarm
@ -164,7 +165,7 @@ func ParseConfigs(client client.ConfigAPIClient, requestedConfigs []*swarmtypes.
for _, ref := range runtimeRefs {
id, ok := foundConfigs[ref.ConfigName]
if !ok {
return nil, errors.Errorf("config not found: %s", ref.ConfigName)
return nil, errors.New(i18n.G("config not found: %s", ref.ConfigName))
}
ref.ConfigID = id
@ -371,7 +372,7 @@ func convertServiceNetworks(
for networkName, network := range networks {
networkConfig, ok := networkConfigs[networkName]
if !ok && networkName != defaultNetwork {
return nil, errors.Errorf("undefined network %q", networkName)
return nil, errors.New(i18n.G("undefined network %q", networkName))
}
var aliases []string
if network != nil {
@ -410,7 +411,7 @@ func convertServiceSecrets(
lookup := func(key string) (composetypes.FileObjectConfig, error) {
secretSpec, exists := secretSpecs[key]
if !exists {
return composetypes.FileObjectConfig{}, errors.Errorf("undefined secret %q", key)
return composetypes.FileObjectConfig{}, errors.New(i18n.G("undefined secret %q", key))
}
return composetypes.FileObjectConfig(secretSpec), nil
}
@ -458,7 +459,7 @@ func convertServiceConfigObjs(
lookup := func(key string) (composetypes.FileObjectConfig, error) {
configSpec, exists := configSpecs[key]
if !exists {
return composetypes.FileObjectConfig{}, errors.Errorf("undefined config %q", key)
return composetypes.FileObjectConfig{}, errors.New(i18n.G("undefined config %q", key))
}
return composetypes.FileObjectConfig(configSpec), nil
}
@ -600,7 +601,7 @@ func convertHealthcheck(healthcheck *composetypes.HealthCheckConfig) (*container
)
if healthcheck.Disable {
if len(healthcheck.Test) != 0 {
return nil, errors.Errorf("test and disable can't be set at the same time")
return nil, errors.New(i18n.G("test and disable can't be set at the same time"))
}
return &container.HealthConfig{
Test: []string{"NONE"},
@ -648,7 +649,7 @@ func convertRestartPolicy(restart string, source *composetypes.RestartPolicy) (*
MaxAttempts: &attempts,
}, nil
default:
return nil, errors.Errorf("unknown restart policy: %s", restart)
return nil, errors.New(i18n.G("unknown restart policy: %s", restart))
}
}
@ -770,13 +771,13 @@ func convertDeployMode(mode string, replicas *uint64) (swarm.ServiceMode, error)
switch mode {
case "global":
if replicas != nil {
return serviceMode, errors.Errorf("replicas can only be used with replicated mode")
return serviceMode, errors.New(i18n.G("replicas can only be used with replicated mode"))
}
serviceMode.Global = &swarm.GlobalService{}
case "replicated", "":
serviceMode.Replicated = &swarm.ReplicatedService{Replicas: replicas}
default:
return serviceMode, errors.Errorf("Unknown mode: %s", mode)
return serviceMode, errors.New(i18n.G("unknown mode: %s", mode))
}
return serviceMode, nil
}
@ -809,9 +810,9 @@ func convertCredentialSpec(namespace Namespace, spec composetypes.CredentialSpec
case l == 0:
return nil, nil
case l == 2:
return nil, errors.Errorf("invalid credential spec: cannot specify both %s and %s", o[0], o[1])
return nil, errors.New(i18n.G("invalid credential spec: cannot specify both %s and %s", o[0], o[1]))
case l > 2:
return nil, errors.Errorf("invalid credential spec: cannot specify both %s, and %s", strings.Join(o[:l-1], ", "), o[l-1])
return nil, errors.New(i18n.G("invalid credential spec: cannot specify both %s, and %s", strings.Join(o[:l-1], ", "), o[l-1]))
}
swarmCredSpec := swarm.CredentialSpec(spec)
// if we're using a swarm Config for the credential spec, over-write it
@ -830,7 +831,7 @@ func convertCredentialSpec(namespace Namespace, spec composetypes.CredentialSpec
return &swarmCredSpec, nil
}
}
return nil, errors.Errorf("invalid credential spec: spec specifies config %v, but no such config can be found", swarmCredSpec.Config)
return nil, errors.New(i18n.G("invalid credential spec: spec specifies config %v, but no such config can be found", swarmCredSpec.Config))
}
return &swarmCredSpec, nil
}

View File

@ -1,6 +1,7 @@
package convert // https://github.com/docker/cli/blob/master/cli/compose/convert/volume.go
import (
"coopcloud.tech/abra/pkg/i18n"
composetypes "github.com/docker/cli/cli/compose/types"
"github.com/docker/docker/api/types/mount"
"github.com/pkg/errors"
@ -40,10 +41,10 @@ func handleVolumeToMount(
result := createMountFromVolume(volume)
if volume.Tmpfs != nil {
return mount.Mount{}, errors.New("tmpfs options are incompatible with type volume")
return mount.Mount{}, errors.New(i18n.G("tmpfs options are incompatible with type volume"))
}
if volume.Bind != nil {
return mount.Mount{}, errors.New("bind options are incompatible with type volume")
return mount.Mount{}, errors.New(i18n.G("bind options are incompatible with type volume"))
}
// Anonymous volumes
if volume.Source == "" {
@ -52,7 +53,7 @@ func handleVolumeToMount(
stackVolume, exists := stackVolumes[volume.Source]
if !exists {
return mount.Mount{}, errors.Errorf("undefined volume %q", volume.Source)
return mount.Mount{}, errors.New(i18n.G("undefined volume %q", volume.Source))
}
result.Source = namespace.Scope(volume.Source)
@ -86,13 +87,13 @@ func handleBindToMount(volume composetypes.ServiceVolumeConfig) (mount.Mount, er
result := createMountFromVolume(volume)
if volume.Source == "" {
return mount.Mount{}, errors.New("invalid bind source, source cannot be empty")
return mount.Mount{}, errors.New(i18n.G("invalid bind source, source cannot be empty"))
}
if volume.Volume != nil {
return mount.Mount{}, errors.New("volume options are incompatible with type bind")
return mount.Mount{}, errors.New(i18n.G("volume options are incompatible with type bind"))
}
if volume.Tmpfs != nil {
return mount.Mount{}, errors.New("tmpfs options are incompatible with type bind")
return mount.Mount{}, errors.New(i18n.G("tmpfs options are incompatible with type bind"))
}
if volume.Bind != nil {
result.BindOptions = &mount.BindOptions{
@ -106,13 +107,13 @@ func handleTmpfsToMount(volume composetypes.ServiceVolumeConfig) (mount.Mount, e
result := createMountFromVolume(volume)
if volume.Source != "" {
return mount.Mount{}, errors.New("invalid tmpfs source, source must be empty")
return mount.Mount{}, errors.New(i18n.G("invalid tmpfs source, source must be empty"))
}
if volume.Bind != nil {
return mount.Mount{}, errors.New("bind options are incompatible with type tmpfs")
return mount.Mount{}, errors.New(i18n.G("bind options are incompatible with type tmpfs"))
}
if volume.Volume != nil {
return mount.Mount{}, errors.New("volume options are incompatible with type tmpfs")
return mount.Mount{}, errors.New(i18n.G("volume options are incompatible with type tmpfs"))
}
if volume.Tmpfs != nil {
result.TmpfsOptions = &mount.TmpfsOptions{
@ -126,13 +127,13 @@ func handleNpipeToMount(volume composetypes.ServiceVolumeConfig) (mount.Mount, e
result := createMountFromVolume(volume)
if volume.Source == "" {
return mount.Mount{}, errors.New("invalid npipe source, source cannot be empty")
return mount.Mount{}, errors.New(i18n.G("invalid npipe source, source cannot be empty"))
}
if volume.Volume != nil {
return mount.Mount{}, errors.New("volume options are incompatible with type npipe")
return mount.Mount{}, errors.New(i18n.G("volume options are incompatible with type npipe"))
}
if volume.Tmpfs != nil {
return mount.Mount{}, errors.New("tmpfs options are incompatible with type npipe")
return mount.Mount{}, errors.New(i18n.G("tmpfs options are incompatible with type npipe"))
}
if volume.Bind != nil {
result.BindOptions = &mount.BindOptions{
@ -158,5 +159,5 @@ func convertVolumeToMount(
case "npipe":
return handleNpipeToMount(volume)
}
return mount.Mount{}, errors.New("volume type must be volume, bind, tmpfs or npipe")
return mount.Mount{}, errors.New(i18n.G("volume type must be volume, bind, tmpfs or npipe"))
}