Repository: gohugoio/hugo (language: go)

Issue:
Hardcoded default lang?
Is it possible to NOT use English as default fallback language, or to not use it at all? We have multiple languages on our site, but we don't have English. For that reason we don't have en.toml, just sr.toml and hu.toml. The default lang is "sr", but the fallback for the missing translations are not working. I'm not a Go developer, but I can see that English is kinda must-have lang at this line:
https://github.com/gohugoio/hugo/blob/75a823a36a75781c0c5d89fe9f328e3b9322d95f/langs/i18n/translationProvider.go#L51

The tests are passing, because they are using "en" as `defaultContentLanguage`, but that gives a "fake" success. Changing the `defaultContentLanguage` to some other lang (and also replacing "en" to that lang everywhere in the tests) results to failing tests...


Discussion / hints:
From memory, `defaultContentLanguage` means _the language assigned to content with no language identifier_ (e.g. `my-post.md`). Are you saying that that statement does not hold water?
> From memory, `defaultContentLanguage` means _the language assigned to content with no language identifier_ (e.g. `my-post.md`). Are you saying that that statement does not hold water?

According to this: https://gohugo.io/content-management/multilingual/#missing-translations
> If a string does not have a translation for the current language, Hugo will use the value from the default language.

and

> defaultContentLanguage sets the project’s default language. If not set, the default language will be en.

... but it is not possible to use other language codes, other than "en", as setting the `defaultContentLanguage` to "sr", with the missing `i18n/en.toml`, Hugo won't use the value from `i18n/sr.toml`, if there is a missing key in `i18n/hu.toml`.

I'm saying that `i18n/en.toml` is mandatory, even there are some cases when a website doesn't have English content. Maybe, it is like this for a reason, but I'm curious what is the recommended solution or configuration for these scenarios.
Confirmed.

```bash
git clone --single-branch -b hugo-github-issue-9216 https://github.com/jmooring/hugo-testing hugo-github-issue-9216
cd hugo-github-issue-9216
hugo server
```

Look at the Français home page. The translation for "dog" is missing even though it is defined in the default language (Deutsch).

If you create an i18n/en.toml file with a translation for "dog", that translation fills in the missing translation. But this site only has three languages: Deutsch, Español, and Français.
Hi, we group of 4 university students would like to attempt this issue as a part of our course project!
Hi! We think that the issue can be resolved by replacing `bundle := i18n.NewBundle(language.English)` with 
```
var defaultLang string
defaultLang = d.Cfg.GetString("defaultContentLanguage")
if defaultLang == "" {
    defaultLang = "en"
}
var defaultLangTag language.Tag
defaultLangTag, err := language.Parse(defaultLang)
// If the default language set can not be parsed to a valid language tag,
// we will fall back to en.
if err != nil {
    defaultLangTag = language.English
}
bundle := i18n.NewBundle(defaultLangTag)
```

Fix patch:
diff --git a/langs/i18n/translationProvider.go b/langs/i18n/translationProvider.go
index d9d334567f9..782bbf719fb 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)


Test patch:
diff --git a/langs/i18n/integration_test.go b/langs/i18n/integration_test.go
index a433fc4cdfc..c010ac1113b 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`)
+}