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
}