tera icon indicating copy to clipboard operation
tera copied to clipboard

Add Fluent based l10n/i18n functions

Open alerque opened this issue 4 years ago • 7 comments

I saw #543 that touches on needed apparatus, but I'd like to propose a feature request that goes a step farther...

A set of localization functions used Fluent should be first class baked in tools. The ergonomics of Rust tooling for Fluent has been improving, but access from templating systems is still lacking in a number of places.

A Rust helper exists already for Rust Handlebars (cf. runtime variant, several non-handlebars Fluent templating crates). I've found that useful, but I'm now stuck using Tera for some projects and miss it sorely.

Many downstream projects would benefit from this rather than having to re-invent the wheel. For example the Zola static site generator has a long running feature request for better i18n function where I and others keep requesting Fluent access, but so far the non Fluent flat key based system they've been able to provide is lack-luster at best and flat out awkward or unworkable at worst. I think if Tera provided a basic function set it would be much easier to wire in to other projects.

alerque avatar Jun 30 '21 09:06 alerque

Isn't that what https://docs.rs/fluent-templates/0.6.1/fluent_templates/ does?

Keats avatar Jun 30 '21 09:06 Keats

I was unaware fluent_templates had some Tera features, I had only ever seen it in plain or Handlebars contexts.

But yes, sort of. If I was building my own Rust application it looks like that would enable me to get the job done. I guess this feature request takes on two smaller parts:

  1. Surface this ability from the Tera side, probably via a feature flag, such that an easy interface to that comes as a ready made set of functions rather than needing to bolt it on from the Rust side yourself.
  2. Enable said feature in Zola's import of Tera by default, hence exposing the functions to static site generators.

As it stands if there is a way to bolt this on to my site without needing to distribute a forked Zola to enable this I don't see what it is.

alerque avatar Jun 30 '21 10:06 alerque

It's planned to add that crate (or something else if needed) to Zola but this shouldn't be added to Tera itself imo. It got a bit delayed in Zola but it should come during the summer, in the release after the next one. Is fluent_templates good enough or are there issues with it that you're aware of?

Keats avatar Jul 01 '21 08:07 Keats

The project I did using fluent_templates was quite nice to work with. The context was was pretty different but the crate is a good one. Provided that

  • The lang parameter gets passed automatically from the web context to the tera function,
  • Resource files get loaded automatically from appropriate sources based on the lang, and
  • Other context variables can be passed easily (or maybe just all of them automatically?)

...I would say that covers what I'm aware of. And sounds promising. I'll be looking forward to it. I don't know if I'll have time to contribute towards the effort but I'll try.

alerque avatar Jul 01 '21 18:07 alerque

Any progress on this? I'm revisiting two sites I wanted to port to Zola, and this is a blocker...

alerque avatar Jun 24 '22 20:06 alerque

None right now, got a bit side-tracked.

Keats avatar Jun 26 '22 19:06 Keats

Roger that, fair enough, it happens. And knowing that help my planning...

alerque avatar Jun 27 '22 09:06 alerque