Giter Club home page Giter Club logo

Comments (7)

zbraniecki avatar zbraniecki commented on May 13, 2024

Ehh, this ends up being a very non trivial task.

I spent way too much time today on #rust trying to understand the limitations. It boils down to - it's not easy/possible to have a single cache for different types. If all our formatters had the same set of methods, we could do this with impl Trait and trait object.
But in the world where we have PluralRules.select and DateTimeFormat.format, it's very hard.

It is possible to use an enum here, in a closed model which will not allow third-party devs to add their own formatters (or at least, they wont be cached).

Unfortunately, that requires us to change the mutability of ctx and env in resolver, because now any call can trigger adding an object to cache, so you have to pass mut env all around.

@stasm - would you be interested in taking a look at this? Maybe you'll come up with some better model for this problem, because I feel like I'm out of ideas :(

from fluent-rs.

stasm avatar stasm commented on May 13, 2024

We'll need some kind of mutability for env (via mut or RefCell maybe?) for #21, too. I'll first look into #21 and perhaps it will give us some ideas for this issue.

from fluent-rs.

mmstick avatar mmstick commented on May 13, 2024

What needs to be cached, exactly?

from fluent-rs.

zbraniecki avatar zbraniecki commented on May 13, 2024

nothing yet for we don't have any intl formatters. It's likely going to be delayed till later.

We're about to switch fluent to use https://github.com/unclenachoduh/pluralrules which will be the first intl formatter and it will not require any caching for now.

from fluent-rs.

zbraniecki avatar zbraniecki commented on May 13, 2024

but once we get intl date time formatting and number formatting we'll likely want to cache the instantiated structures.

from fluent-rs.

zbraniecki avatar zbraniecki commented on May 13, 2024

@mmstick with @unclenachoduh landing of the intl-pluralrules crate use, now we have a good candidate.

Every comparison that involves a PLURAL builtin renegotiates locales and regenerates IntlPluralRules instance: https://github.com/projectfluent/fluent-rs/blob/master/fluent/src/types.rs#L60-L67

Instead, we should do what we do in JS: https://github.com/projectfluent/fluent.js/blob/master/fluent/src/context.js#L212-L222

There are subtle differences - JS uses an Options bag, we just pass one argument, JS does language negotiation inside the constructor, we do it externally, but it boils down to the same.

We want to do it once, and for the given PluralRulesType cache the instance on the MessageContext.

The trick is that in the perfect world, we'd like to make the mechanism flexible enough to handle some sort of Intl.DateTimeFormat and Intl.NumberFormat equivalents in the future once Rust gets them.
But I guess we can also start with a cache just for PluralRules for now.

Wanna take a stab at it?

from fluent-rs.

zbraniecki avatar zbraniecki commented on May 13, 2024

I was able to fix it trivially for now in 7b0cd65

from fluent-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.