1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-04 10:34:55 +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
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
},

View File

@ -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,