mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-21 12:16:54 +02:00
i18n for worktrees
This commit is contained in:
parent
894485190b
commit
2082fdf84a
@ -2,7 +2,6 @@ package helpers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@ -73,7 +72,7 @@ func (self *WorktreeHelper) NewWorktree() error {
|
|||||||
|
|
||||||
f := func(detached bool) error {
|
f := func(detached bool) error {
|
||||||
return self.c.Prompt(types.PromptOpts{
|
return self.c.Prompt(types.PromptOpts{
|
||||||
Title: self.c.Tr.NewWorktreeBranch,
|
Title: self.c.Tr.NewWorktreeBase,
|
||||||
InitialContent: currentBranchName,
|
InitialContent: currentBranchName,
|
||||||
FindSuggestionsFunc: self.suggestionsHelper.GetRefsSuggestionsFunc(),
|
FindSuggestionsFunc: self.suggestionsHelper.GetRefsSuggestionsFunc(),
|
||||||
HandleConfirm: func(base string) error {
|
HandleConfirm: func(base string) error {
|
||||||
@ -83,17 +82,19 @@ func (self *WorktreeHelper) NewWorktree() error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
placeholders := map[string]string{"ref": "ref"}
|
||||||
|
|
||||||
return self.c.Menu(types.CreateMenuOptions{
|
return self.c.Menu(types.CreateMenuOptions{
|
||||||
Title: self.c.Tr.WorktreeTitle,
|
Title: self.c.Tr.WorktreeTitle,
|
||||||
Items: []*types.MenuItem{
|
Items: []*types.MenuItem{
|
||||||
{
|
{
|
||||||
LabelColumns: []string{"Create new worktree from ref"},
|
LabelColumns: []string{utils.ResolvePlaceholderString(self.c.Tr.CreateWorktreeFrom, placeholders)},
|
||||||
OnPress: func() error {
|
OnPress: func() error {
|
||||||
return f(false)
|
return f(false)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
LabelColumns: []string{"Create new worktree from ref (detached)"},
|
LabelColumns: []string{utils.ResolvePlaceholderString(self.c.Tr.CreateWorktreeFromDetached, placeholders)},
|
||||||
OnPress: func() error {
|
OnPress: func() error {
|
||||||
return f(true)
|
return f(true)
|
||||||
},
|
},
|
||||||
@ -128,9 +129,10 @@ func (self *WorktreeHelper) NewWorktreeCheckout(base string, canCheckoutBase boo
|
|||||||
}
|
}
|
||||||
|
|
||||||
if canCheckoutBase {
|
if canCheckoutBase {
|
||||||
|
title := utils.ResolvePlaceholderString(self.c.Tr.NewBranchNameLeaveBlank, map[string]string{"default": base})
|
||||||
// prompt for the new branch name where a blank means we just check out the branch
|
// prompt for the new branch name where a blank means we just check out the branch
|
||||||
return self.c.Prompt(types.PromptOpts{
|
return self.c.Prompt(types.PromptOpts{
|
||||||
Title: fmt.Sprintf("New branch name (leave blank to checkout %s)", base),
|
Title: title,
|
||||||
HandleConfirm: func(branchName string) error {
|
HandleConfirm: func(branchName string) error {
|
||||||
opts.Branch = branchName
|
opts.Branch = branchName
|
||||||
|
|
||||||
@ -140,10 +142,10 @@ func (self *WorktreeHelper) NewWorktreeCheckout(base string, canCheckoutBase boo
|
|||||||
} else {
|
} else {
|
||||||
// prompt for the new branch name where a blank means we just check out the branch
|
// prompt for the new branch name where a blank means we just check out the branch
|
||||||
return self.c.Prompt(types.PromptOpts{
|
return self.c.Prompt(types.PromptOpts{
|
||||||
Title: "New branch name",
|
Title: self.c.Tr.NewBranchName,
|
||||||
HandleConfirm: func(branchName string) error {
|
HandleConfirm: func(branchName string) error {
|
||||||
if branchName == "" {
|
if branchName == "" {
|
||||||
return self.c.ErrorMsg("Branch name cannot be blank")
|
return self.c.ErrorMsg(self.c.Tr.BranchNameCannotBeBlank)
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.Branch = branchName
|
opts.Branch = branchName
|
||||||
@ -217,47 +219,28 @@ func (self *WorktreeHelper) Detach(worktree *models.Worktree) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *WorktreeHelper) ViewWorktreeOptions(context types.IListContext, ref string) error {
|
func (self *WorktreeHelper) ViewWorktreeOptions(context types.IListContext, ref string) error {
|
||||||
if context == self.c.Contexts().Branches {
|
currentBranch := self.refsHelper.GetCheckedOutRef()
|
||||||
return self.ViewBranchWorktreeOptions(ref)
|
canCheckoutBase := context == self.c.Contexts().Branches && ref != currentBranch.RefName()
|
||||||
|
|
||||||
|
return self.ViewBranchWorktreeOptions(ref, canCheckoutBase)
|
||||||
}
|
}
|
||||||
|
|
||||||
return self.ViewRefWorktreeOptions(ref)
|
func (self *WorktreeHelper) ViewBranchWorktreeOptions(branchName string, canCheckoutBase bool) error {
|
||||||
}
|
placeholders := map[string]string{"ref": branchName}
|
||||||
|
|
||||||
func (self *WorktreeHelper) ViewBranchWorktreeOptions(branchName string) error {
|
|
||||||
return self.c.Menu(types.CreateMenuOptions{
|
return self.c.Menu(types.CreateMenuOptions{
|
||||||
Title: self.c.Tr.WorktreeTitle,
|
Title: self.c.Tr.WorktreeTitle,
|
||||||
Items: []*types.MenuItem{
|
Items: []*types.MenuItem{
|
||||||
{
|
{
|
||||||
LabelColumns: []string{"Create new worktree from branch"},
|
LabelColumns: []string{utils.ResolvePlaceholderString(self.c.Tr.CreateWorktreeFrom, placeholders)},
|
||||||
OnPress: func() error {
|
OnPress: func() error {
|
||||||
return self.NewWorktreeCheckout(branchName, true, false)
|
return self.NewWorktreeCheckout(branchName, canCheckoutBase, false)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
LabelColumns: []string{"Create new worktree from branch (detached)"},
|
LabelColumns: []string{utils.ResolvePlaceholderString(self.c.Tr.CreateWorktreeFromDetached, placeholders)},
|
||||||
OnPress: func() error {
|
OnPress: func() error {
|
||||||
return self.NewWorktreeCheckout(branchName, true, true)
|
return self.NewWorktreeCheckout(branchName, canCheckoutBase, true)
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *WorktreeHelper) ViewRefWorktreeOptions(ref string) error {
|
|
||||||
return self.c.Menu(types.CreateMenuOptions{
|
|
||||||
Title: self.c.Tr.WorktreeTitle,
|
|
||||||
Items: []*types.MenuItem{
|
|
||||||
{
|
|
||||||
LabelColumns: []string{"Create new worktree from ref"},
|
|
||||||
OnPress: func() error {
|
|
||||||
return self.NewWorktreeCheckout(ref, false, false)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
LabelColumns: []string{"Create new worktree from ref (detached)"},
|
|
||||||
OnPress: func() error {
|
|
||||||
return self.NewWorktreeCheckout(ref, false, true)
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -51,7 +51,7 @@ func getBranchDisplayStrings(
|
|||||||
coloredName := nameTextStyle.Sprint(displayName)
|
coloredName := nameTextStyle.Sprint(displayName)
|
||||||
branchStatus := utils.WithPadding(ColoredBranchStatus(b, tr), 2, utils.AlignLeft)
|
branchStatus := utils.WithPadding(ColoredBranchStatus(b, tr), 2, utils.AlignLeft)
|
||||||
if b.CheckedOutByOtherWorktree {
|
if b.CheckedOutByOtherWorktree {
|
||||||
worktreeIcon := lo.Ternary(icons.IsIconEnabled(), icons.LINKED_WORKTREE_ICON, "(worktree)")
|
worktreeIcon := lo.Ternary(icons.IsIconEnabled(), icons.LINKED_WORKTREE_ICON, fmt.Sprintf("(%s)", tr.LcWorktree))
|
||||||
coloredName = fmt.Sprintf("%s %s", coloredName, style.FgDefault.Sprint(worktreeIcon))
|
coloredName = fmt.Sprintf("%s %s", coloredName, style.FgDefault.Sprint(worktreeIcon))
|
||||||
}
|
}
|
||||||
coloredName = fmt.Sprintf("%s %s", coloredName, branchStatus)
|
coloredName = fmt.Sprintf("%s %s", coloredName, branchStatus)
|
||||||
|
@ -562,8 +562,14 @@ type TranslationSet struct {
|
|||||||
MainWorktree string
|
MainWorktree string
|
||||||
CreateWorktree string
|
CreateWorktree string
|
||||||
NewWorktreePath string
|
NewWorktreePath string
|
||||||
NewWorktreeBranch string
|
NewWorktreeBase string
|
||||||
|
BranchNameCannotBeBlank string
|
||||||
|
NewBranchName string
|
||||||
|
NewBranchNameLeaveBlank string
|
||||||
ViewWorktreeOptions string
|
ViewWorktreeOptions string
|
||||||
|
CreateWorktreeFrom string
|
||||||
|
CreateWorktreeFromDetached string
|
||||||
|
LcWorktree string
|
||||||
Name string
|
Name string
|
||||||
Branch string
|
Branch string
|
||||||
Path string
|
Path string
|
||||||
@ -1288,8 +1294,14 @@ func EnglishTranslationSet() TranslationSet {
|
|||||||
MainWorktree: "(main)",
|
MainWorktree: "(main)",
|
||||||
CreateWorktree: "Create worktree",
|
CreateWorktree: "Create worktree",
|
||||||
NewWorktreePath: "New worktree path",
|
NewWorktreePath: "New worktree path",
|
||||||
NewWorktreeBranch: "New worktree branch (leave blank to use the current branch)",
|
NewWorktreeBase: "New worktree base ref",
|
||||||
|
BranchNameCannotBeBlank: "Branch name cannot be blank",
|
||||||
|
NewBranchName: "New branch name",
|
||||||
|
NewBranchNameLeaveBlank: "New branch name (leave blank to checkout {{.default}})",
|
||||||
ViewWorktreeOptions: "View worktree options",
|
ViewWorktreeOptions: "View worktree options",
|
||||||
|
CreateWorktreeFrom: "Create worktree from {{.ref}}",
|
||||||
|
CreateWorktreeFromDetached: "Create worktree from {{.ref}} (detached)",
|
||||||
|
LcWorktree: "worktree",
|
||||||
Name: "Name",
|
Name: "Name",
|
||||||
Branch: "Branch",
|
Branch: "Branch",
|
||||||
Path: "Path",
|
Path: "Path",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user