Repository: jesseduffield/lazygit
File: pkg/gui/controllers/files_controller.go (Go)

Code before:
				},
				Key: 's',
			},
			{
				Label: self.c.Tr.StashUnstagedChanges,
				OnPress: func() error {
					if !self.c.Helpers().WorkingTree.IsWorkingTreeDirty() {
						return self.c.ErrorMsg(self.c.Tr.NoFilesToStash)
					}
					if self.c.Helpers().WorkingTree.AnyStagedFiles() {
						return self.handleStashSave(self.c.Git().Stash.StashUnstagedChanges, self.c.Tr.Actions.StashUnstagedChanges)
					}
					// ordinary stash
					return self.handleStashSave(self.c.Git().Stash.Push, self.c.Tr.Actions.StashUnstagedChanges)
				},
				Key: 'u',
			},
		},
	})
}

func (self *FilesController) openCopyMenu() error {
	copyNameNoItemSelectionErr := utils.ResolvePlaceholderString(
		self.c.Tr.FileCopyNoItemSelectedError,
		map[string]string{"target": "name"},
	)
	copyNameItem := &types.MenuItem{
		Label: self.c.Tr.CopyFileName,
		OnPress: func() error {
			name := self.context().GetSelectedItemId()
			if name == "" {
				return self.c.ErrorMsg(copyNameNoItemSelectionErr)
			}

			return self.copyToClipboard(name)
		},
		Key: 'n',
	}

	copyDiffNoItemSelectionErr := utils.ResolvePlaceholderString(
		self.c.Tr.FileCopyNoItemSelectedError,
		map[string]string{"target": "diff"},
	)
	copyFileDiffItem := &types.MenuItem{
		Label:   self.c.Tr.CopySelectedDiff,
		Tooltip: self.c.Tr.CopyFileDiffTooltip,
		OnPress: func() error {
			path := self.context().GetSelectedPath()
			if path == "" {
				return self.c.ErrorMsg(copyDiffNoItemSelectionErr)
			}

Review comment (refactor):
This doesn't work; you are putting a non-translated string into a placeholder of a translated string.

If you are thinking about solving this by making "name" a translated string too, please don't. Stitching together translated strings like this is not good practice; in other languages the grammar might be sufficiently different to make this hard to translate. Also, it's not obvious to translators how the strings are used. If you must have different texts for the different cases, you should duplicate the whole strings. However, in this case I don't think it's worth it, I'd just try to come up with a generic wording that works for all cases.

Code after:
				Key: 's',
			},
			{
				Label: self.c.Tr.StashUnstagedChanges,
				OnPress: func() error {
					if !self.c.Helpers().WorkingTree.IsWorkingTreeDirty() {
						return self.c.ErrorMsg(self.c.Tr.NoFilesToStash)
					}
					if self.c.Helpers().WorkingTree.AnyStagedFiles() {
						return self.handleStashSave(self.c.Git().Stash.StashUnstagedChanges, self.c.Tr.Actions.StashUnstagedChanges)
					}
					// ordinary stash
					return self.handleStashSave(self.c.Git().Stash.Push, self.c.Tr.Actions.StashUnstagedChanges)
				},
				Key: 'u',
			},
		},
	})
}

func (self *FilesController) openCopyMenu() error {
	node := self.context().GetSelected()

	copyNameItem := &types.MenuItem{
		Label: self.c.Tr.CopyFileName,
		OnPress: func() error {
			if err := self.c.OS().CopyToClipboard(node.Name()); err != nil {
				return self.c.Error(err)
			}
			self.c.Toast(self.c.Tr.FileNameCopiedToast)
			return nil
		},
		Key: 'n',
	}
	copyPathItem := &types.MenuItem{
		Label: self.c.Tr.CopyFilePath,
		OnPress: func() error {
			if err := self.c.OS().CopyToClipboard(node.Path); err != nil {
				return self.c.Error(err)
			}
			self.c.Toast(self.c.Tr.FilePathCopiedToast)
			return nil
		},
		Key: 'p',
	}
	copyFileDiffItem := &types.MenuItem{
		Label:   self.c.Tr.CopySelectedDiff,
		Tooltip: self.c.Tr.CopyFileDiffTooltip,
		OnPress: func() error {
			path := self.context().GetSelectedPath()
			hasStaged := self.hasPathStagedChanges(node)