From 2499a6c8a32902fd36014cf2c0add6b4af3764af Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 27 Jul 2024 21:39:46 +0200 Subject: [PATCH] Initialize translation set after reading user config This allows having per-repo config files with different languages per repo. Now granted, this is not an important use case that we need to support; however, the goal is to eventually make all configs hot-reloadable (as opposed to loading them only once at startup), so this is one step in that direction. --- pkg/app/app.go | 9 +++------ pkg/cheatsheet/generate.go | 5 +++++ pkg/gui/gui.go | 12 ++++++++++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/pkg/app/app.go b/pkg/app/app.go index bbe714458..a999a902b 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -63,13 +63,10 @@ func Run( func NewCommon(config config.AppConfigurer) (*common.Common, error) { userConfig := config.GetUserConfig() appState := config.GetAppState() - - var err error log := newLogger(config) - tr, err := i18n.NewTranslationSetFromConfig(log, userConfig.Gui.Language) - if err != nil { - return nil, err - } + // Initialize with English for the time being; the real translation set for + // the configured language will be read after reading the user config + tr := i18n.EnglishTranslationSet() cmn := &common.Common{ Log: log, diff --git a/pkg/cheatsheet/generate.go b/pkg/cheatsheet/generate.go index 5f0d7549d..100245f62 100644 --- a/pkg/cheatsheet/generate.go +++ b/pkg/cheatsheet/generate.go @@ -63,6 +63,11 @@ func generateAtDir(cheatsheetDir string) { if err != nil { log.Fatal(err) } + tr, err := i18n.NewTranslationSetFromConfig(common.Log, lang) + if err != nil { + log.Fatal(err) + } + common.Tr = tr mApp, _ := app.NewApp(mConfig, nil, common) path := cheatsheetDir + "/Keybindings_" + lang + ".md" file, err := os.Create(path) diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 015aec1fa..582047ab9 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -36,6 +36,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/gui/status" "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/gui/types" + "github.com/jesseduffield/lazygit/pkg/i18n" "github.com/jesseduffield/lazygit/pkg/integration/components" integrationTypes "github.com/jesseduffield/lazygit/pkg/integration/types" "github.com/jesseduffield/lazygit/pkg/tasks" @@ -138,6 +139,8 @@ type Gui struct { c *helpers.HelperCommon helpers *helpers.Helpers + previousLanguageConfig string + integrationTest integrationTypes.IntegrationTest afterLayoutFuncs chan func() error @@ -383,6 +386,15 @@ func (gui *Gui) onUserConfigLoaded() error { gui.setColorScheme() gui.configureViewProperties() + if gui.previousLanguageConfig != userConfig.Gui.Language { + tr, err := i18n.NewTranslationSetFromConfig(gui.Log, userConfig.Gui.Language) + if err != nil { + return err + } + gui.c.Tr = tr + gui.previousLanguageConfig = userConfig.Gui.Language + } + return nil }