Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusion of using in a multi-locale environment #64

Closed
renyuneyun opened this issue Aug 17, 2018 · 8 comments
Closed

Confusion of using in a multi-locale environment #64

renyuneyun opened this issue Aug 17, 2018 · 8 comments

Comments

@renyuneyun
Copy link

I guess the goal of fluent-rs is to provide a full functioning i18n system with fluent syntax, so the environment of multi-locale will be encountered.

The signature of MessageContext::new() takes a slice of strings as the parameter, which is said to

represents the best possible fallback chain for a given locale

However, in the next section:

MessageContext stores messages in a single locale, but keeps a locale fallback chain for the purpose of language negotiation with i18n formatters.

The design seems to be conflicting with itself - if MessageContext only stores value of one locale, how does it do locale fallback?

This leads to quite a confusion for me, and I don't really know how to use fluent-rs in a multi-locale environment where fallback is really needed.

@zbraniecki
Copy link
Collaborator

This leads to quite a confusion for me, and I don't really know how to use fluent-rs in a multi-locale environment where fallback is really needed.

Great point! Sorry for the confusion.

The reason we take a list of locales is to allow for Intl formatters that are (or, in case of Rust, will be) used by the context to fallback as well as possible between locales.

But fluent-rs as of today does not provide a higher level API to fallback between locales yet. In JS we have fluent-dom and fluent-react packages which both implement a higher level API which uses asynchronous iterators to lazily fallback between locales.

See, for example the Localization class in fluent-dom: https://github.com/projectfluent/fluent.js/blob/master/fluent-dom/src/localization.js#L12

In Rust, we will want to implement a similar logic using some cached-iterator strategy. What I'm currently waiting for with this is to stabilize fluent-rs a bit (which I hope to do quite soon around Fluent 0.7), and for async/await to land in Rust.

Hope that helps! I'll keep the issue open to improve documentation around it.

@zbraniecki zbraniecki added this to the 0.6 milestone Feb 1, 2019
@zbraniecki
Copy link
Collaborator

I'm starting to look into the learning curve of fluent-rs and this is my top priority. I'm considering introducing a simple resource manager (#88) which would give you an example of how you can bootstrap your project and use the locale fallbacking and locale changes. I'll ask for feedback once I have more concrete PR.

@kazimuth
Copy link
Contributor

kazimuth commented Mar 9, 2019

See the work I've been doing in djc/askama #211 for one use case. There I'm taking the slightly-odd approach of baking localization files into the output executable, since it's a web framework designed to deploy to a static binary anyway.

Having support for fallback chains for missing messages would be amazing. I was thinking about implementing it myself but if it's being worked on here than I can just wait for that.

@zbraniecki
Copy link
Collaborator

@renyuneyun, @kazimuth - can you both evaluate current examples in fluent-bundle, fluent-fallback and fluent-resmgr? They all use fallback mechanisms based on fluent-locale and esp fluent-fallback should be a good example of how in Fluent world you can deploy a localization with fallback mechanism.

It's still super early (I'll release those higher level crates as 0.1), but should be good enough to start collecting feedback.

@kazimuth
Copy link
Contributor

kazimuth commented May 5, 2019

I ended up rolling my own implementation of fluent-resmgr + fluent-fallback, here. The main difference is that I build all the bundles i'm going to need once, in a lazy_static, and then iterate over them during lookup, instead of dynamically building them during lookup. This makes sense in a web server context -- we want to do as much work as we can at startup, to reduce latency during request processing.

@renyuneyun
Copy link
Author

renyuneyun commented May 15, 2019

@zbraniecki Thanks a lot. It seems the crate is missing from crate.io , at least for fluent-resmgr.

Anyway I copied the source code to test.
It is not Sync for the moment, so I didn't really make it work...

For fluent-fallback, the document is not clear how to use it. Briefly looking at the code makes me more confused. Isn't it meant to be used in conjunction with fluent-resmgr?

@zbraniecki
Copy link
Collaborator

@renyuneyun @kazimuth - I just merged a change #114 which hopefully will make it much easier to work with FluentBundle.

You can now just push the FluentResource to it, or pass a reference/Rc/Arc and handle resource caching yourself.

I'll release fluent-fallback with 0.7 to handle language fallbacking.

@zbraniecki
Copy link
Collaborator

I just released 0.7. It can handle any Borrow<FluentResource> which allows you to simply store resources in the bundle, or references, or use Rc/Arc.

I also released fluent-resmgr which can facilitate storing resources for your bundles with just references (so, avoids Rc).

On top of that, I released initial version of fluent-fallback which facilitates language fallbacking allowing for convenient loading of fallback languages.

This should fix this bug! Reopen if needed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants