Crate intl_pluralrules[−][src]
Expand description
A crate for generating plural rule operands from numberical input.
This crate generates plural operands according to the specifications outlined at Unicode’s website.
Input is supported for int, float, and &str.
Examples
Plural rules example for Polish
use intl_pluralrules::{PluralRules, PluralRuleType, PluralCategory};
use unic_langid::LanguageIdentifier;
let langid: LanguageIdentifier = "pl".parse().expect("Parsing failed.");
assert!(PluralRules::get_locales(PluralRuleType::CARDINAL).contains(&langid));
let pr = PluralRules::create(langid.clone(), PluralRuleType::CARDINAL).unwrap();
assert_eq!(pr.select(1), Ok(PluralCategory::ONE));
assert_eq!(pr.select("3"), Ok(PluralCategory::FEW));
assert_eq!(pr.select(12), Ok(PluralCategory::MANY));
assert_eq!(pr.select("5.0"), Ok(PluralCategory::OTHER));
assert_eq!(pr.get_locale(), &langid);
Modules
A public AST module for plural rule representations. Plural operands in compliance with CLDR Plural Rules.
Structs
The main structure for selecting plural rules.
Enums
A public enum for handling the plural category. Each plural category will vary, depending on the language that is being used and whether that language has that plural category.
A public enum for handling plural type.