diff options
author | Bjørn Erik Pedersen <[email protected]> | 2017-02-05 10:20:06 +0700 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2017-02-17 17:15:26 +0100 |
commit | 93ca7c9e958e34469a337e4efcc7c75774ec50fd (patch) | |
tree | 5dfa296cfe74fd5ef8f0d41ea4078704f453aa04 /hugolib/multilingual.go | |
parent | e34af6ee30f70f5780a281e2fd8f4ed9b487ee61 (diff) | |
download | hugo-93ca7c9e958e34469a337e4efcc7c75774ec50fd.tar.gz hugo-93ca7c9e958e34469a337e4efcc7c75774ec50fd.zip |
all: Refactor to nonglobal Viper, i18n etc.
This is a final rewrite that removes all the global state in Hugo, which also enables
the use if `t.Parallel` in tests.
Updates #2701
Fixes #3016
Diffstat (limited to 'hugolib/multilingual.go')
-rw-r--r-- | hugolib/multilingual.go | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/hugolib/multilingual.go b/hugolib/multilingual.go index 29a2ea93a..c5943dbd5 100644 --- a/hugolib/multilingual.go +++ b/hugolib/multilingual.go @@ -22,6 +22,7 @@ import ( "fmt" "github.com/spf13/cast" + "github.com/spf13/hugo/config" "github.com/spf13/hugo/helpers" ) @@ -44,7 +45,7 @@ func (ml *Multilingual) Language(lang string) *helpers.Language { return ml.langMap[lang] } -func newMultiLingualFromSites(sites ...*Site) (*Multilingual, error) { +func newMultiLingualFromSites(cfg config.Provider, sites ...*Site) (*Multilingual, error) { languages := make(helpers.Languages, len(sites)) for i, s := range sites { @@ -54,12 +55,14 @@ func newMultiLingualFromSites(sites ...*Site) (*Multilingual, error) { languages[i] = s.Language } - return &Multilingual{Languages: languages, DefaultLang: helpers.NewDefaultLanguage()}, nil + defaultLang := cfg.GetString("defaultContentLanguage") -} + if defaultLang == "" { + defaultLang = "en" + } + + return &Multilingual{Languages: languages, DefaultLang: helpers.NewLanguage(defaultLang, cfg)}, nil -func newMultiLingualDefaultLanguage() *Multilingual { - return newMultiLingualForLanguage(helpers.NewDefaultLanguage()) } func newMultiLingualForLanguage(language *helpers.Language) *Multilingual { @@ -77,7 +80,7 @@ func (s *Site) multilingualEnabled() bool { return s.owner.multilingual != nil && s.owner.multilingual.enabled() } -func toSortedLanguages(l map[string]interface{}) (helpers.Languages, error) { +func toSortedLanguages(cfg config.Provider, l map[string]interface{}) (helpers.Languages, error) { langs := make(helpers.Languages, len(l)) i := 0 @@ -88,7 +91,7 @@ func toSortedLanguages(l map[string]interface{}) (helpers.Languages, error) { return nil, fmt.Errorf("Language config is not a map: %T", langConf) } - language := helpers.NewLanguage(lang) + language := helpers.NewLanguage(lang, cfg) for loki, v := range langsMap { switch loki { |