-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add lower-level data API to PluralRules (#575)
* Add lower-level data API to PluralRules * Switch to using PluralRulesV1 * Move code to resolver module; turn into free function
- Loading branch information
1 parent
653c3ec
commit 03be3a1
Showing
3 changed files
with
51 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// This file is part of ICU4X. For terms of use, please see the file | ||
// called LICENSE at the top level of the ICU4X source tree | ||
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). | ||
|
||
use super::PluralRuleStringsV1; | ||
use crate::{PluralRuleType, PluralRulesError}; | ||
use icu_locid::LanguageIdentifier; | ||
use icu_provider::prelude::*; | ||
use std::borrow::Cow; | ||
|
||
pub fn resolve_plural_data<'s, D: DataProvider<'s, PluralRuleStringsV1<'s>> + ?Sized>( | ||
langid: LanguageIdentifier, | ||
data_provider: &D, | ||
type_: PluralRuleType, | ||
) -> Result<Cow<'s, PluralRuleStringsV1<'s>>, PluralRulesError> { | ||
let key = match type_ { | ||
PluralRuleType::Cardinal => super::key::CARDINAL_V1, | ||
PluralRuleType::Ordinal => super::key::ORDINAL_V1, | ||
}; | ||
Ok(data_provider | ||
.load_payload(&DataRequest { | ||
resource_path: ResourcePath { | ||
key, | ||
options: ResourceOptions { | ||
variant: None, | ||
langid: Some(langid), | ||
}, | ||
}, | ||
})? | ||
.payload | ||
.take()?) | ||
} |