feat: translation support
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
See #483
This commit is contained in:
@ -12,6 +12,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"coopcloud.tech/abra/pkg/i18n"
|
||||
"github.com/go-git/go-git/v5"
|
||||
|
||||
"coopcloud.tech/abra/pkg/catalogue"
|
||||
@ -70,7 +71,7 @@ func (r RecipeMeta) LatestVersion() string {
|
||||
version = tag
|
||||
}
|
||||
|
||||
log.Debugf("choosing %s as latest version of %s", version, r.Name)
|
||||
log.Debug(i18n.G("choosing %s as latest version of %s", version, r.Name))
|
||||
|
||||
return version
|
||||
}
|
||||
@ -126,7 +127,7 @@ func Get(name string) Recipe {
|
||||
if strings.Contains(name, ":") {
|
||||
split := strings.Split(name, ":")
|
||||
if len(split) > 2 {
|
||||
log.Fatalf("version seems invalid: %s", name)
|
||||
log.Fatal(i18n.G("version seems invalid: %s", name))
|
||||
}
|
||||
name = split[0]
|
||||
|
||||
@ -134,7 +135,7 @@ func Get(name string) Recipe {
|
||||
versionRaw = version
|
||||
if strings.HasSuffix(version, config.DIRTY_DEFAULT) {
|
||||
version = strings.Replace(split[1], config.DIRTY_DEFAULT, "", 1)
|
||||
log.Debugf("removed dirty suffix from .env version: %s -> %s", split[1], version)
|
||||
log.Debug(i18n.G("removed dirty suffix from .env version: %s -> %s", split[1], version))
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,7 +144,7 @@ func Get(name string) Recipe {
|
||||
if strings.Contains(name, "/") {
|
||||
u, err := url.Parse(name)
|
||||
if err != nil {
|
||||
log.Fatalf("invalid recipe: %s", err)
|
||||
log.Fatal(i18n.G("invalid recipe: %s", err))
|
||||
}
|
||||
u.Scheme = "https"
|
||||
gitURL = u.String() + ".git"
|
||||
@ -171,7 +172,7 @@ func Get(name string) Recipe {
|
||||
|
||||
dirty, err := r.IsDirty()
|
||||
if err != nil && !errors.Is(err, git.ErrRepositoryNotExists) {
|
||||
log.Fatalf("failed to check git status of %s: %s", r.Name, err)
|
||||
log.Fatal(i18n.G("failed to check git status of %s: %s", r.Name, err))
|
||||
}
|
||||
r.Dirty = dirty
|
||||
|
||||
@ -195,16 +196,16 @@ type Recipe struct {
|
||||
|
||||
// String outputs a human-friendly string representation.
|
||||
func (r Recipe) String() string {
|
||||
out := fmt.Sprintf("{name: %s, ", r.Name)
|
||||
out += fmt.Sprintf("version : %s, ", r.EnvVersion)
|
||||
out += fmt.Sprintf("dirty: %v, ", r.Dirty)
|
||||
out += fmt.Sprintf("dir: %s, ", r.Dir)
|
||||
out += fmt.Sprintf("git url: %s, ", r.GitURL)
|
||||
out += fmt.Sprintf("ssh url: %s, ", r.SSHURL)
|
||||
out += fmt.Sprintf("compose: %s, ", r.ComposePath)
|
||||
out += fmt.Sprintf("readme: %s, ", r.ReadmePath)
|
||||
out += fmt.Sprintf("sample env: %s, ", r.SampleEnvPath)
|
||||
out += fmt.Sprintf("abra.sh: %s}", r.AbraShPath)
|
||||
out := i18n.G("{name: %s, ", r.Name)
|
||||
out += i18n.G("version : %s, ", r.EnvVersion)
|
||||
out += i18n.G("dirty: %v, ", r.Dirty)
|
||||
out += i18n.G("dir: %s, ", r.Dir)
|
||||
out += i18n.G("git url: %s, ", r.GitURL)
|
||||
out += i18n.G("ssh url: %s, ", r.SSHURL)
|
||||
out += i18n.G("compose: %s, ", r.ComposePath)
|
||||
out += i18n.G("readme: %s, ", r.ReadmePath)
|
||||
out += i18n.G("sample env: %s, ", r.SampleEnvPath)
|
||||
out += i18n.G("abra.sh: %s}", r.AbraShPath)
|
||||
return out
|
||||
}
|
||||
|
||||
@ -233,7 +234,7 @@ func GetRecipeFeaturesAndCategory(r Recipe) (Features, string, []string, error)
|
||||
feat = Features{}
|
||||
)
|
||||
|
||||
log.Debugf("%s: attempt recipe metadata parse", r.ReadmePath)
|
||||
log.Debug(i18n.G("%s: attempt recipe metadata parse", r.ReadmePath))
|
||||
|
||||
readmeFS, err := ioutil.ReadFile(r.ReadmePath)
|
||||
if err != nil {
|
||||
@ -321,12 +322,12 @@ func GetImageMetadata(imageRowString, recipeName string) (Image, []string, error
|
||||
if imageRowString != "" {
|
||||
warnMsgs = append(
|
||||
warnMsgs,
|
||||
fmt.Sprintf("%s: image meta has incorrect format: %s", recipeName, imageRowString),
|
||||
i18n.G("%s: image meta has incorrect format: %s", recipeName, imageRowString),
|
||||
)
|
||||
} else {
|
||||
warnMsgs = append(
|
||||
warnMsgs,
|
||||
fmt.Sprintf("%s: image meta is empty?", recipeName),
|
||||
i18n.G("%s: image meta is empty?", recipeName),
|
||||
)
|
||||
}
|
||||
|
||||
@ -357,14 +358,14 @@ func GetImageMetadata(imageRowString, recipeName string) (Image, []string, error
|
||||
func GetStringInBetween(recipeName, str, start, end string) (result string, err error) {
|
||||
s := strings.Index(str, start)
|
||||
if s == -1 {
|
||||
return "", fmt.Errorf("%s: marker string %s not found", recipeName, start)
|
||||
return "", errors.New(i18n.G("%s: marker string %s not found", recipeName, start))
|
||||
}
|
||||
|
||||
s += len(start)
|
||||
e := strings.Index(str[s:], end)
|
||||
|
||||
if e == -1 {
|
||||
return "", fmt.Errorf("%s: end marker %s not found", recipeName, end)
|
||||
return "", errors.New(i18n.G("%s: end marker %s not found", recipeName, end))
|
||||
}
|
||||
|
||||
return str[s : s+e], nil
|
||||
@ -402,7 +403,7 @@ func readRecipeCatalogueFS(target interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debugf("read recipe catalogue from file system cache in %s", config.RECIPES_JSON)
|
||||
log.Debug(i18n.G("read recipe catalogue from file system cache in %s", config.RECIPES_JSON))
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -431,7 +432,7 @@ func VersionsOfService(recipe, serviceName string, offline bool) ([]string, erro
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("detected versions %s for %s", strings.Join(versions, ", "), recipe)
|
||||
log.Debug(i18n.G("detected versions %s for %s", strings.Join(versions, ", "), recipe))
|
||||
|
||||
return versions, nil
|
||||
}
|
||||
@ -454,11 +455,11 @@ func GetRecipeMeta(recipeName string, offline bool) (RecipeMeta, error) {
|
||||
recipeMeta, ok := catl[recipeName]
|
||||
if !ok {
|
||||
return RecipeMeta{}, RecipeMissingFromCatalogue{
|
||||
err: fmt.Sprintf("recipe %s does not exist?", recipeName),
|
||||
err: i18n.G("recipe %s does not exist?", recipeName),
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("recipe metadata retrieved for %s", recipeName)
|
||||
log.Debug(i18n.G("recipe metadata retrieved for %s", recipeName))
|
||||
|
||||
return recipeMeta, nil
|
||||
}
|
||||
@ -545,13 +546,13 @@ func ReadReposMetadata(debug bool) (RepoCatalogue, error) {
|
||||
reposMeta := make(RepoCatalogue)
|
||||
|
||||
pageIdx := 1
|
||||
bar := formatter.CreateProgressbar(-1, "collecting recipe listing")
|
||||
bar := formatter.CreateProgressbar(-1, i18n.G("collecting recipe listing"))
|
||||
for {
|
||||
var reposList []RepoMeta
|
||||
|
||||
pagedURL := fmt.Sprintf("%s?page=%v", ReposMetadataURL, pageIdx)
|
||||
|
||||
log.Debugf("fetching repo metadata from %s", pagedURL)
|
||||
log.Debug(i18n.G("fetching repo metadata from %s", pagedURL))
|
||||
|
||||
if err := web.ReadJSON(pagedURL, &reposList); err != nil {
|
||||
return reposMeta, err
|
||||
@ -655,7 +656,7 @@ func UpdateRepositories(repos RepoCatalogue, recipeName string, debug bool) erro
|
||||
|
||||
cloneLimiter := limit.New(3)
|
||||
|
||||
retrieveBar := formatter.CreateProgressbar(barLength, "retrieving recipes")
|
||||
retrieveBar := formatter.CreateProgressbar(barLength, i18n.G("retrieving recipes"))
|
||||
ch := make(chan string, barLength)
|
||||
for _, repoMeta := range repos {
|
||||
go func(rm RepoMeta) {
|
||||
|
Reference in New Issue
Block a user