Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a view basic translation functions and translation file #137

Merged
merged 36 commits into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
62fc831
Added a view basic translation functions + tranlation file
mjarkk Aug 13, 2018
d9959eb
fixed @jesseduffield comment #137
mjarkk Aug 13, 2018
65eb378
fixed typo
mjarkk Aug 13, 2018
f2dfcb6
Added more messages and text issue: #137
mjarkk Aug 13, 2018
dfafb98
tried to update to latest master
mjarkk Aug 14, 2018
17dcfbc
Merge pull request #1 from jesseduffield/master
mjarkk Aug 14, 2018
5ad97ad
Added the translation to some words again
mjarkk Aug 14, 2018
f792f74
Merge remote-tracking branch 'origin/master'
mjarkk Aug 14, 2018
dd7e93a
Added all the missing translations from dutch.go
mjarkk Aug 14, 2018
0c39347
Added auto detection for the system language
mjarkk Aug 14, 2018
6e51814
added some commands
mjarkk Aug 14, 2018
0568b32
Added more translations
mjarkk Aug 14, 2018
5cbacb0
make local i18n package confirm to project structure
jesseduffield Aug 14, 2018
4d0702f
Merge branch 'master' of https://github.com/mjarkk/lazygit
jesseduffield Aug 14, 2018
8e22d56
Merge pull request #2 from jesseduffield/master
mjarkk Aug 14, 2018
73a1682
fixed package naming and added tr object to file_panel.go
mjarkk Aug 14, 2018
ba2b6fb
pull errors out of package scope and store sentinel errors on the gui…
jesseduffield Aug 14, 2018
d923796
Merge branch 'master' of https://github.com/mjarkk/lazygit
jesseduffield Aug 14, 2018
883f436
can't go any further because of an error
mjarkk Aug 14, 2018
9c97b75
Merge remote-tracking branch 'origin/master'
mjarkk Aug 14, 2018
38a1a00
Fixed comment from myself on issue: 137
mjarkk Aug 14, 2018
be3f584
Added more translations
mjarkk Aug 14, 2018
3dba246
Added translations for files_panel.go and fixed some typos
mjarkk Aug 14, 2018
8418fa1
Fully translated pkg/gui/commit_message_panel.go
mjarkk Aug 15, 2018
d12cc5a
Fully translated pkg/gui/commits_panel.go
mjarkk Aug 15, 2018
7e926cf
Added translation for pkg/gui/ confirmation_panel.go gui.go merge_pan…
mjarkk Aug 15, 2018
10c5316
Merge pull request #3 from jesseduffield/master
mjarkk Aug 15, 2018
295093a
Translated pkg/gui/stash_panel.go
mjarkk Aug 15, 2018
50b41bf
Translated pkg/gui/view_helpers.go
mjarkk Aug 15, 2018
d00c46a
Added all english translations to a file and fixed some typos
mjarkk Aug 15, 2018
9112278
Merge pull request #4 from jesseduffield/master
mjarkk Aug 15, 2018
9abbfe5
Fully translated pkg/gui/confirmation_panel.go
mjarkk Aug 15, 2018
88e1a81
Fixed comment on issue #137 from @jesseduffield
mjarkk Aug 16, 2018
9074650
Fixed comments from jesseduffield on issue #137
mjarkk Aug 16, 2018
faf218f
Fixed comments from jesseduffield on issue #137
mjarkk Aug 16, 2018
fcf616b
Fixed it
mjarkk Aug 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 2 additions & 9 deletions pkg/commands/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
47 changes: 31 additions & 16 deletions pkg/gui/branches_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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())
}
Expand All @@ -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())
}
Expand All @@ -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())
}
Expand All @@ -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())
}
Expand All @@ -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())
Expand All @@ -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"),
})
}

Expand All @@ -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)
}()
Expand Down
19 changes: 14 additions & 5 deletions pkg/gui/commit_message_panel.go
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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)
}
40 changes: 18 additions & 22 deletions pkg/gui/commits_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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"),
})
}

Expand All @@ -79,21 +74,21 @@ 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)
}

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 {
Expand Down Expand Up @@ -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())
}
Expand All @@ -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())
}
Expand All @@ -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
Expand Down
21 changes: 17 additions & 4 deletions pkg/gui/confirmation_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand All @@ -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
}
Loading