I’m happy to see the upcoming fluent
function (#1040), but with the current configuration system, it won’t solve some of the awkwardness with the localization system and create some more, namely:
- Basic config options like title and description cannot be configured language-specifically,
- Tucking all locale-aware operations into functions means backwards-compatibility for config files, not for themes/tempates. In my opinion, the opposite outcome is desired. Writing a verbose expression like
{{ fluent(lang=lang, key="description") | default(value=config.description) }}
is way too clunky compared to having a language-awareconfig
struct. - Fluent is too awkward for use in configuring themes. One should not need to mess with a domain-specific language to adjust parameters like
author_name
orbio
. Hugo still retains theconfig.languages
key with the ability to transparently override global options alongside thei18n
function for strings translation. - Moving language codes to
unic_langid::LanguageIdentifier
breaks links for sites that did not specify languages with the canonical BCP 47 syntax.
I propose completely redesigning how languages are handled both internally and in the user-facing API.
- Store languages as
LanguageIdentifier
but allow mapping analias
to them which will be used in URLs. This is needed because Fluent treats numbers and dates differently based on language. Having an incorrect language should be a fatal error. - Replace
config.languages: Vec<lLanguage>
andconfig.translations: HashMap<String, TranslateTerm>
with a singleconfig.languages: HashMap<LanguageIdentifier, Language>
- Move language-specific config options (
taxonomies
,title
,description
,extra
etc.) intoLanguages
. - Create a newtype
struct LanguageConfig(Config)
that is generated by overriding specific fields ofConfig
with language-specific options fromLanguage
and pass that as theconfig
object to templates. - Deprecate the
trans
function for general use, but keep it as an interface for getting options for a specific language. So,trans(lang="lang", key="key")
would basically returnconfig.languages._lang_.extra._key_
, which is the new equivalent ofconfig.translations._lang_._key_
.
Pretty much every module that deals with the config and templates needs to be changed. Because this change would be pretty big (I estimate 500+ lines excluding tests and benches), I want to open a discussion about how people want the localization system to function and to get a go-ahead from those working on Zola or using it in production environments.
I’ve already mentioned some of these on the PR created by @XAMPPRocky . They have not responded to my commits in a while and the current progress would need to be rewritten to accommodate these architectural changes, so I’d like to take over and file a new PR. I’m a high school student with currently a crap-ton of time so besides review and the occasional question, I can handle this.
sorry for not linking relevant stuff, but I triggered the abuse detection with my references