Mark user interface strings

For now exclude command help, as cobra itself is not localizable yet.
This commit is contained in:
Philipp Wolfer 2023-12-09 16:43:14 +01:00
parent 511b71b909
commit d6ca8d33f7
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
27 changed files with 1005 additions and 95 deletions

View file

@ -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")
}