1 | use fluent_langneg::{negotiate_languages, NegotiationStrategy}; |
2 | use intl_memoizer::Memoizable; |
3 | use intl_pluralrules::{PluralRuleType, PluralRules as IntlPluralRules}; |
4 | use unic_langid::LanguageIdentifier; |
5 | |
6 | pub struct PluralRules(pub IntlPluralRules); |
7 | |
8 | impl Memoizable for PluralRules { |
9 | type Args = (PluralRuleType,); |
10 | type Error = &'static str; |
11 | fn construct(lang: LanguageIdentifier, args: Self::Args) -> Result<Self, Self::Error> { |
12 | let default_lang: LanguageIdentifier = "en" .parse().unwrap(); |
13 | let pr_lang: LanguageIdentifier = negotiate_languages&LanguageIdentifier( |
14 | &[lang], |
15 | &IntlPluralRules::get_locales(args.0), |
16 | default:Some(&default_lang), |
17 | strategy:NegotiationStrategy::Lookup, |
18 | )[0] |
19 | .clone(); |
20 | Ok(Self(IntlPluralRules::create(langid:pr_lang, prt:args.0)?)) |
21 | } |
22 | } |
23 | |