URI: 
       langs/i18n: Fallback to defaultContentLanguage instead of English - hugo - [fork] hugo port for 9front
  HTML git clone git@git.drkhsh.at/hugo.git
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
   DIR README
   DIR LICENSE
       ---
   DIR commit 0cb6ca59061eec19ad5117b540728d518caa360a
   DIR parent f1062519ae7d5dd41b681e43e992dbc66fcd0855
  HTML Author: Joe Mooring <joe.mooring@veriphor.com>
       Date:   Sat, 22 Apr 2023 15:58:44 -0700
       
       langs/i18n: Fallback to defaultContentLanguage instead of English
       
       Co-authored-by: 641bill <wo23636@126.com>
       
       Fixes #9216
       
       Diffstat:
         M langs/i18n/integration_test.go      |      38 +++++++++++++++++++++++++++++++
         M langs/i18n/translationProvider.go   |       7 ++++++-
       
       2 files changed, 44 insertions(+), 1 deletion(-)
       ---
   DIR diff --git a/langs/i18n/integration_test.go b/langs/i18n/integration_test.go
       @@ -103,3 +103,41 @@ i18n: {{ i18n "a" . }}|
                i18n: Reading time: 3|
                `)
        }
       +
       +// Issue 9216
       +func TestI18nDefaultContentLanguage(t *testing.T) {
       +        t.Parallel()
       +
       +        files := `
       +-- config.toml --
       +disableKinds = ['RSS','sitemap','taxonomy','term','page','section']
       +defaultContentLanguage = 'es'
       +defaultContentLanguageInSubdir = true
       +[languages.es]
       +[languages.fr]
       +-- i18n/es.toml --
       +cat = 'gato'
       +-- i18n/fr.toml --
       +# this file intentionally empty
       +-- layouts/index.html --
       +{{ .Title }}_{{ T "cat" }}
       +-- content/_index.fr.md --
       +---
       +title: home_fr
       +---
       +-- content/_index.md --
       +---
       +title: home_es
       +---
       +`
       +
       +        b := hugolib.NewIntegrationTestBuilder(
       +                hugolib.IntegrationTestConfig{
       +                        T:           t,
       +                        TxtarString: files,
       +                },
       +        ).Build()
       +
       +        b.AssertFileContent("public/es/index.html", `home_es_gato`)
       +        b.AssertFileContent("public/fr/index.html", `home_fr_gato`)
       +}
   DIR diff --git a/langs/i18n/translationProvider.go b/langs/i18n/translationProvider.go
       @@ -48,7 +48,12 @@ func NewTranslationProvider() *TranslationProvider {
        func (tp *TranslationProvider) Update(d *deps.Deps) error {
                spec := source.NewSourceSpec(d.PathSpec, nil, nil)
        
       -        bundle := i18n.NewBundle(language.English)
       +        var defaultLangTag, err = language.Parse(d.Cfg.GetString("defaultContentLanguage"))
       +        if err != nil {
       +                defaultLangTag = language.English
       +        }
       +        bundle := i18n.NewBundle(defaultLangTag)
       +
                bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
                bundle.RegisterUnmarshalFunc("yaml", yaml.Unmarshal)
                bundle.RegisterUnmarshalFunc("yml", yaml.Unmarshal)