allow user to configure the gui language

pull/265/head
Dwarven YANG 3 years ago
parent c88fba546f
commit 43f83f64ec

@ -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

@ -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

@ -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,
}
}

@ -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{

@ -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
}
for key := range GetTranslationSets() {
if key == configLanguage {
return NewTranslationSet(log, configLanguage), nil
}
}
return NewTranslationSet(log, "en"), errors.New("Language not found: " + configLanguage)
}
log.Info("language: " + userLang)
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)
}
}

Loading…
Cancel
Save