diff --git a/docs/Config.md b/docs/Config.md index 5f35dc72..20221fa2 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -16,6 +16,7 @@ Changes to the user config will only take place after closing and re-opening laz ```yml gui: scrollHeight: 2 + language: 'auto' # one of 'auto' | 'en' | 'pl' | 'nl' | 'de' | 'tr' theme: activeBorderColor: - green diff --git a/pkg/app/app.go b/pkg/app/app.go index ffc73494..c1b426b8 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -34,7 +34,10 @@ func NewApp(config *config.AppConfig) (*App, error) { } var err error app.Log = log.NewLogger(config, "23432119147a4367abf7c0de2aa99a2d") - app.Tr = i18n.NewTranslationSet(app.Log) + app.Tr, err = i18n.NewTranslationSetFromConfig(app.Log, config.UserConfig.Gui.Language) + if err != nil { + return app, err + } app.OSCommand = commands.NewOSCommand(app.Log, config) // here is the place to make use of the docker-compose.yml file in the current directory diff --git a/pkg/commands/dummies.go b/pkg/commands/dummies.go index c32e8f76..416a57dd 100644 --- a/pkg/commands/dummies.go +++ b/pkg/commands/dummies.go @@ -42,10 +42,11 @@ func NewDummyDockerCommand() *DockerCommand { // NewDummyDockerCommandWithOSCommand creates a new dummy DockerCommand for testing func NewDummyDockerCommandWithOSCommand(osCommand *OSCommand) *DockerCommand { + newAppConfig := NewDummyAppConfig() return &DockerCommand{ Log: NewDummyLog(), OSCommand: osCommand, - Tr: i18n.NewTranslationSet(NewDummyLog()), - Config: NewDummyAppConfig(), + Tr: i18n.NewTranslationSet(NewDummyLog(), newAppConfig.UserConfig.Gui.Language), + Config: newAppConfig, } } diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 8c8fa8a9..00f62208 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -79,6 +79,9 @@ type GuiConfig struct { // scrolling the main panel ScrollHeight int `yaml:"scrollHeight,omitempty"` + // Language determines which language the GUI displayed. + Language string `yaml:"language,omitempty"` + // ScrollPastBottom determines whether you can scroll past the bottom of the // main view ScrollPastBottom bool `yaml:"scrollPastBottom,omitempty"` @@ -311,6 +314,7 @@ func GetDefaultConfig() UserConfig { return UserConfig{ Gui: GuiConfig{ ScrollHeight: 2, + Language: "auto", ScrollPastBottom: false, IgnoreMouseEvents: false, Theme: ThemeConfig{ diff --git a/pkg/i18n/i18n.go b/pkg/i18n/i18n.go index bdc62ab1..914ec1ba 100644 --- a/pkg/i18n/i18n.go +++ b/pkg/i18n/i18n.go @@ -6,6 +6,7 @@ import ( "github.com/imdario/mergo" "github.com/cloudfoundry/jibber_jabber" + "github.com/go-errors/errors" "github.com/sirupsen/logrus" ) @@ -16,16 +17,28 @@ type Localizer struct { S TranslationSet } -// NewTranslationSet creates a new Localizer -func NewTranslationSet(log *logrus.Entry) *TranslationSet { - userLang := detectLanguage(jibber_jabber.DetectLanguage) +func NewTranslationSetFromConfig(log *logrus.Entry, configLanguage string) (*TranslationSet, error) { + if configLanguage == "auto" { + 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 := englishSet() for languageCode, translationSet := range GetTranslationSets() { - if strings.HasPrefix(userLang, languageCode) { + if strings.HasPrefix(language, languageCode) { _ = mergo.Merge(&baseSet, translationSet, mergo.WithOverride) } }