chore: make usage strings translatable

This commit is contained in:
Maxim Slipenko 2025-01-22 17:16:15 +03:00
parent b9bf908007
commit 30f95a4cbf
12 changed files with 789 additions and 584 deletions

@ -35,25 +35,26 @@ import (
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/repos"
)
var buildCmd = &cli.Command{
func BuildCmd() *cli.Command {
return &cli.Command{
Name: "build",
Usage: "Build a local package",
Usage: gotext.Get("Build a local package"),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "script",
Aliases: []string{"s"},
Value: "alr.sh",
Usage: "Path to the build script",
Usage: gotext.Get("Path to the build script"),
},
&cli.StringFlag{
Name: "package",
Aliases: []string{"p"},
Usage: "Name of the package to build and its repo (example: default/go-bin)",
Usage: gotext.Get("Name of the package to build and its repo (example: default/go-bin)"),
},
&cli.BoolFlag{
Name: "clean",
Aliases: []string{"c"},
Usage: "Build package from scratch even if there's an already built package available",
Usage: gotext.Get("Build package from scratch even if there's an already built package available"),
},
},
Action: func(c *cli.Context) error {
@ -105,3 +106,4 @@ var buildCmd = &cli.Command{
return nil
},
}
}

6
fix.go

@ -31,9 +31,10 @@ import (
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/repos"
)
var fixCmd = &cli.Command{
func FixCmd() *cli.Command {
return &cli.Command{
Name: "fix",
Usage: "Attempt to fix problems with ALR",
Usage: gotext.Get("Attempt to fix problems with ALR"),
Action: func(c *cli.Context) error {
ctx := c.Context
@ -67,3 +68,4 @@ var fixCmd = &cli.Command{
return nil
},
}
}

17
gen.go

@ -22,23 +22,21 @@ package main
import (
"os"
"github.com/leonelquinteros/gotext"
"github.com/urfave/cli/v2"
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/gen"
)
var genCmd = &cli.Command{
func GenCmd() *cli.Command {
return &cli.Command{
Name: "generate",
Usage: "Generate a ALR script from a template",
Usage: gotext.Get("Generate a ALR script from a template"),
Aliases: []string{"gen"},
Subcommands: []*cli.Command{
genPipCmd,
},
}
var genPipCmd = &cli.Command{
&cli.Command{
Name: "pip",
Usage: "Generate a ALR script for a pip module",
Usage: gotext.Get("Generate a ALR script for a pip module"),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "name",
@ -62,4 +60,7 @@ var genPipCmd = &cli.Command{
Description: c.String("description"),
})
},
},
},
}
}

@ -35,16 +35,29 @@ import (
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/distro"
)
var helperCmd = &cli.Command{
func HelperCmd() *cli.Command {
var helperListCmd = &cli.Command{
Name: "list",
Usage: gotext.Get("List all the available helper commands"),
Aliases: []string{"ls"},
Action: func(ctx *cli.Context) error {
for name := range helpers.Helpers {
fmt.Println(name)
}
return nil
},
}
return &cli.Command{
Name: "helper",
Usage: "Run a ALR helper command",
Usage: gotext.Get("Run a ALR helper command"),
ArgsUsage: `<helper_name|"list">`,
Subcommands: []*cli.Command{helperListCmd},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "dest-dir",
Aliases: []string{"d"},
Usage: "The directory that the install commands will install to",
Usage: gotext.Get("The directory that the install commands will install to"),
Value: "dest",
},
},
@ -95,15 +108,4 @@ var helperCmd = &cli.Command{
}
},
}
var helperListCmd = &cli.Command{
Name: "list",
Usage: "List all the available helper commands",
Aliases: []string{"ls"},
Action: func(ctx *cli.Context) error {
for name := range helpers.Helpers {
fmt.Println(name)
}
return nil
},
}

