Crate intl_pluralrules

source ·
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::{IntlPluralRules, PluralRuleType, PluralCategory};
use unic_langid::LanguageIdentifier;
use std::convert::TryFrom;

let langid = LanguageIdentifier::try_from("pl").expect("Parsing failed.");

assert!(IntlPluralRules::get_locales(PluralRuleType::CARDINAL).contains(&langid));

let pr = IntlPluralRules::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§

Structs§

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.

Statics§

  • CLDR_VERSION is the version of CLDR extracted from the file used to generate rules.rs.