With #14225 we now look for:
- A translation table matching the current language's
LanguageCode (new behavior), falling back to...
- A translation table matching the current language's key, falling back to...
- A translation table matching the
defaultContentLanguage
That means that you can now do this, which is great:
defaultContentLanguage = 'en'
[languages.en]
languageCode = 'en-US'
weight = 1
[languages.de]
languageCode = 'de-DE'
weight = 2
i18n/
├── de-de.toml
└── en-us.toml
But for the last fallback (item 3 in the list above) to work, you must also have an en.toml file in the i18n directory, which isn't great. We should fallback to a translation table matching the LanguageCode of the defaultContentLanguage, then to a translation table matching the defaultContentLanguage.
Integration test:
func TestDefaultContentLanguageFallback14243(t *testing.T) {
t.Parallel()
files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
defaultContentLanguage = 'es'
defaultContentLanguageInSubdir = true
[languages.es]
locale = 'es-AR'
weight = 1
[languages.pt]
locale = 'pt-BR'
weight = 2
-- layouts/home.html --
{{ T "foo"}}|
-- i18n/es-ar.toml --
foo = 'foo es-ar'
-- i18n/es.toml --
foo = 'foo es'
-- i18n/pt-br.toml --
foo = 'foo pt-br'
-- i18n/pt.toml --
foo = 'foo pt'
`
b := hugolib.Test(t, files)
b.AssertFileContent("public/pt/index.html", "foo pt-br|")
files = strings.ReplaceAll(files, "i18n/pt-br.toml", "unused-a.toml")
b = hugolib.Test(t, files)
b.AssertFileContent("public/pt/index.html", "foo pt|")
files = strings.ReplaceAll(files, "i18n/pt.toml", "unused-b.toml")
b = hugolib.Test(t, files)
b.AssertFileContent("public/pt/index.html", "foo es-ar|")
files = strings.ReplaceAll(files, "i18n/es-ar.toml", "unused-c.toml")
b = hugolib.Test(t, files)
b.AssertFileContent("public/pt/index.html", "foo es|")
}
cc: @chalin
With #14225 we now look for:
LanguageCode(new behavior), falling back to...defaultContentLanguageThat means that you can now do this, which is great:
But for the last fallback (item 3 in the list above) to work, you must also have an
en.tomlfile in thei18ndirectory, which isn't great. We should fallback to a translation table matching theLanguageCodeof thedefaultContentLanguage, then to a translation table matching thedefaultContentLanguage.Integration test:
cc: @chalin