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 53342a5dd4
25 changed files with 142 additions and 113 deletions

View File

@ -2,6 +2,7 @@ package git
import (
"context"
"errors"
"fmt"
"os"
"os/signal"
@ -10,6 +11,7 @@ import (
"coopcloud.tech/abra/pkg/log"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/leonelquinteros/gotext"
)
// gitCloneIgnoreErr checks whether we can ignore a git clone error or not.
@ -44,7 +46,7 @@ func Clone(dir, url string) error {
go func() {
if _, err := os.Stat(dir); os.IsNotExist(err) {
log.Debugf("git clone: %s", url)
log.Debugf(gotext.Get("git clone: %s", url))
_, err := git.PlainCloneContext(ctx, dir, false, &git.CloneOptions{
URL: url,
@ -54,16 +56,16 @@ func Clone(dir, url string) error {
})
if err != nil && gitCloneIgnoreErr(err) {
log.Debugf("git clone: %s cloned successfully", dir)
log.Debugf(gotext.Get("git clone: %s cloned successfully", dir))
errCh <- nil
}
if err := ctx.Err(); err != nil {
errCh <- fmt.Errorf("git clone %s: cancelled due to interrupt", dir)
errCh <- errors.New(gotext.Get("git clone %s: cancelled due to interrupt", dir))
}
if err != nil {
log.Debug("git clone: main branch failed, attempting master branch")
log.Debug(gotext.Get("git clone: main branch failed, attempting master branch"))
_, err := git.PlainCloneContext(ctx, dir, false, &git.CloneOptions{
URL: url,
@ -73,7 +75,7 @@ func Clone(dir, url string) error {
})
if err != nil && gitCloneIgnoreErr(err) {
log.Debugf("git clone: %s cloned successfully", dir)
log.Debugf(gotext.Get("git clone: %s cloned successfully", dir))
errCh <- nil
}
@ -82,9 +84,9 @@ func Clone(dir, url string) error {
}
}
log.Debugf("git clone: %s cloned successfully", dir)
log.Debugf(gotext.Get("git clone: %s cloned successfully", dir))
} else {
log.Debugf("git clone: %s already exists", dir)
log.Debugf(gotext.Get("git clone: %s already exists", dir))
}
errCh <- nil
@ -95,9 +97,9 @@ func Clone(dir, url string) error {
cancelCtx()
fmt.Println() // NOTE(d1): newline after ^C
if err := os.RemoveAll(dir); err != nil {
return fmt.Errorf("unable to clean up git clone of %s: %s", dir, err)
return errors.New(gotext.Get("unable to clean up git clone of %s: %s", dir, err))
}
return fmt.Errorf("git clone %s: cancelled due to interrupt", dir)
return errors.New(gotext.Get("git clone %s: cancelled due to interrupt", dir))
case err := <-errCh:
return err
}