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

@ -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"))
}