hugo icon indicating copy to clipboard operation
hugo copied to clipboard

Hardcoded default lang?

Open nandorstanko opened this issue 3 years ago • 5 comments

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...

nandorstanko avatar Nov 29 '21 10:11 nandorstanko

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?

bep avatar Nov 29 '21 11:11 bep

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.

nandorstanko avatar Nov 29 '21 12:11 nandorstanko

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.

jmooring avatar Nov 29 '21 17:11 jmooring

Hi, we group of 4 university students would like to attempt this issue as a part of our course project!

641bill avatar Mar 01 '22 13:03 641bill

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)

641bill avatar Mar 06 '22 13:03 641bill

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.

github-actions[bot] avatar May 16 '23 01:05 github-actions[bot]