no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / third_party / rust / intl-memoizer / README.md
blob98e0092861aee389bcc02a7d342d81fdf772f645
1 # IntlMemoizer
3 `intl-memoizer` is a crate designed to handle lazy-initialized references
4 to intl formatters.
6 The assumption is that allocating a new formatter instance is costly, and such
7 instance is read-only during its life time, with constructor being expensive, and
8 `format`/`select` calls being cheap.
10 In result it pays off to use a singleton to manage memoization of all instances of intl
11 APIs such as `PluralRules`, DateTimeFormat` etc. between all `FluentBundle` instances.
13 Usage
14 -----
16 ```rust
17 use intl_memoizer::{IntlMemoizer, Memoizable};
18 use unic_langid::langid;
20 use intl_pluralrules::{PluralRules, PluralRuleType, PluralCategory};
22 impl Memoizable for PluralRules {
23     type Args = (PluralRulesType,);
24     fn construct(lang: LanguageIdentifier, args: Self::Args) -> Self {
25       Self::new(lang, args.0)
26     }
29 fn main() {
30     let lang = langid!("en-US");
32     // A single memoizer for all languages
33     let mut memoizer = IntlMemoizer::new();
35     // A RefCell for a particular language to be used in all `FluentBundle`
36     // instances.
37     let mut en_us_memoizer = memoizer.get_for_lang(lang.clone());
39     // Per-call borrow
40     let mut en_us_memoizer_borrow = en_us_memoizer.borrow_mut();
41     let cb = en_us_memoizer_borrow.get::<PluralRules>((PluralRulesType::Cardinal,));
42     assert_eq!(cb.select(1), PluralCategory::One);
45 ```
47 Get Involved
48 ------------
50 `fluent-rs` is open-source, licensed under the Apache License, Version 2.0.  We
51 encourage everyone to take a look at our code and we'll listen to your
52 feedback.
55 Discuss
56 -------
58 We'd love to hear your thoughts on Project Fluent! Whether you're a localizer
59 looking for a better way to express yourself in your language, or a developer
60 trying to make your app localizable and multilingual, or a hacker looking for
61 a project to contribute to, please do get in touch on the mailing list and the
62 IRC channel.
64  - Discourse: https://discourse.mozilla.org/c/fluent
65  - IRC channel: [irc://irc.mozilla.org/l20n](irc://irc.mozilla.org/l20n)