From b7079634ee6b597ab5f8082e2deda2b52d9cc648 Mon Sep 17 00:00:00 2001 From: Moritz Haase Date: Thu, 24 Mar 2022 13:19:46 +0100 Subject: [PATCH] i18n: Make user-facing strings in the updater translatable Convert a number of static (english) user-facing string in the updater code to translatable ones. --- pkg/gui/updates.go | 28 +++++++++++++++++++--------- pkg/i18n/english.go | 14 ++++++++++++++ 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/pkg/gui/updates.go b/pkg/gui/updates.go index 83642a81a..edc208625 100644 --- a/pkg/gui/updates.go +++ b/pkg/gui/updates.go @@ -1,16 +1,21 @@ package gui import ( - "fmt" - "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/gui/types" + "github.com/jesseduffield/lazygit/pkg/utils" ) func (gui *Gui) showUpdatePrompt(newVersion string) error { + message := utils.ResolvePlaceholderString( + gui.Tr.UpdateAvailable, map[string]string{ + "newVersion": newVersion, + }, + ) + return gui.c.Ask(types.AskOpts{ - Title: "New version available!", - Prompt: fmt.Sprintf("Download version %s? (enter/esc)", newVersion), + Title: gui.Tr.UpdateAvailableTitle, + Prompt: message, HandleConfirm: func() error { gui.startUpdating(newVersion) return nil @@ -23,7 +28,7 @@ func (gui *Gui) onUserUpdateCheckFinish(newVersion string, err error) error { return gui.c.Error(err) } if newVersion == "" { - return gui.c.ErrorMsg("New version not found") + return gui.c.ErrorMsg(gui.Tr.FailedToRetrieveLatestVersionErr) } return gui.showUpdatePrompt(newVersion) } @@ -46,7 +51,7 @@ func (gui *Gui) onBackgroundUpdateCheckFinish(newVersion string, err error) erro func (gui *Gui) startUpdating(newVersion string) { gui.State.Updating = true - statusId := gui.statusManager.addWaitingStatus("updating") + statusId := gui.statusManager.addWaitingStatus(gui.Tr.UpdateInProgressWaitingStatus) gui.Updater.Update(newVersion, func(err error) error { return gui.onUpdateFinish(statusId, err) }) } @@ -56,7 +61,12 @@ func (gui *Gui) onUpdateFinish(statusId int, err error) error { gui.OnUIThread(func() error { _ = gui.renderString(gui.Views.AppStatus, "") if err != nil { - return gui.c.ErrorMsg("Update failed: " + err.Error()) + errMessage := utils.ResolvePlaceholderString( + gui.Tr.UpdateFailedErr, map[string]string{ + "errMessage": err.Error(), + }, + ) + return gui.c.ErrorMsg(errMessage) } return nil }) @@ -66,8 +76,8 @@ func (gui *Gui) onUpdateFinish(statusId int, err error) error { func (gui *Gui) createUpdateQuitConfirmation() error { return gui.c.Ask(types.AskOpts{ - Title: "Currently Updating", - Prompt: "An update is in progress. Are you sure you want to quit?", + Title: gui.Tr.ConfirmQuitDuringUpdateTitle, + Prompt: gui.Tr.ConfirmQuitDuringUpdate, HandleConfirm: func() error { return gocui.ErrQuit }, diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 3bef51e8b..f7f02600e 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -129,9 +129,16 @@ type TranslationSet struct { UpdatesRejectedAndForcePushDisabled string LcCheckForUpdate string CheckingForUpdates string + UpdateAvailableTitle string + UpdateAvailable string + UpdateInProgressWaitingStatus string + FailedToRetrieveLatestVersionErr string OnLatestVersionErr string MajorVersionErr string CouldNotFindBinaryErr string + UpdateFailedErr string + ConfirmQuitDuringUpdateTitle string + ConfirmQuitDuringUpdate string MergeToolTitle string MergeToolPrompt string IntroPopupMessage string @@ -719,9 +726,16 @@ func EnglishTranslationSet() TranslationSet { UpdatesRejectedAndForcePushDisabled: "Updates were rejected and you have disabled force pushing", LcCheckForUpdate: "check for update", CheckingForUpdates: "Checking for updates...", + UpdateAvailableTitle: "Update available!", + UpdateAvailable: "Download and install version {{.newVersion}}?", + UpdateInProgressWaitingStatus: "updating", + FailedToRetrieveLatestVersionErr: "Failed to retrieve version information", OnLatestVersionErr: "You already have the latest version", MajorVersionErr: "New version ({{.newVersion}}) has non-backwards compatible changes compared to the current version ({{.currentVersion}})", CouldNotFindBinaryErr: "Could not find any binary at {{.url}}", + UpdateFailedErr: "Update failed: {{.errMessage}}", + ConfirmQuitDuringUpdateTitle: "Currently Updating", + ConfirmQuitDuringUpdate: "An update is in progress. Are you sure you want to quit?", MergeToolTitle: "Merge tool", MergeToolPrompt: "Are you sure you want to open `git mergetool`?", IntroPopupMessage: englishIntroPopupMessage,