diff options
author | Joe Mooring <[email protected]> | 2023-04-22 15:58:44 -0700 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2023-04-24 21:20:09 +0200 |
commit | 0cb6ca59061eec19ad5117b540728d518caa360a (patch) | |
tree | cd73274f378fb8b2cc001de1dabae41bf119e0e7 /langs | |
parent | f1062519ae7d5dd41b681e43e992dbc66fcd0855 (diff) | |
download | hugo-0cb6ca59061eec19ad5117b540728d518caa360a.tar.gz hugo-0cb6ca59061eec19ad5117b540728d518caa360a.zip |
langs/i18n: Fallback to defaultContentLanguage instead of English
Co-authored-by: 641bill <[email protected]>
Fixes #9216
Diffstat (limited to 'langs')
-rw-r--r-- | langs/i18n/integration_test.go | 38 | ||||
-rw-r--r-- | langs/i18n/translationProvider.go | 7 |
2 files changed, 44 insertions, 1 deletions
diff --git a/langs/i18n/integration_test.go b/langs/i18n/integration_test.go index a433fc4cd..c010ac111 100644 --- 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`) +} diff --git a/langs/i18n/translationProvider.go b/langs/i18n/translationProvider.go index d9d334567..782bbf719 100644 --- 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) |