hugo
hugo copied to clipboard
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...
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,
defaultContentLanguagemeans 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.
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)
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.