-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Open
Description
Hugo currently loads i18n translation tables based only on the language key in the languages map (Lang). This causes a mismatch when a site sets a more specific languageCode but retains a short language key.
Example:
languages:
pt:
languageCode: pt-BRi18n/
├── en.toml # Default language
├── [No pt.toml file exists here on in themes etc.]
└── pt-br.toml
When rendering {{ T "some-key" }} for the pt site, Hugo falls back to en.toml because it looks only for pt.toml, ignoring the declared languageCode: pt-BR even though a matching pt-br.toml file exists.
Proposed behavior
If languages.<LANG_KEY>.languageCode is set:
- Try loading translations using
languageCode. - If no matching file exists, fall back to current behavior.
Benefits
The proposed behavior maximizes compatibility with existing behavior, while maximizing utility to site authors. Also it:
- Makes translation lookup consistent with the language declared for the site.
- Supports region-specific translations (
pt-BR,pt-PT, etc.) without needing multiple language keys. - Improves compatibility with themes/modules that ship region-coded translation files (e.g.,
pt-br.toml,zh-hans.toml).
Related
- Hugo cannot identity correct translation string when multiple variants of a language code is used #7982
- Downstream context: [i18n] Translation IDs are not being resolved for pt-BR or zh-CN, or they are but with warnings open-telemetry/opentelemetry.io#8481
Minimal site for testing
vitorvasc and emdneto