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 (
|
||||
|
||||
"coopcloud.tech/abra/pkg/app"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"coopcloud.tech/abra/pkg/i18n"
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"coopcloud.tech/abra/pkg/recipe"
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
@ -31,7 +32,7 @@ func ValidateRecipe(args []string, cmdName string) recipe.Recipe {
|
||||
|
||||
localRecipes, err := recipe.GetRecipesLocal()
|
||||
if err != nil {
|
||||
log.Debugf("can't read local recipes: %s", err)
|
||||
log.Debug(i18n.G("can't read local recipes: %s", err))
|
||||
} else {
|
||||
for _, recipeLocal := range localRecipes {
|
||||
if _, ok := knownRecipes[recipeLocal]; !ok {
|
||||
@ -46,7 +47,7 @@ func ValidateRecipe(args []string, cmdName string) recipe.Recipe {
|
||||
|
||||
if recipeName == "" && !NoInput {
|
||||
prompt := &survey.Select{
|
||||
Message: "Select recipe",
|
||||
Message: i18n.G("Select recipe"),
|
||||
Options: recipes,
|
||||
}
|
||||
if err := survey.AskOne(prompt, &recipeName); err != nil {
|
||||
@ -55,12 +56,12 @@ func ValidateRecipe(args []string, cmdName string) recipe.Recipe {
|
||||
}
|
||||
|
||||
if recipeName == "" {
|
||||
log.Fatal("no recipe name provided")
|
||||
log.Fatal(i18n.G("no recipe name provided"))
|
||||
}
|
||||
|
||||
if _, ok := knownRecipes[recipeName]; !ok {
|
||||
if !strings.Contains(recipeName, "/") {
|
||||
log.Fatalf("no recipe '%s' exists?", recipeName)
|
||||
log.Fatal(i18n.G("no recipe '%s' exists?", recipeName))
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,20 +72,20 @@ func ValidateRecipe(args []string, cmdName string) recipe.Recipe {
|
||||
|
||||
_, err = chosenRecipe.GetComposeConfig(nil)
|
||||
if err != nil {
|
||||
if cmdName == "generate" {
|
||||
if cmdName == i18n.G("generate") {
|
||||
if strings.Contains(err.Error(), "missing a compose") {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Warn(err)
|
||||
} else {
|
||||
if strings.Contains(err.Error(), "template_driver is not allowed") {
|
||||
log.Warnf("ensure %s recipe compose.* files include \"version: '3.8'\"", recipeName)
|
||||
log.Warn(i18n.G("ensure %s recipe compose.* files include \"version: '3.8'\"", recipeName))
|
||||
}
|
||||
log.Fatalf("unable to validate recipe: %s", err)
|
||||
log.Fatal(i18n.G("unable to validate recipe: %s", err))
|
||||
}
|
||||
}
|
||||
|
||||
log.Debugf("validated %s as recipe argument", recipeName)
|
||||
log.Debug(i18n.G("validated %s as recipe argument", recipeName))
|
||||
|
||||
return chosenRecipe
|
||||
}
|
||||
@ -92,7 +93,7 @@ func ValidateRecipe(args []string, cmdName string) recipe.Recipe {
|
||||
// ValidateApp ensures the app name arg is valid.
|
||||
func ValidateApp(args []string) app.App {
|
||||
if len(args) == 0 {
|
||||
log.Fatal("no app provided")
|
||||
log.Fatal(i18n.G("no app provided"))
|
||||
}
|
||||
|
||||
appName := args[0]
|
||||
@ -102,7 +103,7 @@ func ValidateApp(args []string) app.App {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Debugf("validated %s as app argument", appName)
|
||||
log.Debug(i18n.G("validated %s as app argument", appName))
|
||||
|
||||
return app
|
||||
}
|
||||
@ -116,8 +117,8 @@ func ValidateDomain(args []string) string {
|
||||
|
||||
if domainName == "" && !NoInput {
|
||||
prompt := &survey.Input{
|
||||
Message: "Specify a domain name",
|
||||
Default: "example.com",
|
||||
Message: i18n.G("Specify a domain name"),
|
||||
Default: "1312.net",
|
||||
}
|
||||
if err := survey.AskOne(prompt, &domainName); err != nil {
|
||||
log.Fatal(err)
|
||||
@ -125,10 +126,10 @@ func ValidateDomain(args []string) string {
|
||||
}
|
||||
|
||||
if domainName == "" {
|
||||
log.Fatal("no domain provided")
|
||||
log.Fatal(i18n.G("no domain provided"))
|
||||
}
|
||||
|
||||
log.Debugf("validated %s as domain argument", domainName)
|
||||
log.Debug(i18n.G("validated %s as domain argument", domainName))
|
||||
|
||||
return domainName
|
||||
}
|
||||
@ -147,7 +148,7 @@ func ValidateServer(args []string) string {
|
||||
|
||||
if serverName == "" && !NoInput {
|
||||
prompt := &survey.Select{
|
||||
Message: "Specify a server name",
|
||||
Message: i18n.G("Specify a server name"),
|
||||
Options: serverNames,
|
||||
}
|
||||
if err := survey.AskOne(prompt, &serverName); err != nil {
|
||||
@ -163,14 +164,14 @@ func ValidateServer(args []string) string {
|
||||
}
|
||||
|
||||
if serverName == "" {
|
||||
log.Fatal("no server provided")
|
||||
log.Fatal(i18n.G("no server provided"))
|
||||
}
|
||||
|
||||
if !matched {
|
||||
log.Fatal("server doesn't exist?")
|
||||
log.Fatal(i18n.G("server doesn't exist?"))
|
||||
}
|
||||
|
||||
log.Debugf("validated %s as server argument", serverName)
|
||||
log.Debug(i18n.G("validated %s as server argument", serverName))
|
||||
|
||||
return serverName
|
||||
}
|
||||
|
Reference in New Issue
Block a user