mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-25 05:47:57 +02:00
Mark user interface strings
For now exclude command help, as cobra itself is not localizable yet.
This commit is contained in:
parent
511b71b909
commit
d6ca8d33f7
27 changed files with 1005 additions and 95 deletions
|
@ -22,6 +22,7 @@ import (
|
|||
|
||||
"github.com/spf13/cobra"
|
||||
"go.uploadedlobster.com/scotty/internal/backends"
|
||||
"go.uploadedlobster.com/scotty/internal/i18n"
|
||||
)
|
||||
|
||||
var backendsCmd = &cobra.Command{
|
||||
|
@ -32,8 +33,8 @@ var backendsCmd = &cobra.Command{
|
|||
backends := backends.GetBackends()
|
||||
for _, info := range backends {
|
||||
fmt.Printf("%s:\n", info.Name)
|
||||
fmt.Printf("\texport: %s\n", strings.Join(info.ExportCapabilities, ", "))
|
||||
fmt.Printf("\timport: %s\n\n", strings.Join(info.ImportCapabilities, ", "))
|
||||
fmt.Println(i18n.Tr("\texport: %s", strings.Join(info.ExportCapabilities, ", ")))
|
||||
fmt.Println(i18n.Tr("\timport: %s\n", strings.Join(info.ImportCapabilities, ", ")))
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
@ -26,7 +26,8 @@ var beamCmd = &cobra.Command{
|
|||
Long: `Transfers data (listens, loves) between two configured services.
|
||||
|
||||
The services must be configured and be able to handle export and import of
|
||||
the data.`,
|
||||
the data. See "scotty backends" for a list of backends and their supported
|
||||
features.`,
|
||||
// Run: func(cmd *cobra.Command, args []string) { },
|
||||
}
|
||||
|
||||
|
|
10
cmd/root.go
10
cmd/root.go
|
@ -21,8 +21,8 @@ import (
|
|||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"go.uploadedlobster.com/scotty/internal/config"
|
||||
"go.uploadedlobster.com/scotty/internal/i18n"
|
||||
"go.uploadedlobster.com/scotty/internal/version"
|
||||
)
|
||||
|
||||
|
@ -32,8 +32,8 @@ var cfgFile string
|
|||
var rootCmd = &cobra.Command{
|
||||
Use: version.AppName,
|
||||
Short: "Beam data between music listening services",
|
||||
Long: `Scotty transfers your listens/scrobbles between ListenBrainz and
|
||||
various other listening and streaming services.`,
|
||||
Long: `Scotty transfers listens and loves between different listening and streaming
|
||||
services. Run "scotty backends" for a list of supported service backends.`,
|
||||
Version: version.AppVersion,
|
||||
// Uncomment the following line if your bare application
|
||||
// has an action associated with it:
|
||||
|
@ -69,8 +69,6 @@ func init() {
|
|||
func initConfig() {
|
||||
// If a config file is found, read it in.
|
||||
if err := config.InitConfig(cfgFile); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Failed reading config:", err)
|
||||
} else {
|
||||
fmt.Println("Using config file:", viper.ConfigFileUsed())
|
||||
fmt.Fprintln(os.Stderr, i18n.Tr("Failed reading config: %v", err))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,12 +29,13 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
"go.uploadedlobster.com/scotty/internal/cli"
|
||||
"go.uploadedlobster.com/scotty/internal/config"
|
||||
"go.uploadedlobster.com/scotty/internal/i18n"
|
||||
)
|
||||
|
||||
var serviceAddCmd = &cobra.Command{
|
||||
Use: "add",
|
||||
Short: "Add a service configuration",
|
||||
Long: `Add a service configuration.`,
|
||||
Long: `Interactively add a service to the configuration file.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// Select backend
|
||||
backend, err := cli.SelectBackend("")
|
||||
|
@ -42,12 +43,12 @@ var serviceAddCmd = &cobra.Command{
|
|||
|
||||
// Set service name
|
||||
prompt := promptui.Prompt{
|
||||
Label: "Service name",
|
||||
Label: i18n.Tr("Service name"),
|
||||
Default: backend,
|
||||
Validate: func(s string) error {
|
||||
srv, _ := config.GetService(s)
|
||||
if srv != nil {
|
||||
return errors.New("a service with this name already exists")
|
||||
return errors.New(i18n.Tr("a service with this name already exists"))
|
||||
}
|
||||
return config.ValidateKey(s)
|
||||
},
|
||||
|
@ -69,7 +70,7 @@ var serviceAddCmd = &cobra.Command{
|
|||
// Save the service config
|
||||
err = service.Save()
|
||||
cobra.CheckErr(err)
|
||||
fmt.Printf("Saved service %v using backend %v\n", service.Name, service.Backend)
|
||||
fmt.Println(i18n.Tr("Saved service %v using backend %v", service.Name, service.Backend))
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ import (
|
|||
"go.uploadedlobster.com/scotty/internal/backends"
|
||||
"go.uploadedlobster.com/scotty/internal/cli"
|
||||
"go.uploadedlobster.com/scotty/internal/config"
|
||||
"go.uploadedlobster.com/scotty/internal/i18n"
|
||||
"go.uploadedlobster.com/scotty/internal/models"
|
||||
"go.uploadedlobster.com/scotty/internal/storage"
|
||||
"golang.org/x/oauth2"
|
||||
|
@ -35,12 +36,16 @@ import (
|
|||
|
||||
var serviceAuthCmd = &cobra.Command{
|
||||
Use: "auth",
|
||||
Short: "Authenticate with a backend",
|
||||
Long: `For backends requiring authentication this command can be used to authenticate.`,
|
||||
Short: "Authenticate a service",
|
||||
Long: `For backends requiring authentication this command can be used to authenticate.
|
||||
|
||||
Authentication is always done per configured service. That means you can have
|
||||
multiple services using the same backend but different authentication.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
serviceConfig := cli.GetServiceConfigFromFlag(cmd, "service")
|
||||
if serviceConfig == nil {
|
||||
cobra.CheckErr(errors.New("failed loading service configuration"))
|
||||
err := errors.New(i18n.Tr("failed loading service configuration"))
|
||||
cobra.CheckErr(err)
|
||||
}
|
||||
backend, err := backends.ResolveBackend[models.OAuth2Authenticator](serviceConfig)
|
||||
cobra.CheckErr(err)
|
||||
|
@ -64,14 +69,14 @@ var serviceAuthCmd = &cobra.Command{
|
|||
auth.RunOauth2CallbackServer(*redirectURL, authUrl.Param, responseChan)
|
||||
|
||||
// Open the URL
|
||||
fmt.Printf("Visit the URL for the auth dialog: %v\n", authUrl.Url)
|
||||
fmt.Println(i18n.Tr("Visit the URL for authorization: %v", authUrl.Url))
|
||||
err = browser.OpenURL(authUrl.Url)
|
||||
cobra.CheckErr(err)
|
||||
|
||||
// Retrieve the code from the authentication callback
|
||||
code := <-responseChan
|
||||
if code.State != authUrl.State {
|
||||
cobra.CompErrorln("Error: oauth state mismatch")
|
||||
cobra.CompErrorln(i18n.Tr("Error: OAuth state mismatch"))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
@ -86,13 +91,13 @@ var serviceAuthCmd = &cobra.Command{
|
|||
err = db.SetOAuth2Token(serviceConfig.Name, tok)
|
||||
cobra.CheckErr(err)
|
||||
|
||||
fmt.Printf("Access token received, you can use %v now.\n\n", serviceConfig.Name)
|
||||
fmt.Println(i18n.Tr("Access token received, you can use %v now.\n", serviceConfig.Name))
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
serviceCmd.AddCommand(serviceAuthCmd)
|
||||
|
||||
serviceAuthCmd.Flags().StringP("service", "s", "", "Service configuration (required)")
|
||||
serviceAuthCmd.Flags().StringP("service", "s", "", "service configuration (required)")
|
||||
serviceAuthCmd.MarkFlagRequired("service")
|
||||
}
|
||||
|
|
|
@ -26,29 +26,30 @@ import (
|
|||
|
||||
"github.com/spf13/cobra"
|
||||
"go.uploadedlobster.com/scotty/internal/cli"
|
||||
"go.uploadedlobster.com/scotty/internal/i18n"
|
||||
)
|
||||
|
||||
var serviceDeleteCmd = &cobra.Command{
|
||||
Use: "delete",
|
||||
Short: "Delete existing service configuration",
|
||||
Long: `Delete an existing service configuration.`,
|
||||
Long: `Delete an existing service from the configuration file.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
service, err := cli.SelectService()
|
||||
cobra.CheckErr(err)
|
||||
|
||||
// Prompt for deletion
|
||||
delete, err := cli.PromptYesNo(fmt.Sprintf("Delete the service configuration \"%v\"?", service))
|
||||
delete, err := cli.PromptYesNo(i18n.Tr("Delete the service configuration \"%v\"?", service))
|
||||
cobra.CheckErr(err)
|
||||
|
||||
if !delete {
|
||||
fmt.Println("Aborted")
|
||||
fmt.Println(i18n.Tr("Aborted"))
|
||||
return
|
||||
}
|
||||
|
||||
// Delete the service config
|
||||
err = service.Delete()
|
||||
cobra.CheckErr(err)
|
||||
fmt.Printf("Service \"%v\" deleted\n", service.Name)
|
||||
fmt.Println(i18n.Tr("Service \"%v\" deleted\n", service.Name))
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -26,12 +26,13 @@ import (
|
|||
|
||||
"github.com/spf13/cobra"
|
||||
"go.uploadedlobster.com/scotty/internal/cli"
|
||||
"go.uploadedlobster.com/scotty/internal/i18n"
|
||||
)
|
||||
|
||||
var serviceEditCmd = &cobra.Command{
|
||||
Use: "edit",
|
||||
Short: "Edit existing service configuration",
|
||||
Long: `Edit an existing service configuration.`,
|
||||
Long: `Edit an existing service in the configuration file.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
service, err := cli.SelectService()
|
||||
cobra.CheckErr(err)
|
||||
|
@ -48,7 +49,7 @@ var serviceEditCmd = &cobra.Command{
|
|||
// Save the service config
|
||||
err = service.Save()
|
||||
cobra.CheckErr(err)
|
||||
fmt.Printf("Updated service %v using backend %v\n", service.Name, service.Backend)
|
||||
fmt.Println(i18n.Tr("Updated service %v using backend %v\n", service.Name, service.Backend))
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
|
||||
"github.com/spf13/cobra"
|
||||
"go.uploadedlobster.com/scotty/internal/config"
|
||||
"go.uploadedlobster.com/scotty/internal/i18n"
|
||||
)
|
||||
|
||||
var serviceListCmd = &cobra.Command{
|
||||
|
@ -37,7 +38,7 @@ var serviceListCmd = &cobra.Command{
|
|||
for _, s := range config.AllServicesAsList() {
|
||||
fmt.Printf("%v\n", s.Name)
|
||||
if verbose {
|
||||
fmt.Printf("\tbackend: %v\n", s.Backend)
|
||||
fmt.Println(i18n.Tr("\tbackend: %v", s.Backend))
|
||||
for k, v := range s.ConfigValues {
|
||||
fmt.Printf("\t%v: %v\n", k, v)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue