1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-05-21 22:43:27 +02:00

Internationalise logging of commands (#2852)

This commit is contained in:
Jesse Duffield 2023-08-01 10:06:48 +10:00 committed by GitHub
commit e932aaaeaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 131 additions and 18 deletions

View File

@ -104,7 +104,13 @@ func (self *RebaseCommands) MoveCommitDown(commits []*models.Commit, index int)
sha := commits[index].Sha sha := commits[index].Sha
self.os.LogCommand(fmt.Sprintf("Moving TODO down: %s", utils.ShortSha(sha)), false) msg := utils.ResolvePlaceholderString(
self.Tr.Log.MoveCommitDown,
map[string]string{
"shortSha": utils.ShortSha(sha),
},
)
self.os.LogCommand(msg, false)
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{ return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: baseShaOrRoot, baseShaOrRoot: baseShaOrRoot,
@ -118,7 +124,13 @@ func (self *RebaseCommands) MoveCommitUp(commits []*models.Commit, index int) er
sha := commits[index].Sha sha := commits[index].Sha
self.os.LogCommand(fmt.Sprintf("Moving TODO up: %s", utils.ShortSha(sha)), false) msg := utils.ResolvePlaceholderString(
self.Tr.Log.MoveCommitUp,
map[string]string{
"shortSha": utils.ShortSha(sha),
},
)
self.os.LogCommand(msg, false)
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{ return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: baseShaOrRoot, baseShaOrRoot: baseShaOrRoot,
@ -149,7 +161,13 @@ func (self *RebaseCommands) InteractiveRebase(commits []*models.Commit, index in
} }
func (self *RebaseCommands) EditRebase(branchRef string) error { func (self *RebaseCommands) EditRebase(branchRef string) error {
self.os.LogCommand(fmt.Sprintf("Beginning interactive rebase at '%s'", branchRef), false) msg := utils.ResolvePlaceholderString(
self.Tr.Log.EditRebase,
map[string]string{
"ref": branchRef,
},
)
self.os.LogCommand(msg, false)
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{ return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: branchRef, baseShaOrRoot: branchRef,
instruction: daemon.NewInsertBreakInstruction(), instruction: daemon.NewInsertBreakInstruction(),
@ -157,7 +175,14 @@ func (self *RebaseCommands) EditRebase(branchRef string) error {
} }
func (self *RebaseCommands) EditRebaseFromBaseCommit(targetBranchName string, baseCommit string) error { func (self *RebaseCommands) EditRebaseFromBaseCommit(targetBranchName string, baseCommit string) error {
self.os.LogCommand(fmt.Sprintf("Beginning interactive rebase from '%s' onto '%s", baseCommit, targetBranchName), false) msg := utils.ResolvePlaceholderString(
self.Tr.Log.EditRebaseFromBaseCommit,
map[string]string{
"baseCommit": baseCommit,
"targetBranchName": targetBranchName,
},
)
self.os.LogCommand(msg, false)
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{ return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: baseCommit, baseShaOrRoot: baseCommit,
onto: targetBranchName, onto: targetBranchName,
@ -412,7 +437,13 @@ func (self *RebaseCommands) CherryPickCommits(commits []*models.Commit) error {
commitLines := lo.Map(commits, func(commit *models.Commit, _ int) string { commitLines := lo.Map(commits, func(commit *models.Commit, _ int) string {
return fmt.Sprintf("%s %s", utils.ShortSha(commit.Sha), commit.Name) return fmt.Sprintf("%s %s", utils.ShortSha(commit.Sha), commit.Name)
}) })
self.os.LogCommand(fmt.Sprintf("Cherry-picking commits:\n%s", strings.Join(commitLines, "\n")), false) msg := utils.ResolvePlaceholderString(
self.Tr.Log.CherryPickCommits,
map[string]string{
"commitLines": strings.Join(commitLines, "\n"),
},
)
self.os.LogCommand(msg, false)
return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{ return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{
baseShaOrRoot: "HEAD", baseShaOrRoot: "HEAD",

View File

@ -117,7 +117,15 @@ func (c *OSCommand) Quote(message string) string {
// AppendLineToFile adds a new line in file // AppendLineToFile adds a new line in file
func (c *OSCommand) AppendLineToFile(filename, line string) error { func (c *OSCommand) AppendLineToFile(filename, line string) error {
c.LogCommand(fmt.Sprintf("Appending '%s' to file '%s'", line, filename), false) msg := utils.ResolvePlaceholderString(
c.Tr.Log.AppendingLineToFile,
map[string]string{
"line": line,
"filename": filename,
},
)
c.LogCommand(msg, false)
f, err := os.OpenFile(filename, os.O_APPEND|os.O_RDWR|os.O_CREATE, 0o600) f, err := os.OpenFile(filename, os.O_APPEND|os.O_RDWR|os.O_CREATE, 0o600)
if err != nil { if err != nil {
return utils.WrapError(err) return utils.WrapError(err)
@ -154,7 +162,13 @@ func (c *OSCommand) AppendLineToFile(filename, line string) error {
// CreateFileWithContent creates a file with the given content // CreateFileWithContent creates a file with the given content
func (c *OSCommand) CreateFileWithContent(path string, content string) error { func (c *OSCommand) CreateFileWithContent(path string, content string) error {
c.LogCommand(fmt.Sprintf("Creating file '%s'", path), false) msg := utils.ResolvePlaceholderString(
c.Tr.Log.CreateFileWithContent,
map[string]string{
"path": path,
},
)
c.LogCommand(msg, false)
if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil { if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil {
c.Log.Error(err) c.Log.Error(err)
return err return err
@ -170,7 +184,13 @@ func (c *OSCommand) CreateFileWithContent(path string, content string) error {
// Remove removes a file or directory at the specified path // Remove removes a file or directory at the specified path
func (c *OSCommand) Remove(filename string) error { func (c *OSCommand) Remove(filename string) error {
c.LogCommand(fmt.Sprintf("Removing '%s'", filename), false) msg := utils.ResolvePlaceholderString(
c.Tr.Log.Remove,
map[string]string{
"filename": filename,
},
)
c.LogCommand(msg, false)
err := os.RemoveAll(filename) err := os.RemoveAll(filename)
return utils.WrapError(err) return utils.WrapError(err)
} }
@ -265,7 +285,14 @@ func PrepareForChildren(cmd *exec.Cmd) {
func (c *OSCommand) CopyToClipboard(str string) error { func (c *OSCommand) CopyToClipboard(str string) error {
escaped := strings.Replace(str, "\n", "\\n", -1) escaped := strings.Replace(str, "\n", "\\n", -1)
truncated := utils.TruncateWithEllipsis(escaped, 40) truncated := utils.TruncateWithEllipsis(escaped, 40)
c.LogCommand(fmt.Sprintf("Copying '%s' to clipboard", truncated), false)
msg := utils.ResolvePlaceholderString(
c.Tr.Log.CopyToClipboard,
map[string]string{
"str": truncated,
},
)
c.LogCommand(msg, false)
if c.UserConfig.OS.CopyToClipboardCmd != "" { if c.UserConfig.OS.CopyToClipboardCmd != "" {
cmdStr := utils.ResolvePlaceholderString(c.UserConfig.OS.CopyToClipboardCmd, map[string]string{ cmdStr := utils.ResolvePlaceholderString(c.UserConfig.OS.CopyToClipboardCmd, map[string]string{
"text": c.Cmd.Quote(str), "text": c.Cmd.Quote(str),
@ -277,7 +304,13 @@ func (c *OSCommand) CopyToClipboard(str string) error {
} }
func (c *OSCommand) RemoveFile(path string) error { func (c *OSCommand) RemoveFile(path string) error {
c.LogCommand(fmt.Sprintf("Deleting path '%s'", path), false) msg := utils.ResolvePlaceholderString(
c.Tr.Log.RemoveFile,
map[string]string{
"path": path,
},
)
c.LogCommand(msg, false)
return c.removeFileFn(path) return c.removeFileFn(path)
} }

View File

@ -421,10 +421,15 @@ func (self *LocalCommitsController) handleMidRebaseCommand(action todo.TodoComma
} }
self.c.LogAction("Update rebase TODO") self.c.LogAction("Update rebase TODO")
self.c.LogCommand(
fmt.Sprintf("Updating rebase action of commit %s to '%s'", commit.ShortSha(), action.String()), msg := utils.ResolvePlaceholderString(
false, self.c.Tr.Log.HandleMidRebaseCommand,
map[string]string{
"shortSha": commit.ShortSha(),
"action": action.String(),
},
) )
self.c.LogCommand(msg, false)
if err := self.c.Git().Rebase.EditRebaseTodo(commit, action); err != nil { if err := self.c.Git().Rebase.EditRebaseTodo(commit, action); err != nil {
return false, self.c.Error(err) return false, self.c.Error(err)
@ -452,7 +457,14 @@ func (self *LocalCommitsController) moveDown(commit *models.Commit) error {
// logging directly here because MoveTodoDown doesn't have enough information // logging directly here because MoveTodoDown doesn't have enough information
// to provide a useful log // to provide a useful log
self.c.LogAction(self.c.Tr.Actions.MoveCommitDown) self.c.LogAction(self.c.Tr.Actions.MoveCommitDown)
self.c.LogCommand(fmt.Sprintf("Moving commit %s down", commit.ShortSha()), false)
msg := utils.ResolvePlaceholderString(
self.c.Tr.Log.MovingCommitDown,
map[string]string{
"shortSha": commit.ShortSha(),
},
)
self.c.LogCommand(msg, false)
if err := self.c.Git().Rebase.MoveTodoDown(commit); err != nil { if err := self.c.Git().Rebase.MoveTodoDown(commit); err != nil {
return self.c.Error(err) return self.c.Error(err)
@ -487,10 +499,13 @@ func (self *LocalCommitsController) moveUp(commit *models.Commit) error {
// logging directly here because MoveTodoDown doesn't have enough information // logging directly here because MoveTodoDown doesn't have enough information
// to provide a useful log // to provide a useful log
self.c.LogAction(self.c.Tr.Actions.MoveCommitUp) self.c.LogAction(self.c.Tr.Actions.MoveCommitUp)
self.c.LogCommand( msg := utils.ResolvePlaceholderString(
fmt.Sprintf("Moving commit %s up", commit.ShortSha()), self.c.Tr.Log.MovingCommitUp,
false, map[string]string{
"shortSha": commit.ShortSha(),
},
) )
self.c.LogCommand(msg, false)
if err := self.c.Git().Rebase.MoveTodoUp(self.c.Model().Commits[index]); err != nil { if err := self.c.Git().Rebase.MoveTodoUp(self.c.Model().Commits[index]); err != nil {
return self.c.Error(err) return self.c.Error(err)

View File

@ -215,7 +215,7 @@ func (self *MergeConflictsController) HandleUndo() error {
} }
self.c.LogAction("Restoring file to previous state") self.c.LogAction("Restoring file to previous state")
self.c.LogCommand("Undoing last conflict resolution", false) self.c.LogCommand(self.c.Tr.Log.HandleUndo, false)
if err := os.WriteFile(state.GetPath(), []byte(state.GetContent()), 0o644); err != nil { if err := os.WriteFile(state.GetPath(), []byte(state.GetContent()), 0o644); err != nil {
return err return err
} }

View File

@ -587,6 +587,7 @@ type TranslationSet struct {
MarkedCommitMarker string MarkedCommitMarker string
Actions Actions Actions Actions
Bisect Bisect Bisect Bisect
Log Log
} }
type Bisect struct { type Bisect struct {
@ -609,6 +610,23 @@ type Bisect struct {
Bisecting string Bisecting string
} }
type Log struct {
EditRebase string
MoveCommitUp string
MoveCommitDown string
CherryPickCommits string
HandleUndo string
HandleMidRebaseCommand string
MovingCommitUp string
MovingCommitDown string
RemoveFile string
CopyToClipboard string
Remove string
CreateFileWithContent string
AppendingLineToFile string
EditRebaseFromBaseCommit string
}
type Actions struct { type Actions struct {
CheckoutCommit string CheckoutCommit string
CheckoutTag string CheckoutTag string
@ -1456,5 +1474,21 @@ func EnglishTranslationSet() TranslationSet {
CompletePromptIndeterminate: "Bisect complete! Some commits were skipped, so any of the following commits may have introduced the change:\n\n%s\n\nDo you want to reset 'git bisect' now?", CompletePromptIndeterminate: "Bisect complete! Some commits were skipped, so any of the following commits may have introduced the change:\n\n%s\n\nDo you want to reset 'git bisect' now?",
Bisecting: "Bisecting", Bisecting: "Bisecting",
}, },
Log: Log{
EditRebase: "Beginning interactive rebase at '{{.ref}}'",
MoveCommitUp: "Moving TODO down: '{{.shortSha}}'",
MoveCommitDown: "Moving TODO down: '{{.shortSha}}'",
CherryPickCommits: "Cherry-picking commits:\n'{{.commitLines}}'",
HandleUndo: "Undoing last conflict resolution",
HandleMidRebaseCommand: "Updating rebase action of commit {{.shortSha}} to '{{.action}}'",
MovingCommitUp: "Moving commit {{.shortSha}} up",
MovingCommitDown: "Moving commit {{.shortSha}} down",
RemoveFile: "Deleting path '{{.path}}'",
CopyToClipboard: "Copying '{{.str}}' to clipboard",
Remove: "Removing '{{.filename}}'",
CreateFileWithContent: "Creating file '{{.path}}'",
AppendingLineToFile: "Appending '{{.line}}' to file '{{.filename}}'",
EditRebaseFromBaseCommit: "Beginning interactive rebase from '{{.baseCommit}}' onto '{{.targetBranchName}}",
},
} }
} }