diff options
50 files changed, 12905 insertions, 141 deletions
diff --git a/Gopkg.lock b/Gopkg.lock index 288f8ba4d..eef8e12ac 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -8,6 +8,15 @@ version = "v1.0.6" [[projects]] + branch = "master" + digest = "1:cd7ba2b29e93e2a8384e813dfc80ebb0f85d9214762e6ca89bb55a58092eab87" + name = "github.com/cloudfoundry/jibber_jabber" + packages = ["."] + pruneopts = "NUT" + revision = "bcc4c8345a21301bf47c032ff42dd1aae2fe3027" + +[[projects]] + digest = "1:a2c1d0e43bd3baaa071d1b9ed72c27d78169b2b269f71c105ac4ba34b1be4a39" name = "github.com/davecgh/go-spew" packages = ["spew"] revision = "346938d642f2ec3594ed81d874461961cd0faa76" @@ -100,6 +109,18 @@ revision = "58046073cbffe2f25d425fe1331102f55cf719de" [[projects]] + digest = "1:2c34c77bf3ec848da26e48af58fc511ed52750961fa848399d122882b8890928" + name = "github.com/nicksnyder/go-i18n" + packages = [ + "v2/i18n", + "v2/internal", + "v2/internal/plural", + ] + pruneopts = "NUT" + revision = "a16b91a3ba80db3a2301c70d1d302d42251c9079" + version = "v2.0.0-beta.5" + +[[projects]] branch = "master" name = "github.com/nsf/termbox-go" packages = ["."] @@ -186,11 +207,14 @@ revision = "98c5dad5d1a0e8a73845ecc8897d0bd56586511d" [[projects]] + digest = "1:a95288ef1ef4dfad6cba7fe30843e1683f71bc28c912ca1ba3f6a539d44db739" name = "golang.org/x/text" packages = [ "internal/gen", + "internal/tag", "internal/triegen", "internal/ucd", + "language", "transform", "unicode/cldr", "unicode/norm" @@ -265,6 +289,19 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "3f40b7e57ce53b6c2b95ff995adab776197c0e110228dc1befef0d14dcefd229" + input-imports = [ + "github.com/Sirupsen/logrus", + "github.com/cloudfoundry/jibber_jabber", + "github.com/davecgh/go-spew/spew", + "github.com/fatih/color", + "github.com/golang-collections/collections/stack", + "github.com/jesseduffield/gocui", + "github.com/mgutz/str", + "github.com/nicksnyder/go-i18n/v2/i18n", + "github.com/tcnksm/go-gitconfig", + "golang.org/x/text/language", + "gopkg.in/src-d/go-git.v4", + "gopkg.in/src-d/go-git.v4/plumbing", + ] solver-name = "gps-cdcl" solver-version = 1 diff --git a/pkg/app/app.go b/pkg/app/app.go index d558ed250..3e227a395 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -9,6 +9,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/gui" + "github.com/jesseduffield/lazygit/pkg/i18n" ) // App struct @@ -20,6 +21,7 @@ type App struct { OSCommand *commands.OSCommand GitCommand *commands.GitCommand Gui *gui.Gui + Tr *i18n.Localizer } func newLogger(config config.AppConfigurer) *logrus.Logger { @@ -48,11 +50,17 @@ func NewApp(config config.AppConfigurer) (*App, error) { if err != nil { return nil, err } + + app.Tr, err = i18n.NewLocalizer(app.Log) + if err != nil { + return nil, err + } + app.GitCommand, err = commands.NewGitCommand(app.Log, app.OSCommand) if err != nil { return nil, err } - app.Gui, err = gui.NewGui(app.Log, app.GitCommand, app.OSCommand, config.GetVersion()) + app.Gui, err = gui.NewGui(app.Log, app.GitCommand, app.OSCommand, app.Tr, config.GetVersion()) if err != nil { return nil, err } diff --git a/pkg/commands/os.go b/pkg/commands/os.go index 9f9819a5a..d4ea75e74 100644 --- a/pkg/commands/os.go +++ b/pkg/commands/os.go @@ -14,13 +14,6 @@ import ( gitconfig "github.com/tcnksm/go-gitconfig" ) -var ( - // ErrNoOpenCommand : When we don't know which command to use to open a file - ErrNoOpenCommand = errors.New("Unsure what command to use to open this file") - // ErrNoEditorDefined : When we can't find an editor to edit a file - ErrNoEditorDefined = errors.New("No editor defined in $VISUAL, $EDITOR, or git config") -) - // Platform stores the os state type Platform struct { os string @@ -113,7 +106,7 @@ func (c *OSCommand) GetOpenCommand() (string, string, error) { return name, trail, nil } } - return "", "", ErrNoOpenCommand + return "", "", errors.New("Unsure what command to use to open this file") } // VsCodeOpenFile opens the file in code, with the -r flag to open in the @@ -157,7 +150,7 @@ func (c *OSCommand) EditFile(filename string) (*exec.Cmd, error) { } } if editor == "" { - return nil, ErrNoEditorDefined + return nil, errors.New("No editor defined in $VISUAL, $EDITOR, or git config") } return c.PrepareSubProcess(editor, filename) } diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index c4786d39f..67e0ceb07 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -12,7 +12,7 @@ import ( func (gui *Gui) handleBranchPress(g *gocui.Gui, v *gocui.View) error { index := gui.getItemPosition(v) if index == 0 { - return gui.createErrorPanel(g, "You have already checked out this branch") + return gui.createErrorPanel(g, gui.Tr.SLocalize("AlreadyCheckedOutBranch")) } branch := gui.getSelectedBranch(v) if err := gui.GitCommand.Checkout(branch.Name, false); err != nil { @@ -23,7 +23,9 @@ func (gui *Gui) handleBranchPress(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleForceCheckout(g *gocui.Gui, v *gocui.View) error { branch := gui.getSelectedBranch(v) - return gui.createConfirmationPanel(g, v, "Force Checkout Branch", "Are you sure you want force checkout? You will lose all local changes", func(g *gocui.Gui, v *gocui.View) error { + message := gui.Tr.SLocalize("SureForceCheckout") + title := gui.Tr.SLocalize("ForceCheckoutBranch") + return gui.createConfirmationPanel(g, v, title, message, func(g *gocui.Gui, v *gocui.View) error { if err := gui.GitCommand.Checkout(branch.Name, true); err != nil { gui.createErrorPanel(g, err.Error()) } @@ -32,7 +34,7 @@ func (gui *Gui) handleForceCheckout(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) handleCheckoutByName(g *gocui.Gui, v *gocui.View) error { - gui.createPromptPanel(g, v, "Branch Name:", func(g *gocui.Gui, v *gocui.View) error { + gui.createPromptPanel(g, v, gui.Tr.SLocalize("BranchName")+":", func(g *gocui.Gui, v *gocui.View) error { if err := gui.GitCommand.Checkout(gui.trimmedContent(v), false); err != nil { return gui.createErrorPanel(g, err.Error()) } @@ -43,7 +45,13 @@ func (gui *Gui) handleCheckoutByName(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleNewBranch(g *gocui.Gui, v *gocui.View) error { branch := gui.State.Branches[0] - gui.createPromptPanel(g, v, "New Branch Name (Branch is off of "+branch.Name+")", func(g *gocui.Gui, v *gocui.View) error { + message := gui.Tr.TemplateLocalize( + "NewBranchNameBranchOff", + Teml{ + "branchName": branch.Name, + }, + ) + gui.createPromptPanel(g, v, message, func(g *gocui.Gui, v *gocui.View) error { if err := gui.GitCommand.NewBranch(gui.trimmedContent(v)); err != nil { return gui.createErrorPanel(g, err.Error()) } @@ -57,9 +65,16 @@ func (gui *Gui) handleDeleteBranch(g *gocui.Gui, v *gocui.View) error { checkedOutBranch := gui.State.Branches[0] selectedBranch := gui.getSelectedBranch(v) if checkedOutBranch.Name == selectedBranch.Name { - return gui.createErrorPanel(g, "You cannot delete the checked out branch!") + return gui.createErrorPanel(g, gui.Tr.SLocalize("CantDeleteCheckOutBranch")) } - return gui.createConfirmationPanel(g, v, "Delete Branch", "Are you sure you want delete the branch "+selectedBranch.Name+" ?", func(g *gocui.Gui, v *gocui.View) error { + message := gui.Tr.TemplateLocalize( + "DeleteBranchMessage", + Teml{ + "selectedBranchName": selectedBranch.Name, + }, + ) + title := gui.Tr.SLocalize("DeleteBranch") + return gui.createConfirmationPanel(g, v, title, message, func(g *gocui.Gui, v *gocui.View) error { if err := gui.GitCommand.DeleteBranch(selectedBranch.Name); err != nil { return gui.createErrorPanel(g, err.Error()) } @@ -72,7 +87,7 @@ func (gui *Gui) handleMerge(g *gocui.Gui, v *gocui.View) error { selectedBranch := gui.getSelectedBranch(v) defer gui.refreshSidePanels(g) if checkedOutBranch.Name == selectedBranch.Name { - return gui.createErrorPanel(g, "You cannot merge a branch into itself") + return gui.createErrorPanel(g, gui.Tr.SLocalize("CantMergeBranchIntoItself")) } if err := gui.GitCommand.Merge(selectedBranch.Name); err != nil { return gui.createErrorPanel(g, err.Error()) @@ -87,13 +102,13 @@ func (gui *Gui) getSelectedBranch(v *gocui.View) commands.Branch { func (gui *Gui) renderBranchesOptions(g *gocui.Gui) error { return gui.renderOptionsMap(g, map[string]string{ - "space": "checkout", - "f": "force checkout", - "m": "merge", - "c": "checkout by name", - "n": "new branch", - "d": "delete branch", - "← → ↑ ↓": "navigate", + "space": gui.Tr.SLocalize("checkout"), + "f": gui.Tr.SLocalize("forceCheckout"), + "m": gui.Tr.SLocalize("merge"), + "c": gui.Tr.SLocalize("checkoutByName"), + "n": gui.Tr.SLocalize("newBranch"), + "d": gui.Tr.SLocalize("deleteBranch"), + "← → ↑ ↓": gui.Tr.SLocalize("navigate"), }) } @@ -104,13 +119,13 @@ func (gui *Gui) handleBranchSelect(g *gocui.Gui, v *gocui.View) error { } // This really shouldn't happen: there should always be a master branch if len(gui.State.Branches) == 0 { - return gui.renderString(g, "main", "No branches for this repo") + return gui.renderString(g, "main", gui.Tr.SLocalize("NoBranchesThisRepo")) } go func() { branch := gui.getSelectedBranch(v) diff, err := gui.GitCommand.GetBranchGraph(branch.Name) if err != nil && strings.HasPrefix(diff, "fatal: ambiguous argument") { - diff = "There is no tracking for this branch" + diff = gui.Tr.SLocalize("NoTrackingThisBranch") } gui.renderString(g, "main", diff) }() diff --git a/pkg/gui/commit_message_panel.go b/pkg/gui/commit_message_panel.go index f765ab308..26db703f0 100644 --- a/pkg/gui/commit_message_panel.go +++ b/pkg/gui/commit_message_panel.go @@ -1,22 +1,24 @@ package gui -import "github.com/jesseduffield/gocui" +import ( + "github.com/jesseduffield/gocui" +) func (gui *Gui) handleCommitConfirm(g *gocui.Gui, v *gocui.View) error { message := gui.trimmedContent(v) if message == "" { - return gui.createErrorPanel(g, "You cannot commit without a commit message") + return gui.createErrorPanel(g, gui.Tr.SLocalize("CommitWithoutMessageErr")) } sub, err := gui.GitCommand.Commit(g, message) if err != nil { // TODO need to find a way to send through this error - if err != ErrSubProcess { + if err != gui.Errors.ErrSubProcess { return gui.createErrorPanel(g, err.Error()) } } if sub != nil { gui.SubProcess = sub - return ErrSubProcess + return gui.Errors.ErrSubProcess } gui.refreshFiles(g) v.Clear() @@ -46,5 +48,12 @@ func (gui *Gui) handleNewlineCommitMessage(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) handleCommitFocused(g *gocui.Gui, v *gocui.View) error { - return gui.renderString(g, "options", "esc: close, enter: confirm") + message := gui.Tr.TemplateLocalize( + "CloseConfirm", + Teml{ + "keyBindClose": "esc", + "keyBindConfirm": "enter", + }, + ) + return gui.renderString(g, "options", message) } diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go index 60ae1c315..417b947a2 100644 --- a/pkg/gui/commits_panel.go +++ b/pkg/gui/commits_panel.go @@ -8,11 +8,6 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands" ) -var ( - // ErrNoCommits : When no commits are found for the branch - ErrNoCommits = errors.New("No commits for this branch") -) - func (gui *Gui) refreshCommits(g *gocui.Gui) error { g.Update(func(*gocui.Gui) error { gui.State.Commits = gui.GitCommand.GetCommits() @@ -44,7 +39,7 @@ func (gui *Gui) refreshCommits(g *gocui.Gui) error { } func (gui *Gui) handleResetToCommit(g *gocui.Gui, commitView *gocui.View) error { - return gui.createConfirmationPanel(g, commitView, "Reset To Commit", "Are you sure you want to reset to this commit?", func(g *gocui.Gui, v *gocui.View) error { + return gui.createConfirmationPanel(g, commitView, gui.Tr.SLocalize("ResetToCommit"), gui.Tr.SLocalize("SureResetThisCommit"), func(g *gocui.Gui, v *gocui.View) error { commit, err := gui.getSelectedCommit(g) if err != nil { panic(err) @@ -65,11 +60,11 @@ func (gui *Gui) handleResetToCommit(g *gocui.Gui, commitView *gocui.View) error func (gui *Gui) renderCommitsOptions(g *gocui.Gui) error { return gui.renderOptionsMap(g, map[string]string{ - "s": "squash down", - "r": "rename", - "g": "reset to this commit", - "f": "fixup commit", - "← → ↑ ↓": "navigate", + "s": gui.Tr.SLocalize("squashDown"), + "r": gui.Tr.SLocalize("rename"), + "g": gui.Tr.SLocalize("resetToThisCommit"), + "f": gui.Tr.SLocalize("fixupCommit"), + "← → ↑ ↓": gui.Tr.SLocalize("navigate"), }) } @@ -79,10 +74,10 @@ func (gui *Gui) handleCommitSelect(g *gocui.Gui, v *gocui.View) error { } commit, err := gui.getSelectedCommit(g) if err != nil { - if err != ErrNoCommits { + if err != errors.New(gui.Tr.SLocalize("NoCommitsThisBranch")) { return err } - return gui.renderString(g, "main", "No commits for this branch") + return gui.renderString(g, "main", gui.Tr.SLocalize("NoCommitsThisBranch")) } commitText := gui.GitCommand.Show(commit.Sha) return gui.renderString(g, "main", commitText) @@ -90,10 +85,10 @@ func (gui *Gui) handleCommitSelect(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCommitSquashDown(g *gocui.Gui, v *gocui.View) error { if gui.getItemPosition(v) != 0 { - return gui.createErrorPanel(g, "Can only squash topmost commit") + return gui.createErrorPanel(g, gui.Tr.SLocalize("OnlySquashTopmostCommit")) } if len(gui.State.Commits) == 1 { - return gui.createErrorPanel(g, "You have no commits to squash with") + return gui.createErrorPanel(g, gui.Tr.SLocalize("YouNoCommitsToSquash")) } commit, err := gui.getSelectedCommit(g) if err != nil { @@ -121,17 +116,18 @@ func (gui *Gui) anyUnStagedChanges(files []commands.File) bool { func (gui *Gui) handleCommitFixup(g *gocui.Gui, v *gocui.View) error { if len(gui.State.Commits) == 1 { - return gui.createErrorPanel(g, "You have no commits to squash with") + return gui.createErrorPanel(g, gui.Tr.SLocalize("YouNoCommitsToSquash")) } if gui.anyUnStagedChanges(gui.State.Files) { - return gui.createErrorPanel(g, "Can't fixup while there are unstaged changes") + return gui.createErrorPanel(g, gui.Tr.SLocalize("CantFixupWhileUnstagedChanges")) } branch := gui.State.Branches[0] commit, err := gui.getSelectedCommit(g) if err != nil { return err } - gui.createConfirmationPanel(g, v, "Fixup", "Are you sure you want to fixup this commit? The commit beneath will be squashed up into this one", func(g *gocui.Gui, v *gocui.View) error { + message := gui.Tr.SLocalize("SureFixupThisCommit") + gui.createConfirmationPanel(g, v, gui.Tr.SLocalize("Fixup"), message, func(g *gocui.Gui, v *gocui.View) error { if err := gui.GitCommand.SquashFixupCommit(branch.Name, commit.Sha); err != nil { return gui.createErrorPanel(g, err.Error()) } @@ -145,9 +141,9 @@ func (gui *Gui) handleCommitFixup(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleRenameCommit(g *gocui.Gui, v *gocui.View) error { if gui.getItemPosition(v) != 0 { - return gui.createErrorPanel(g, "Can only rename topmost commit") + return gui.createErrorPanel(g, gui.Tr.SLocalize("OnlyRenameTopCommit")) } - gui.createPromptPanel(g, v, "Rename Commit", func(g *gocui.Gui, v *gocui.View) error { + gui.createPromptPanel(g, v, gui.Tr.SLocalize("RenameCommit"), func(g *gocui.Gui, v *gocui.View) error { if err := gui.GitCommand.RenameCommit(v.Buffer()); err != nil { return gui.createErrorPanel(g, err.Error()) } @@ -165,11 +161,11 @@ func (gui *Gui) getSelectedCommit(g *gocui.Gui) (commands.Commit, error) { panic(err) } if len(gui.State.Commits) == 0 { - return commands.Commit{}, ErrNoCommits + return commands.Commit{}, errors.New(gui.Tr.SLocalize("NoCommitsThisBranch")) } lineNumber := gui.getItemPosition(v) if lineNumber > len(gui.State.Commits)-1 { - gui.Log.Info("potential error in getSelected Commit (mismatched ui and state)", gui.State.Commits, lineNumber) + gui.Log.Info(gui.Tr.SLocalize("PotentialErrInGetselectedCommit"), gui.State.Commits, lineNumber) return gui.State.Commits[len(gui.State.Commits)-1], nil } return gui.State.Commits[lineNumber], nil diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go index 5018d0a9f..9c3d2b263 100644 --- a/pkg/gui/confirmation_panel.go +++ b/pkg/gui/confirmation_panel.go @@ -83,7 +83,13 @@ func (gui *Gui) createConfirmationPanel(g *gocui.Gui, currentView *gocui.View, t // delete the existing confirmation panel if it exists if view, _ := g.View("confirmation"); view != nil { if err := gui.closeConfirmationPrompt(g); err != nil { - gui.Log.Error("Could not close confirmation prompt: ", err.Error()) + errMessage := gui.Tr.TemplateLocalize( + "CantCloseConfirmationPrompt", + Teml{ + "error": err.Error(), + }, + ) + gui.Log.Error(errMessage) } } x0, y0, x1, y1 := gui.getConfirmationPanelDimensions(g, prompt) @@ -117,7 +123,14 @@ func (gui *Gui) handleNewline(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) setKeyBindings(g *gocui.Gui, handleConfirm, handleClose func(*gocui.Gui, *gocui.View) error) error { - gui.renderString(g, "options", "esc: close, enter: confirm") + actions := gui.Tr.TemplateLocalize( + "CloseConfirm", + Teml{ + "keyBindClose": "esc", + "keyBindConfirm": "enter", + }, + ) + gui.renderString(g, "options", actions) if err := g.SetKeybinding("confirmation", gocui.KeyEnter, gocui.ModNone, gui.wrappedConfirmationFunction(handleConfirm)); err != nil { return err } @@ -135,7 +148,7 @@ func (gui *Gui) createErrorPanel(g *gocui.Gui, message string) error { currentView := g.CurrentView() colorFunction := color.New(color.FgRed).SprintFunc() coloredMessage := colorFunction(strings.TrimSpace(message)) - return gui.createConfirmationPanel(g, currentView, "Error", coloredMessage, nil, nil) + return gui.createConfirmationPanel(g, currentView, gui.Tr.SLocalize("Error"), coloredMessage, nil, nil) } func (gui *Gui) resizePopupPanel(g *gocui.Gui, v *gocui.View) error { @@ -147,7 +160,7 @@ func (gui *Gui) resizePopupPanel(g *gocui.Gui, v *gocui.View) error { if vx0 == x0 && vy0 == y0 && vx1 == x1 && vy1 == y1 { return nil } - gui.Log.Info("resizing popup panel") + gui.Log.Info(gui.Tr.SLocalize("resizingPopupPanel")) _, err := g.SetView(v.Name(), x0, y0, x1, y1, 0) return err } diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index a7e9683d2..27589bc19 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -7,7 +7,6 @@ import ( // "strings" - "errors" "os/exec" "strings" @@ -16,11 +15,6 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands" ) -var ( - errNoFiles = errors.New("No changed files") - errNoUsername = errors.New(`No username set. Please do: git config --global user.name "Your Name"`) -) - func (gui *Gui) stagedFiles() []commands.File { files := gui.State.Files result := make([]commands.File, 0) @@ -54,7 +48,7 @@ func (gui *Gui) stageSelectedFile(g *gocui.Gui) error { func (gui *Gui) handleFilePress(g *gocui.Gui, v *gocui.View) error { file, err := gui.getSelectedFile(g) if err != nil { - if err == errNoFiles { + if err == gui.Errors.ErrNoFiles { return nil } return err @@ -80,28 +74,28 @@ func (gui *Gui) handleFilePress(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleAddPatch(g *gocui.Gui, v *gocui.View) error { file, err := gui.getSelectedFile(g) if err != nil { - if err == errNoFiles { + if err == gui.Errors.ErrNoFiles { < |