WIP: feat: translation support
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
See #483
This commit is contained in:
@ -5,6 +5,7 @@ import (
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"coopcloud.tech/abra/pkg/i18n"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
@ -16,13 +17,13 @@ func LoadAbraConfig() Abra {
|
||||
wd, _ := os.Getwd()
|
||||
configFile := findAbraConfig(wd)
|
||||
if configFile == "" {
|
||||
log.Debugf("no config file found")
|
||||
log.Debug(i18n.G("no config file found"))
|
||||
return Abra{}
|
||||
}
|
||||
data, err := os.ReadFile(configFile)
|
||||
if err != nil {
|
||||
// Do nothing, when an error occurs
|
||||
log.Debugf("error reading config file: %s", err)
|
||||
log.Debug(i18n.G("error reading config file: %s", err))
|
||||
return Abra{}
|
||||
}
|
||||
|
||||
@ -30,10 +31,10 @@ func LoadAbraConfig() Abra {
|
||||
err = yaml.Unmarshal(data, &config)
|
||||
if err != nil {
|
||||
// Do nothing, when an error occurs
|
||||
log.Debugf("error loading config file: %s", err)
|
||||
log.Debug(i18n.G("error loading config file: %s", err))
|
||||
return Abra{}
|
||||
}
|
||||
log.Debugf("config file loaded from: %s", configFile)
|
||||
log.Debug(i18n.G("config file loaded from: %s", configFile))
|
||||
config.configPath = filepath.Dir(configFile)
|
||||
return config
|
||||
}
|
||||
@ -73,26 +74,24 @@ type Abra struct {
|
||||
// 3. use $HOME/.abra when above two options failed
|
||||
func (a Abra) GetAbraDir() string {
|
||||
if dir, exists := os.LookupEnv("ABRA_DIR"); exists && dir != "" {
|
||||
log.Debug("read abra dir from $ABRA_DIR")
|
||||
log.Debug(i18n.G("read abra dir from $ABRA_DIR"))
|
||||
return dir
|
||||
}
|
||||
if a.AbraDir != "" {
|
||||
log.Debug("read abra dir from config file")
|
||||
log.Debug(i18n.G("read abra dir from config file"))
|
||||
if path.IsAbs(a.AbraDir) {
|
||||
return a.AbraDir
|
||||
}
|
||||
// Make the path absolute
|
||||
return path.Join(a.configPath, a.AbraDir)
|
||||
}
|
||||
log.Debug("using default abra dir")
|
||||
log.Debug(i18n.G("using default abra dir"))
|
||||
return os.ExpandEnv("$HOME/.abra")
|
||||
}
|
||||
|
||||
func (a Abra) GetServersDir() string { return path.Join(a.GetAbraDir(), "servers") }
|
||||
func (a Abra) GetRecipesDir() string { return path.Join(a.GetAbraDir(), "recipes") }
|
||||
func (a Abra) GetLogsDir() string { return path.Join(a.GetAbraDir(), "logs") }
|
||||
func (a Abra) GetVendorDir() string { return path.Join(a.GetAbraDir(), "vendor") }
|
||||
func (a Abra) GetBackupDir() string { return path.Join(a.GetAbraDir(), "backups") }
|
||||
func (a Abra) GetCatalogueDir() string { return path.Join(a.GetAbraDir(), "catalogue") }
|
||||
|
||||
var config = LoadAbraConfig()
|
||||
@ -102,8 +101,6 @@ var (
|
||||
SERVERS_DIR = config.GetServersDir()
|
||||
RECIPES_DIR = config.GetRecipesDir()
|
||||
LOGS_DIR = config.GetLogsDir()
|
||||
VENDOR_DIR = config.GetVendorDir()
|
||||
BACKUP_DIR = config.GetBackupDir()
|
||||
CATALOGUE_DIR = config.GetCatalogueDir()
|
||||
RECIPES_JSON = path.Join(config.GetCatalogueDir(), "recipes.json")
|
||||
REPOS_BASE_URL = "https://git.coopcloud.tech/coop-cloud"
|
||||
|
Reference in New Issue
Block a user