Problem
Zola already knows the active language when rendering a page — it's embedded in the routing context (/es/... → lang = "es"). But trans(key="foo") ignores this and always defaults to default_language. And trans(key="foo", lang=lang) throws a hard error if the key is missing in that language.
This makes partial translations impractical. Common scenario: a site where [translations] is fully filled but [languages.es.translations] only has a few keys so far. Right now you have two bad options:
- Duplicate all default language keys into every language, even untranslated ones
- Never pass
lang=lang and keep the UI permanently in the default language
Proposed solutions
Option A — change default behavior of trans() (breaking):
trans(key="foo") without explicit lang= uses the active page language first, falls back to default_language if the key is missing. Strict behavior can be opted into per-call or globally in config.toml:
{{ trans(key="foo") }} {# active lang → fallback to default #}
{{ trans(key="foo", strict=true) }} {# error if key missing #}
# config.toml — enforce strict mode globally
[translations]
strict = true
Option B — new function trans_fallback() (non-breaking):
{{ trans_fallback(key="foo") }} {# active lang → fallback to default #}
{{ trans(key="foo", lang=lang) }} {# existing strict behavior unchanged #}
Option C — fallback parameter on existing trans() (non-breaking):
{{ trans(key="foo", lang=lang, fallback=true) }}
Personally I find Option B the most pragmatic — it doesn't touch existing behavior at all and gives users an explicit opt-in for the fallback semantic.
Happy to open a PR for whichever direction you prefer.
Problem
Zola already knows the active language when rendering a page — it's embedded in the routing context (
/es/...→lang = "es"). Buttrans(key="foo")ignores this and always defaults todefault_language. Andtrans(key="foo", lang=lang)throws a hard error if the key is missing in that language.This makes partial translations impractical. Common scenario: a site where
[translations]is fully filled but[languages.es.translations]only has a few keys so far. Right now you have two bad options:lang=langand keep the UI permanently in the default languageProposed solutions
Option A — change default behavior of
trans()(breaking):trans(key="foo")without explicitlang=uses the active page language first, falls back todefault_languageif the key is missing. Strict behavior can be opted into per-call or globally inconfig.toml:Option B — new function
trans_fallback()(non-breaking):Option C —
fallbackparameter on existingtrans()(non-breaking):Personally I find Option B the most pragmatic — it doesn't touch existing behavior at all and gives users an explicit opt-in for the fallback semantic.
Happy to open a PR for whichever direction you prefer.