Comments (7)
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.
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.
What needs to be cached, exactly?
from fluent-rs.
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.
but once we get intl date time formatting and number formatting we'll likely want to cache the instantiated structures.
from fluent-rs.
@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.
I was able to fix it trivially for now in 7b0cd65
from fluent-rs.
Related Issues (20)
- ResourceManager::get_bundle and get_bundles is inconsistent and confusing
- ResourceManager ignores and hides errors
- ResourceManager needs to implement BundleGenerator HOT 2
- Parser swallows leading whitespace after indented placeable HOT 2
- Clippy should be run in CI HOT 2
- rustmt should be run in CI
- error[E0277]: `(dyn Any + 'static)` cannot be sent between threads safely HOT 11
- Cannot use built-in functions HOT 2
- Which data providers Fluent crates use? HOT 3
- Make FluentArgs a trait? HOT 1
- Switching windows process/thread ui languages HOT 2
- Provide Way to Avoid Allocating To Collect Formatting Errors HOT 7
- Using or switching to icu4x crates? HOT 4
- Output looks the same, but is different HOT 3
- Behaviour of FluentArgs::set is misleading HOT 1
- Support full precision of all numbers HOT 1
- How to use this in a command line program and properly parse POSIX locales? HOT 1
- [Feature request] Allow serialize all AST types instead of just Resource HOT 7
- Include source position in the AST HOT 5
- Does a 'safe harbor' release of the current HEAD make sense before further changes? HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fluent-rs.