diff options
author | Karl Heitmann <khf1988@gmail.com> | 2023-07-30 21:33:47 -0400 |
---|---|---|
committer | Karl Heitmann <khf1988@gmail.com> | 2023-07-31 19:35:55 -0400 |
commit | 51e205ce11d9c7301f4c78d1fc7f69d6bd313447 (patch) | |
tree | 6d5dbe47e9ba9c856fe6092ecefcd40d71866b02 /pkg/commands | |
parent | 6984a4f4d41d003a3443abe357d75caf2af6b34c (diff) |
Moves hard coded strings for LogCommand to i18n.
Diffstat (limited to 'pkg/commands')
-rw-r--r-- | pkg/commands/git_commands/rebase.go | 32 | ||||
-rw-r--r-- | pkg/commands/oscommands/os.go | 43 |
2 files changed, 66 insertions, 9 deletions
diff --git a/pkg/commands/git_commands/rebase.go b/pkg/commands/git_commands/rebase.go index d491b6f5e..c952c7fd1 100644 --- a/pkg/commands/git_commands/rebase.go +++ b/pkg/commands/git_commands/rebase.go @@ -104,7 +104,13 @@ func (self *RebaseCommands) MoveCommitDown(commits []*models.Commit, index int) sha := commits[index].Sha - self.os.LogCommand(fmt.Sprintf("Moving TODO down: %s", utils.ShortSha(sha)), false) + msg := utils.ResolvePlaceholderString( + self.Tr.Actions.LogMoveCommitDown, + map[string]string{ + "shortSha": utils.ShortSha(sha), + }, + ) + self.os.LogCommand(msg, false) return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{ baseShaOrRoot: baseShaOrRoot, @@ -118,7 +124,13 @@ func (self *RebaseCommands) MoveCommitUp(commits []*models.Commit, index int) er sha := commits[index].Sha - self.os.LogCommand(fmt.Sprintf("Moving TODO up: %s", utils.ShortSha(sha)), false) + msg := utils.ResolvePlaceholderString( + self.Tr.Actions.LogMoveCommitUp, + map[string]string{ + "shortSha": utils.ShortSha(sha), + }, + ) + self.os.LogCommand(msg, false) return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{ baseShaOrRoot: baseShaOrRoot, @@ -149,7 +161,13 @@ func (self *RebaseCommands) InteractiveRebase(commits []*models.Commit, index in } func (self *RebaseCommands) EditRebase(branchRef string) error { - self.os.LogCommand(fmt.Sprintf("Beginning interactive rebase at '%s'", branchRef), false) + msg := utils.ResolvePlaceholderString( + self.Tr.Actions.LogEditRebase, + map[string]string{ + "ref": branchRef, + }, + ) + self.os.LogCommand(msg, false) return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{ baseShaOrRoot: branchRef, instruction: daemon.NewInsertBreakInstruction(), @@ -412,7 +430,13 @@ func (self *RebaseCommands) CherryPickCommits(commits []*models.Commit) error { commitLines := lo.Map(commits, func(commit *models.Commit, _ int) string { 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.Actions.LogCherryPickCommits, + map[string]string{ + "commitLines": strings.Join(commitLines, "\n"), + }, + ) + self.os.LogCommand(msg, false) return self.PrepareInteractiveRebaseCommand(PrepareInteractiveRebaseCommandOpts{ baseShaOrRoot: "HEAD", diff --git a/pkg/commands/oscommands/os.go b/pkg/commands/oscommands/os.go index 4a77310b5..f260cce85 100644 --- a/pkg/commands/oscommands/os.go +++ b/pkg/commands/oscommands/os.go @@ -117,7 +117,15 @@ func (c *OSCommand) Quote(message string) string { // AppendLineToFile adds a new line in file 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.Actions.LogAppendingLineToFile, + 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) if err != nil { return utils.WrapError(err) @@ -154,7 +162,13 @@ func (c *OSCommand) AppendLineToFile(filename, line string) error { // CreateFileWithContent creates a file with the given content func (c *OSCommand) CreateFileWithContent(path string, content string) error { - c.LogCommand(fmt.Sprintf("Creating file '%s'", path), false) + msg := utils.ResolvePlaceholderString( + c.Tr.Actions.LogCreateFileWithContent, + map[string]string{ + "path": path, + }, + ) + c.LogCommand(msg, false) if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil { c.Log.Error(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 func (c *OSCommand) Remove(filename string) error { - c.LogCommand(fmt.Sprintf("Removing '%s'", filename), false) + msg := utils.ResolvePlaceholderString( + c.Tr.Actions.LogRemove, + map[string]string{ + "filename": filename, + }, + ) + c.LogCommand(msg, false) err := os.RemoveAll(filename) return utils.WrapError(err) } @@ -265,7 +285,14 @@ func PrepareForChildren(cmd *exec.Cmd) { func (c *OSCommand) CopyToClipboard(str string) error { escaped := strings.Replace(str, "\n", "\\n", -1) truncated := utils.TruncateWithEllipsis(escaped, 40) - c.LogCommand(fmt.Sprintf("Copying '%s' to clipboard", truncated), false) + + msg := utils.ResolvePlaceholderString( + c.Tr.Actions.LogCopyToClipboard, + map[string]string{ + "str": truncated, + }, + ) + c.LogCommand(msg, false) if c.UserConfig.OS.CopyToClipboardCmd != "" { cmdStr := utils.ResolvePlaceholderString(c.UserConfig.OS.CopyToClipboardCmd, map[string]string{ "text": c.Cmd.Quote(str), @@ -277,7 +304,13 @@ func (c *OSCommand) CopyToClipboard(str string) error { } func (c *OSCommand) RemoveFile(path string) error { - c.LogCommand(fmt.Sprintf("Deleting path '%s'", path), false) + msg := utils.ResolvePlaceholderString( + c.Tr.Actions.LogRemoveFile, + map[string]string{ + "path": path, + }, + ) + c.LogCommand(msg, false) return c.removeFileFn(path) } |