1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-05-21 22:43:27 +02:00

localize update errors

This commit is contained in:
Jesse Duffield 2018-08-27 20:23:47 +10:00
parent 38557f131d
commit 25c60b1854
3 changed files with 23 additions and 5 deletions

View File

@ -56,7 +56,7 @@ func NewApp(config config.AppConfigurer) (*App, error) {
if err != nil { if err != nil {
return app, err return app, err
} }
app.Updater, err = updates.NewUpdater(app.Log, config, app.OSCommand) app.Updater, err = updates.NewUpdater(app.Log, config, app.OSCommand, app.Tr)
if err != nil { if err != nil {
return app, err return app, err
} }

View File

@ -318,6 +318,15 @@ func addEnglish(i18nObject *i18n.Bundle) error {
}, &i18n.Message{ }, &i18n.Message{
ID: "CheckingForUpdates", ID: "CheckingForUpdates",
Other: "Checking for updates...", Other: "Checking for updates...",
}, &i18n.Message{
ID: "OnLatestVersionErr",
Other: "You already have the latest version",
}, &i18n.Message{
ID: "MajorVersionErr",
Other: "New version has non-backwards compatible changes.",
}, &i18n.Message{
ID: "CouldNotFindBinaryErr",
Other: "Could not find any binary at {{.url}}",
}, },
) )
} }

View File

@ -18,6 +18,7 @@ import (
getter "github.com/jesseduffield/go-getter" getter "github.com/jesseduffield/go-getter"
"github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/i18n"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -26,6 +27,7 @@ type Updater struct {
Log *logrus.Entry Log *logrus.Entry
Config config.AppConfigurer Config config.AppConfigurer
OSCommand *commands.OSCommand OSCommand *commands.OSCommand
Tr *i18n.Localizer
} }
// Updater implements the check and update methods // Updater implements the check and update methods
@ -39,13 +41,14 @@ var (
) )
// NewUpdater creates a new updater // NewUpdater creates a new updater
func NewUpdater(log *logrus.Logger, config config.AppConfigurer, osCommand *commands.OSCommand) (*Updater, error) { func NewUpdater(log *logrus.Logger, config config.AppConfigurer, osCommand *commands.OSCommand, tr *i18n.Localizer) (*Updater, error) {
contextLogger := log.WithField("context", "updates") contextLogger := log.WithField("context", "updates")
updater := &Updater{ updater := &Updater{
Log: contextLogger, Log: contextLogger,
Config: config, Config: config,
OSCommand: osCommand, OSCommand: osCommand,
Tr: tr,
} }
return updater, nil return updater, nil
} }
@ -102,11 +105,11 @@ func (u *Updater) checkForNewUpdate() (string, error) {
u.Log.Info("New version is " + newVersion) u.Log.Info("New version is " + newVersion)
if newVersion == u.Config.GetVersion() { if newVersion == u.Config.GetVersion() {
return "", errors.New("You already have the latest version") return "", errors.New(u.Tr.SLocalize("OnLatestVersionErr"))
} }
if u.majorVersionDiffers(u.Config.GetVersion(), newVersion) { if u.majorVersionDiffers(u.Config.GetVersion(), newVersion) {
return "", errors.New("New version has non-backwards compatible changes.") return "", errors.New(u.Tr.SLocalize("MajorVersionErr"))
} }
rawUrl, err := u.getBinaryUrl(newVersion) rawUrl, err := u.getBinaryUrl(newVersion)
@ -115,7 +118,13 @@ func (u *Updater) checkForNewUpdate() (string, error) {
} }
u.Log.Info("Checking for resource at url " + rawUrl) u.Log.Info("Checking for resource at url " + rawUrl)
if !u.verifyResourceFound(rawUrl) { if !u.verifyResourceFound(rawUrl) {
return "", errors.New("Could not find any binary at " + rawUrl) errMessage := u.Tr.TemplateLocalize(
"CouldNotFindBinaryErr",
i18n.Teml{
"url": rawUrl,
},
)
return "", errors.New(errMessage)
} }
u.Log.Info("Verified resource is available, ready to update") u.Log.Info("Verified resource is available, ready to update")