mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-02 23:27:32 +02:00
allow user to configure the gui language
This commit is contained in:
parent
44d08edfb0
commit
63072af5bc
@ -22,6 +22,7 @@ gui:
|
|||||||
sidePanelWidth: 0.3333 # number from 0 to 1
|
sidePanelWidth: 0.3333 # number from 0 to 1
|
||||||
expandFocusedSidePanel: false
|
expandFocusedSidePanel: false
|
||||||
mainPanelSplitMode: 'flexible' # one of 'horizontal' | 'flexible' | 'vertical'
|
mainPanelSplitMode: 'flexible' # one of 'horizontal' | 'flexible' | 'vertical'
|
||||||
|
language: 'auto' # one of 'auto' | 'en' | 'zh' | 'pl' | 'nl'
|
||||||
theme:
|
theme:
|
||||||
lightTheme: false # For terminals with a light background
|
lightTheme: false # For terminals with a light background
|
||||||
activeBorderColor:
|
activeBorderColor:
|
||||||
|
@ -102,7 +102,10 @@ func NewApp(config config.AppConfigurer, filterPath string) (*App, error) {
|
|||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
app.Log = newLogger(config)
|
app.Log = newLogger(config)
|
||||||
app.Tr = i18n.NewTranslationSet(app.Log)
|
app.Tr, err = i18n.NewTranslationSetFromConfig(app.Log, config.GetUserConfig().Gui.Language)
|
||||||
|
if err != nil {
|
||||||
|
return app, err
|
||||||
|
}
|
||||||
|
|
||||||
// if we are being called in 'demon' mode, we can just return here
|
// if we are being called in 'demon' mode, we can just return here
|
||||||
app.ClientContext = os.Getenv("LAZYGIT_CLIENT_COMMAND")
|
app.ClientContext = os.Getenv("LAZYGIT_CLIENT_COMMAND")
|
||||||
|
@ -14,11 +14,12 @@ func NewDummyGitCommand() *GitCommand {
|
|||||||
|
|
||||||
// NewDummyGitCommandWithOSCommand creates a new dummy GitCommand for testing
|
// NewDummyGitCommandWithOSCommand creates a new dummy GitCommand for testing
|
||||||
func NewDummyGitCommandWithOSCommand(osCommand *oscommands.OSCommand) *GitCommand {
|
func NewDummyGitCommandWithOSCommand(osCommand *oscommands.OSCommand) *GitCommand {
|
||||||
|
newAppConfig := config.NewDummyAppConfig()
|
||||||
return &GitCommand{
|
return &GitCommand{
|
||||||
Log: utils.NewDummyLog(),
|
Log: utils.NewDummyLog(),
|
||||||
OSCommand: osCommand,
|
OSCommand: osCommand,
|
||||||
Tr: i18n.NewTranslationSet(utils.NewDummyLog()),
|
Tr: i18n.NewTranslationSet(utils.NewDummyLog(), newAppConfig.GetUserConfig().Gui.Language),
|
||||||
Config: config.NewDummyAppConfig(),
|
Config: newAppConfig,
|
||||||
getGitConfigValue: func(string) (string, error) { return "", nil },
|
getGitConfigValue: func(string) (string, error) { return "", nil },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,8 @@ func TestNewGitCommand(t *testing.T) {
|
|||||||
for _, s := range scenarios {
|
for _, s := range scenarios {
|
||||||
t.Run(s.testName, func(t *testing.T) {
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
s.setup()
|
s.setup()
|
||||||
s.test(NewGitCommand(utils.NewDummyLog(), oscommands.NewDummyOSCommand(), i18n.NewTranslationSet(utils.NewDummyLog()), config.NewDummyAppConfig()))
|
newAppConfig := config.NewDummyAppConfig()
|
||||||
|
s.test(NewGitCommand(utils.NewDummyLog(), oscommands.NewDummyOSCommand(), i18n.NewTranslationSet(utils.NewDummyLog(), newAppConfig.GetUserConfig().Gui.Language), newAppConfig))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ func NewDummyCommitListBuilder() *CommitListBuilder {
|
|||||||
Log: utils.NewDummyLog(),
|
Log: utils.NewDummyLog(),
|
||||||
GitCommand: NewDummyGitCommandWithOSCommand(osCommand),
|
GitCommand: NewDummyGitCommandWithOSCommand(osCommand),
|
||||||
OSCommand: osCommand,
|
OSCommand: osCommand,
|
||||||
Tr: i18n.NewTranslationSet(utils.NewDummyLog()),
|
Tr: i18n.NewTranslationSet(utils.NewDummyLog(), "auto"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ type GuiConfig struct {
|
|||||||
SidePanelWidth float64 `yaml:"sidePanelWidth"`
|
SidePanelWidth float64 `yaml:"sidePanelWidth"`
|
||||||
ExpandFocusedSidePanel bool `yaml:"expandFocusedSidePanel"`
|
ExpandFocusedSidePanel bool `yaml:"expandFocusedSidePanel"`
|
||||||
MainPanelSplitMode string `yaml:"mainPanelSplitMode"`
|
MainPanelSplitMode string `yaml:"mainPanelSplitMode"`
|
||||||
|
Language string `yaml:"language"`
|
||||||
Theme ThemeConfig `yaml:"theme"`
|
Theme ThemeConfig `yaml:"theme"`
|
||||||
CommitLength CommitLengthConfig `yaml:"commitLength"`
|
CommitLength CommitLengthConfig `yaml:"commitLength"`
|
||||||
SkipNoStagedFilesWarning bool `yaml:"skipNoStagedFilesWarning"`
|
SkipNoStagedFilesWarning bool `yaml:"skipNoStagedFilesWarning"`
|
||||||
@ -310,6 +311,7 @@ func GetDefaultConfig() *UserConfig {
|
|||||||
SidePanelWidth: 0.3333,
|
SidePanelWidth: 0.3333,
|
||||||
ExpandFocusedSidePanel: false,
|
ExpandFocusedSidePanel: false,
|
||||||
MainPanelSplitMode: "flexible",
|
MainPanelSplitMode: "flexible",
|
||||||
|
Language: "auto",
|
||||||
Theme: ThemeConfig{
|
Theme: ThemeConfig{
|
||||||
LightTheme: false,
|
LightTheme: false,
|
||||||
ActiveBorderColor: []string{"green", "bold"},
|
ActiveBorderColor: []string{"green", "bold"},
|
||||||
|
@ -11,11 +11,13 @@ import (
|
|||||||
|
|
||||||
// NewDummyGui creates a new dummy GUI for testing
|
// NewDummyGui creates a new dummy GUI for testing
|
||||||
func NewDummyUpdater() *updates.Updater {
|
func NewDummyUpdater() *updates.Updater {
|
||||||
DummyUpdater, _ := updates.NewUpdater(utils.NewDummyLog(), config.NewDummyAppConfig(), oscommands.NewDummyOSCommand(), i18n.NewTranslationSet(utils.NewDummyLog()))
|
newAppConfig := config.NewDummyAppConfig()
|
||||||
|
DummyUpdater, _ := updates.NewUpdater(utils.NewDummyLog(), newAppConfig, oscommands.NewDummyOSCommand(), i18n.NewTranslationSet(utils.NewDummyLog(), newAppConfig.GetUserConfig().Gui.Language))
|
||||||
return DummyUpdater
|
return DummyUpdater
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDummyGui() *Gui {
|
func NewDummyGui() *Gui {
|
||||||
DummyGui, _ := NewGui(utils.NewDummyLog(), commands.NewDummyGitCommand(), oscommands.NewDummyOSCommand(), i18n.NewTranslationSet(utils.NewDummyLog()), config.NewDummyAppConfig(), NewDummyUpdater(), "", false)
|
newAppConfig := config.NewDummyAppConfig()
|
||||||
|
DummyGui, _ := NewGui(utils.NewDummyLog(), commands.NewDummyGitCommand(), oscommands.NewDummyOSCommand(), i18n.NewTranslationSet(utils.NewDummyLog(), newAppConfig.GetUserConfig().Gui.Language), newAppConfig, NewDummyUpdater(), "", false)
|
||||||
return DummyGui
|
return DummyGui
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/cloudfoundry/jibber_jabber"
|
"github.com/cloudfoundry/jibber_jabber"
|
||||||
|
"github.com/go-errors/errors"
|
||||||
"github.com/imdario/mergo"
|
"github.com/imdario/mergo"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@ -14,20 +15,31 @@ type Localizer struct {
|
|||||||
S TranslationSet
|
S TranslationSet
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTranslationSet creates a new Localizer
|
func NewTranslationSetFromConfig(log *logrus.Entry, configLanguage string) (*TranslationSet, error) {
|
||||||
func NewTranslationSet(log *logrus.Entry) *TranslationSet {
|
if configLanguage == "auto" {
|
||||||
userLang := detectLanguage(jibber_jabber.DetectLanguage)
|
language := detectLanguage(jibber_jabber.DetectLanguage)
|
||||||
|
return NewTranslationSet(log, language), nil
|
||||||
|
}
|
||||||
|
|
||||||
log.Info("language: " + userLang)
|
for key := range GetTranslationSets() {
|
||||||
|
if key == configLanguage {
|
||||||
|
return NewTranslationSet(log, configLanguage), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NewTranslationSet(log, "en"), errors.New("Language not found: " + configLanguage)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewTranslationSet(log *logrus.Entry, language string) *TranslationSet {
|
||||||
|
log.Info("language: " + language)
|
||||||
|
|
||||||
baseSet := englishTranslationSet()
|
baseSet := englishTranslationSet()
|
||||||
|
|
||||||
for languageCode, translationSet := range GetTranslationSets() {
|
for languageCode, translationSet := range GetTranslationSets() {
|
||||||
if strings.HasPrefix(userLang, languageCode) {
|
if strings.HasPrefix(language, languageCode) {
|
||||||
_ = mergo.Merge(&baseSet, translationSet, mergo.WithOverride)
|
_ = mergo.Merge(&baseSet, translationSet, mergo.WithOverride)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &baseSet
|
return &baseSet
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user