@ -36,7 +36,7 @@ import (
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/repos"
)
func GetInfoCmd() *cli.Command {
func InfoCmd() *cli.Command {
return &cli.Command{
Name: "info",
Usage: gotext.Get("Print information about a package"),

@ -36,9 +36,11 @@ import (
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/repos"
)
var installCmd = &cli.Command{
func InstallCmd() *cli.Command {
return &cli.Command{
Name: "install",
Usage: "Install a new package",
Usage: gotext.Get("Install a new package"),
Aliases: []string{"in"},
Flags: []cli.Flag{
&cli.BoolFlag{
@ -102,10 +104,12 @@ var installCmd = &cli.Command{
}
},
}
}
var removeCmd = &cli.Command{
func RemoveCmd() *cli.Command {
return &cli.Command{
Name: "remove",
Usage: "Remove an installed package",
Usage: gotext.Get("Remove an installed package"),
Aliases: []string{"rm"},
Action: func(c *cli.Context) error {
args := c.Args()
@ -129,3 +133,4 @@ var removeCmd = &cli.Command{
return nil
},
}
}

@ -9,51 +9,92 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: build.go:69
#: build.go:41
msgid "Build a local package"
msgstr ""
#: build.go:47
msgid "Path to the build script"
msgstr ""
#: build.go:52
msgid "Name of the package to build and its repo (example: default/go-bin)"
msgstr ""
#: build.go:57
msgid ""
"Build package from scratch even if there's an already built package available"
msgstr ""
#: build.go:70
msgid "Error pulling repositories"
msgstr ""
#: build.go:75
#: build.go:76
msgid "Unable to detect a supported package manager on the system"
msgstr ""
#: build.go:86
#: build.go:87
msgid "Error building package"
msgstr ""
#: build.go:92
#: build.go:93
msgid "Error getting working directory"
msgstr ""
#: build.go:100
#: build.go:101
msgid "Error moving the package"
msgstr ""
#: fix.go:43
#: fix.go:37
msgid "Attempt to fix problems with ALR"
msgstr ""
#: fix.go:44
msgid "Removing cache directory"
msgstr ""
#: fix.go:47
#: fix.go:48
msgid "Unable to remove cache directory"
msgstr ""
#: fix.go:51
#: fix.go:52
msgid "Rebuilding cache"
msgstr ""
#: fix.go:55
#: fix.go:56
msgid "Unable to create new cache directory"
msgstr ""
#: fix.go:61
#: fix.go:62
msgid "Error pulling repos"
msgstr ""
#: fix.go:65
#: fix.go:66
msgid "Done"
msgstr ""
#: gen.go:34
msgid "Generate a ALR script from a template"
msgstr ""
#: gen.go:39
msgid "Generate a ALR script for a pip module"
msgstr ""
#: helper.go:41
msgid "List all the available helper commands"
msgstr ""
#: helper.go:53
msgid "Run a ALR helper command"
msgstr ""
#: helper.go:60
msgid "The directory that the install commands will install to"
msgstr ""
#: helper.go:73
msgid "No such helper command"
msgstr ""
@ -85,23 +126,27 @@ msgstr ""
msgid "Error encoding script variables"
msgstr ""
#: install.go:55
#: install.go:57
msgid "Command install expected at least 1 argument, got %d"
msgstr ""
#: install.go:88
#: install.go:90
msgid "Error getting packages"
msgstr ""
#: install.go:97
#: install.go:99
msgid "Error iterating over packages"
msgstr ""
#: install.go:113
#: install.go:112
msgid "Remove an installed package"
msgstr ""
#: install.go:117
msgid "Command remove expected at least 1 argument, got %d"
msgstr ""
#: install.go:125
#: install.go:129
msgid "Error removing packages"
msgstr ""
@ -202,21 +247,37 @@ msgstr ""
msgid "ERROR"
msgstr ""
#: list.go:53
#: list.go:40
msgid "List ALR repo packages"
msgstr ""
#: list.go:54
msgid "Error initialization database"
msgstr ""
#: list.go:87
#: list.go:88
msgid "Error listing installed packages"
msgstr ""
#: main.go:88
#: main.go:45
msgid "Print the current ALR version and exit"
msgstr ""
#: main.go:61
msgid "Arguments to be passed on to the package manager"
msgstr ""
#: main.go:67
msgid "Enable interactive questions and prompts"
msgstr ""
#: main.go:90
msgid ""
"Running ALR as root is forbidden as it may cause catastrophic damage to your "
"system"
msgstr ""
#: main.go:122
#: main.go:124
msgid "Error while running app"
msgstr ""
@ -328,26 +389,54 @@ msgid ""
"updating ALR if something doesn't work."
msgstr ""
#: repo.go:78 repo.go:133
#: repo.go:41
msgid "Add a new repository"
msgstr ""
#: repo.go:48
msgid "Name of the new repo"
msgstr ""
#: repo.go:54
msgid "URL of the new repo"
msgstr ""
#: repo.go:79 repo.go:136
msgid "Error opening config file"
msgstr ""
#: repo.go:84 repo.go:139
#: repo.go:85 repo.go:142
msgid "Error encoding config"
msgstr ""
#: repo.go:125
#: repo.go:103
msgid "Remove an existing repository"
msgstr ""
#: repo.go:110
msgid "Name of the repo to be deleted"
msgstr ""
#: repo.go:128
msgid "Repo does not exist"
msgstr ""
#: repo.go:145
#: repo.go:148
msgid "Error removing repo directory"
msgstr ""
#: repo.go:151
#: repo.go:154
msgid "Error removing packages from database"
msgstr ""
#: upgrade.go:78
#: repo.go:166
msgid "Pull all repositories that have changed"
msgstr ""
#: upgrade.go:47
msgid "Upgrade all installed packages"
msgstr ""
#: upgrade.go:79
msgid "Error checking for updates"
msgstr ""

@ -11,55 +11,98 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && "
"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
"X-Generator: Gtranslator 47.1\n"
#: build.go:69
#: build.go:41
#, fuzzy
msgid "Build a local package"
msgstr "Сборка пакета"
#: build.go:47
#, fuzzy
msgid "Path to the build script"
msgstr "Не удалось предложить просмотреть скрипт"
#: build.go:52
msgid "Name of the package to build and its repo (example: default/go-bin)"
msgstr ""
#: build.go:57
msgid ""
"Build package from scratch even if there's an already built package available"
msgstr ""
#: build.go:70
msgid "Error pulling repositories"
msgstr ""
#: build.go:75
#: build.go:76
msgid "Unable to detect a supported package manager on the system"
msgstr ""
#: build.go:86
#: build.go:87
msgid "Error building package"
msgstr "Ошибка при сборке пакета"
#: build.go:92
#: build.go:93
msgid "Error getting working directory"
msgstr ""
#: build.go:100
#: build.go:101
msgid "Error moving the package"
msgstr ""
#: fix.go:43
#: fix.go:37
msgid "Attempt to fix problems with ALR"
msgstr ""
#: fix.go:44
msgid "Removing cache directory"
msgstr ""
#: fix.go:47
#: fix.go:48
msgid "Unable to remove cache directory"
msgstr ""
#: fix.go:51
#: fix.go:52
msgid "Rebuilding cache"
msgstr ""
#: fix.go:55
#: fix.go:56
msgid "Unable to create new cache directory"
msgstr ""
#: fix.go:61
#: fix.go:62
msgid "Error pulling repos"
msgstr ""
#: fix.go:65
#: fix.go:66
msgid "Done"
msgstr ""
#: gen.go:34
msgid "Generate a ALR script from a template"
msgstr ""
#: gen.go:39
msgid "Generate a ALR script for a pip module"
msgstr ""
#: helper.go:41
msgid "List all the available helper commands"
msgstr ""
#: helper.go:53
msgid "Run a ALR helper command"
msgstr ""
#: helper.go:60
msgid "The directory that the install commands will install to"
msgstr ""
#: helper.go:73
msgid "No such helper command"
msgstr ""
@ -91,23 +134,27 @@ msgstr ""
msgid "Error encoding script variables"
msgstr ""
#: install.go:55
#: install.go:57
msgid "Command install expected at least 1 argument, got %d"
msgstr ""
#: install.go:88
#: install.go:90
msgid "Error getting packages"
msgstr ""
#: install.go:97
#: install.go:99
msgid "Error iterating over packages"
msgstr ""
#: install.go:113
#: install.go:112
msgid "Remove an installed package"
msgstr ""
#: install.go:117
msgid "Command remove expected at least 1 argument, got %d"
msgstr ""
#: install.go:125
#: install.go:129
msgid "Error removing packages"
msgstr ""
@ -208,21 +255,37 @@ msgstr "Скачивание источника"
msgid "ERROR"
msgstr "ОШИБКА"
#: list.go:53
#: list.go:40
msgid "List ALR repo packages"
msgstr ""
#: list.go:54
msgid "Error initialization database"
msgstr ""
#: list.go:87
#: list.go:88
msgid "Error listing installed packages"
msgstr ""
#: main.go:88
#: main.go:45
msgid "Print the current ALR version and exit"
msgstr ""
#: main.go:61
msgid "Arguments to be passed on to the package manager"
msgstr ""
#: main.go:67
msgid "Enable interactive questions and prompts"
msgstr ""
#: main.go:90
msgid ""
"Running ALR as root is forbidden as it may cause catastrophic damage to your "
"system"
msgstr ""
#: main.go:122
#: main.go:124
msgid "Error while running app"
msgstr ""
@ -334,26 +397,55 @@ msgid ""
"updating ALR if something doesn't work."
msgstr ""
#: repo.go:78 repo.go:133
#: repo.go:41
#, fuzzy
msgid "Add a new repository"
msgstr "Скачивание репозитория"
#: repo.go:48
msgid "Name of the new repo"
msgstr ""
#: repo.go:54
msgid "URL of the new repo"
msgstr ""
#: repo.go:79 repo.go:136
msgid "Error opening config file"
msgstr ""
#: repo.go:84 repo.go:139
#: repo.go:85 repo.go:142
msgid "Error encoding config"
msgstr ""
#: repo.go:125
#: repo.go:103
msgid "Remove an existing repository"
msgstr ""
#: repo.go:110
msgid "Name of the repo to be deleted"
msgstr ""
#: repo.go:128
msgid "Repo does not exist"
msgstr ""
#: repo.go:145
#: repo.go:148
msgid "Error removing repo directory"
msgstr ""
#: repo.go:151
#: repo.go:154
msgid "Error removing packages from database"
msgstr ""
#: upgrade.go:78
#: repo.go:166
msgid "Pull all repositories that have changed"
msgstr ""
#: upgrade.go:47
msgid "Upgrade all installed packages"
msgstr ""
#: upgrade.go:79
msgid "Error checking for updates"
msgstr ""

@ -34,9 +34,10 @@ import (
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/repos"
)
var listCmd = &cli.Command{
func ListCmd() *cli.Command {
return &cli.Command{
Name: "list",
Usage: "List ALR repo packages",
Usage: gotext.Get("List ALR repo packages"),
Aliases: []string{"ls"},
Flags: []cli.Flag{
&cli.BoolFlag{
@ -121,3 +122,4 @@ var listCmd = &cli.Command{
return nil
},
}
}

36
main.go

@ -39,14 +39,16 @@ import (
"gitea.plemya-x.ru/Plemya-x/ALR/internal/logger"
)
var versionCmd = &cli.Command{
func VersionCmd() *cli.Command {
return &cli.Command{
Name: "version",
Usage: "Print the current ALR version and exit",
Usage: gotext.Get("Print the current ALR version and exit"),
Action: func(ctx *cli.Context) error {
println(config.Version)
return nil
},
}
}
func GetApp() *cli.App {
return &cli.App{
@ -56,29 +58,29 @@ func GetApp() *cli.App {
&cli.StringFlag{
Name: "pm-args",
Aliases: []string{"P"},
Usage: "Arguments to be passed on to the package manager",
Usage: gotext.Get("Arguments to be passed on to the package manager"),
},
&cli.BoolFlag{
Name: "interactive",
Aliases: []string{"i"},
Value: isatty.IsTerminal(os.Stdin.Fd()),
Usage: "Enable interactive questions and prompts",
Usage: gotext.Get("Enable interactive questions and prompts"),
},
},
Commands: []*cli.Command{
installCmd,
removeCmd,
upgradeCmd,
GetInfoCmd(),
listCmd,
buildCmd,
addrepoCmd,
removerepoCmd,
refreshCmd,
fixCmd,
genCmd,
helperCmd,
versionCmd,
InstallCmd(),
RemoveCmd(),
UpgradeCmd(),
InfoCmd(),
ListCmd(),
BuildCmd(),
AddRepoCmd(),
RemoveRepoCmd(),
RefreshCmd(),
FixCmd(),
GenCmd(),
HelperCmd(),
VersionCmd(),
},
Before: func(c *cli.Context) error {
ctx := c.Context

24
repo.go

@ -35,22 +35,23 @@ import (
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/repos"
)
var addrepoCmd = &cli.Command{
func AddRepoCmd() *cli.Command {
return &cli.Command{
Name: "addrepo",
Usage: "Add a new repository",
Usage: gotext.Get("Add a new repository"),
Aliases: []string{"ar"},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "name",
Aliases: []string{"n"},
Required: true,
Usage: "Name of the new repo",
Usage: gotext.Get("Name of the new repo"),
},
&cli.StringFlag{
Name: "url",
Aliases: []string{"u"},
Required: true,
Usage: "URL of the new repo",
Usage: gotext.Get("URL of the new repo"),
},
},
Action: func(c *cli.Context) error {
@ -94,17 +95,19 @@ var addrepoCmd = &cli.Command{
return nil
},
}
}
var removerepoCmd = &cli.Command{
func RemoveRepoCmd() *cli.Command {
return &cli.Command{
Name: "removerepo",
Usage: "Remove an existing repository",
Usage: gotext.Get("Remove an existing repository"),
Aliases: []string{"rr"},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "name",
Aliases: []string{"n"},
Required: true,
Usage: "Name of the repo to be deleted",
Usage: gotext.Get("Name of the repo to be deleted"),
},
},
Action: func(c *cli.Context) error {
@ -155,10 +158,12 @@ var removerepoCmd = &cli.Command{
return nil
},
}
}
var refreshCmd = &cli.Command{
func RefreshCmd() *cli.Command {
return &cli.Command{
Name: "refresh",
Usage: "Pull all repositories that have changed",
Usage: gotext.Get("Pull all repositories that have changed"),
Aliases: []string{"ref"},
Action: func(c *cli.Context) error {
ctx := c.Context
@ -170,3 +175,4 @@ var refreshCmd = &cli.Command{
return nil
},
}
}

@ -41,15 +41,16 @@ import (
"gitea.plemya-x.ru/Plemya-x/ALR/pkg/repos"
)
var upgradeCmd = &cli.Command{
func UpgradeCmd() *cli.Command {
return &cli.Command{
Name: "upgrade",
Usage: "Upgrade all installed packages",
Usage: gotext.Get("Upgrade all installed packages"),
Aliases: []string{"up"},
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "clean",
Aliases: []string{"c"},
Usage: "Build package from scratch even if there's an already built package available",
Usage: gotext.Get("Build package from scratch even if there's an already built package available"),
},
},
Action: func(c *cli.Context) error {
@ -92,6 +93,7 @@ var upgradeCmd = &cli.Command{
return nil
},
}
}
func checkForUpdates(ctx context.Context, mgr manager.Manager, info *distro.OSRelease) ([]db.Package, error) {
installed, err := mgr.ListInstalled(nil)