-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed
Description
When using a language with a custom key including a slash the generated translate function keys won't match the i18n translation files.
According to the documentation:
From Hugo 0.31 you no longer need to use a valid language code. It can be anything.
#3564
When using a language config like this:
languages:
fragen:
languageName: Deutsch
# ....
en/questions:
languageName: English
# ....
The generated translate function will use the i18n translation file names as keys.
But executing the translation, the lookup key will be using the original languages key ("fragen"
and "en/questions"
respectively)
Since I cannot name the translation files including a slash, I tried replacing it with a colon, but had no success.
For me this patch works, but it is hardly a generic solution
--- a/langs/i18n/i18n.go
+++ b/langs/i18n/i18n.go
@@ -49,6 +49,7 @@ func NewTranslator(b *i18n.Bundle, cfg config.Provider, logger loggers.Logger) T
// Func gets the translate func for the given language, or for the default
// configured language if not found.
func (t Translator) Func(lang string) translateFunc {
+ lang = strings.SplitN(lang, "/", 2)[0]
if f, ok := t.translateFuncs[lang]; ok {
return f
}
What version of Hugo are you using (hugo version
)?
$ hugo version hugo v0.89.0-ADE966B8 linux/amd64 BuildDate=2021-11-02T10:00:18Z VendorInfo=gohugoio
Does this issue reproduce with the latest release?
Yes