1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-13 01:30:53 +02:00

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.
This commit is contained in:
Moritz Haase
2022-03-24 13:19:46 +01:00
committed by Jesse Duffield
parent 9bccc20888
commit b7079634ee
2 changed files with 33 additions and 9 deletions

View File

@ -1,16 +1,21 @@
package gui package gui
import ( import (
"fmt"
"github.com/jesseduffield/gocui" "github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
) )
func (gui *Gui) showUpdatePrompt(newVersion string) error { func (gui *Gui) showUpdatePrompt(newVersion string) error {
message := utils.ResolvePlaceholderString(
gui.Tr.UpdateAvailable, map[string]string{
"newVersion": newVersion,
},
)
return gui.c.Ask(types.AskOpts{ return gui.c.Ask(types.AskOpts{
Title: "New version available!", Title: gui.Tr.UpdateAvailableTitle,
Prompt: fmt.Sprintf("Download version %s? (enter/esc)", newVersion), Prompt: message,
HandleConfirm: func() error { HandleConfirm: func() error {
gui.startUpdating(newVersion) gui.startUpdating(newVersion)
return nil return nil
@ -23,7 +28,7 @@ func (gui *Gui) onUserUpdateCheckFinish(newVersion string, err error) error {
return gui.c.Error(err) return gui.c.Error(err)
} }
if newVersion == "" { if newVersion == "" {
return gui.c.ErrorMsg("New version not found") return gui.c.ErrorMsg(gui.Tr.FailedToRetrieveLatestVersionErr)
} }
return gui.showUpdatePrompt(newVersion) return gui.showUpdatePrompt(newVersion)
} }
@ -46,7 +51,7 @@ func (gui *Gui) onBackgroundUpdateCheckFinish(newVersion string, err error) erro
func (gui *Gui) startUpdating(newVersion string) { func (gui *Gui) startUpdating(newVersion string) {
gui.State.Updating = true 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) }) 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.OnUIThread(func() error {
_ = gui.renderString(gui.Views.AppStatus, "") _ = gui.renderString(gui.Views.AppStatus, "")
if err != nil { 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 return nil
}) })
@ -66,8 +76,8 @@ func (gui *Gui) onUpdateFinish(statusId int, err error) error {
func (gui *Gui) createUpdateQuitConfirmation() error { func (gui *Gui) createUpdateQuitConfirmation() error {
return gui.c.Ask(types.AskOpts{ return gui.c.Ask(types.AskOpts{
Title: "Currently Updating", Title: gui.Tr.ConfirmQuitDuringUpdateTitle,
Prompt: "An update is in progress. Are you sure you want to quit?", Prompt: gui.Tr.ConfirmQuitDuringUpdate,
HandleConfirm: func() error { HandleConfirm: func() error {
return gocui.ErrQuit return gocui.ErrQuit
}, },

View File

@ -129,9 +129,16 @@ type TranslationSet struct {
UpdatesRejectedAndForcePushDisabled string UpdatesRejectedAndForcePushDisabled string
LcCheckForUpdate string LcCheckForUpdate string
CheckingForUpdates string CheckingForUpdates string
UpdateAvailableTitle string
UpdateAvailable string
UpdateInProgressWaitingStatus string
FailedToRetrieveLatestVersionErr string
OnLatestVersionErr string OnLatestVersionErr string
MajorVersionErr string MajorVersionErr string
CouldNotFindBinaryErr string CouldNotFindBinaryErr string
UpdateFailedErr string
ConfirmQuitDuringUpdateTitle string
ConfirmQuitDuringUpdate string
MergeToolTitle string MergeToolTitle string
MergeToolPrompt string MergeToolPrompt string
IntroPopupMessage string IntroPopupMessage string
@ -719,9 +726,16 @@ func EnglishTranslationSet() TranslationSet {
UpdatesRejectedAndForcePushDisabled: "Updates were rejected and you have disabled force pushing", UpdatesRejectedAndForcePushDisabled: "Updates were rejected and you have disabled force pushing",
LcCheckForUpdate: "check for update", LcCheckForUpdate: "check for update",
CheckingForUpdates: "Checking for updates...", 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", OnLatestVersionErr: "You already have the latest version",
MajorVersionErr: "New version ({{.newVersion}}) has non-backwards compatible changes compared to the current version ({{.currentVersion}})", MajorVersionErr: "New version ({{.newVersion}}) has non-backwards compatible changes compared to the current version ({{.currentVersion}})",
CouldNotFindBinaryErr: "Could not find any binary at {{.url}}", 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", MergeToolTitle: "Merge tool",
MergeToolPrompt: "Are you sure you want to open `git mergetool`?", MergeToolPrompt: "Are you sure you want to open `git mergetool`?",
IntroPopupMessage: englishIntroPopupMessage, IntroPopupMessage: englishIntroPopupMessage,