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

Code before:
			},
			OnPress: func() error {
				self.c.LogAction("Reset")
				return self.ResetToRef(ref, row.strength, []string{})
			},
			Key:     row.key,
			Tooltip: row.tooltip,
		}
	})

	return self.c.Menu(types.CreateMenuOptions{
		Title: fmt.Sprintf("%s %s", self.c.Tr.ResetTo, ref),
		Items: menuItems,
	})
}

func (self *RefsHelper) CreateCheckoutMenu(commit *models.Commit) error {
	branches := lo.Filter(self.c.Model().Branches, func(branch *models.Branch, _ int) bool {
		return commit.Hash == branch.CommitHash && branch.Name != self.c.Model().CheckedOutBranch
	})

	ref := commit.Hash
	var menuItems []*types.MenuItem

	menuItems = append(menuItems, &types.MenuItem{
		LabelColumns: []string{fmt.Sprintf("%s %s", self.c.Tr.CheckoutCommit, self.c.Tr.AsDetachedHead), style.FgRed.Sprint(ref[:8])},
		OnPress: func() error {
			self.c.Confirm(types.ConfirmOpts{
				Title:  self.c.Tr.CheckoutCommit,
				Prompt: self.c.Tr.SureCheckoutThisCommit,
				HandleConfirm: func() error {
					self.c.LogAction(self.c.Tr.Actions.CheckoutCommit)
					return self.CheckoutRef(ref, types.CheckoutRefOptions{})
				},
			})
			return nil
		},
		Tooltip: self.c.Tr.CheckoutCommitTooltip,
		Key:     'd',
	})

	if len(branches) > 0 {
		menuItems = append(menuItems, lo.Map(branches, func(branch *models.Branch, index int) *types.MenuItem {
			return &types.MenuItem{
				LabelColumns: []string{self.c.Tr.Actions.CheckoutBranch, style.FgBlue.Sprint(branch.Name)},
				OnPress: func() error {
					self.c.LogAction(self.c.Tr.Actions.CheckoutBranch)
					return self.CheckoutRef(branch.RefName(), types.CheckoutRefOptions{})
				},
				Tooltip: self.c.Tr.CheckoutBranchTooltip,
				Key:     rune(index + 1 + '0'), // Convert 1-based index to key

Review comment (suggestion):
As a general rule of thumb, you should never concatenate or otherwise assemble several translated strings. You never know, it might not work well in other languages (order might have to be different). It is better to introduce a new text that is the assembled sentence you need (`CheckoutAsDetachedHead` in this case, with the text "Checkout commit as detached head").

Code after:
			},
			OnPress: func() error {
				self.c.LogAction("Reset")
				return self.ResetToRef(ref, row.strength, []string{})
			},
			Key:     row.key,
			Tooltip: row.tooltip,
		}
	})

	return self.c.Menu(types.CreateMenuOptions{
		Title: fmt.Sprintf("%s %s", self.c.Tr.ResetTo, ref),
		Items: menuItems,
	})
}

func (self *RefsHelper) CreateCheckoutMenu(commit *models.Commit) error {
	branches := lo.Filter(self.c.Model().Branches, func(branch *models.Branch, _ int) bool {
		return commit.Hash == branch.CommitHash && branch.Name != self.c.Model().CheckedOutBranch
	})

	hash := commit.Hash
	var menuItems []*types.MenuItem

	if len(branches) > 0 {
		menuItems = append(menuItems, lo.Map(branches, func(branch *models.Branch, index int) *types.MenuItem {
			var key types.Key
			if index < 9 {
				key = rune(index + 1 + '0') // Convert 1-based index to key
			}
			return &types.MenuItem{
				LabelColumns: []string{fmt.Sprintf(self.c.Tr.Actions.CheckoutBranchAtCommit, branch.Name)},
				OnPress: func() error {
					self.c.LogAction(self.c.Tr.Actions.CheckoutBranch)
					return self.CheckoutRef(branch.RefName(), types.CheckoutRefOptions{})
				},
				Key: key,
			}
		})...)
	} else {
		menuItems = append(menuItems, &types.MenuItem{
			LabelColumns:   []string{self.c.Tr.Actions.CheckoutBranch},
			OnPress:        func() error { return nil },
			DisabledReason: &types.DisabledReason{Text: self.c.Tr.NoBranchesFoundAtCommitTooltip},
			Key:            '1',
		})
	}

	menuItems = append(menuItems, &types.MenuItem{
		LabelColumns: []string{fmt.Sprintf(self.c.Tr.Actions.CheckoutCommitAsDetachedHead, utils.ShortHash(hash))},
		OnPress: func() error {