Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AuxiliaryKey to DataLocale #3872

Merged
merged 27 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3d36855
Initial auxiliary key APIs
sffc Aug 15, 2023
59aa0b4
Start writing impl FromStr for DataLocale
sffc Aug 15, 2023
6cb45f6
Make comparison operations work
sffc Aug 16, 2023
06e453c
Change custom error type to DataError::KeyLocaleSyntax
sffc Aug 16, 2023
d0e30e2
Docs, tests, cleanup
sffc Aug 16, 2023
54101ad
Forbid the empty string in AuxiliaryKey
sffc Aug 16, 2023
f36b405
Use auxiliary keys in HelloWorldProvider
sffc Aug 16, 2023
52ab723
Add DataLocale::is_und; gen hello world testdata
sffc Aug 16, 2023
3493b75
Use is_und instead of is_empty more consistently in fallback iterator
sffc Aug 16, 2023
93f0969
Handle $ in baked_exporter
sffc Aug 16, 2023
241b563
Pull the separator character into a function where possible.
sffc Aug 16, 2023
cd0d86c
Fix baked_exporter.rs
sffc Aug 17, 2023
5551d6b
fmt and refactor
sffc Aug 17, 2023
33fad72
Merge branch 'main' into auxkey
sffc Aug 17, 2023
f8e310e
is_und in driver.rs (post merge cleanup)
sffc Aug 17, 2023
dbefbf9
More more is_und
sffc Aug 17, 2023
f31643a
Use `+` for aux key
sffc Aug 17, 2023
71c1087
Support multipart auxiliary keys
sffc Aug 17, 2023
cda1498
Fix build post merge
sffc Aug 17, 2023
3b14fbd
Add 3-way enum (not using Stack variant yet)
sffc Aug 17, 2023
3d83b95
Add impls based on Deref
sffc Aug 17, 2023
04ee1df
Remove Default impl
sffc Aug 17, 2023
45778ce
Use the TinyStr variant
sffc Aug 17, 2023
1e52541
Update sizes (probably need to fix nightly sizes too)
sffc Aug 17, 2023
905e697
gn-gen
sffc Aug 17, 2023
7f84837
Update request.rs
sffc Aug 18, 2023
5a31f2f
fmt
sffc Aug 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion provider/adapters/src/fallback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl<P> LocaleFallbackProvider<P> {
});
}
// If we just checked und, break out of the loop.
if fallback_iterator.get().is_empty() {
if fallback_iterator.get().is_und() {
break;
}
fallback_iterator.step();
Expand Down
Binary file modified provider/adapters/tests/data/blob.postcard
Binary file not shown.
Binary file modified provider/blob/tests/data/hello_world.postcard
Binary file not shown.
4 changes: 4 additions & 0 deletions provider/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ pub enum DataErrorKind {
#[displaydoc("Invalid state")]
InvalidState,

/// The syntax of the [`DataKey`] or [`DataLocale`] was invalid.
#[displaydoc("Parse error for data key or data locale")]
KeyLocaleSyntax,

/// An unspecified error occurred, such as a Serde error.
///
/// Check debug logs for potentially more information.
Expand Down
29 changes: 24 additions & 5 deletions provider/core/src/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@ impl KeyedDataMarker for HelloWorldV1Marker {
///
/// assert_eq!("Hallo Welt", german_hello_world.get().message);
/// ```
///
/// Load the reverse string using an auxiliary key:
///
/// ```
/// use icu_provider::hello_world::*;
/// use icu_provider::prelude::*;
///
/// let reverse_hello_world: DataPayload<HelloWorldV1Marker> =
/// HelloWorldProvider
/// .load(DataRequest {
/// locale: &"en$reverse".parse().unwrap(),
/// metadata: Default::default(),
/// })
/// .expect("Loading should succeed")
/// .take_payload()
/// .expect("Data should be present");
///
/// assert_eq!("Olleh Dlrow", reverse_hello_world.get().message);
/// ```
#[derive(Debug, PartialEq, Default)]
pub struct HelloWorldProvider;

Expand All @@ -88,11 +107,13 @@ impl HelloWorldProvider {
("de", "Hallo Welt"),
("el", "Καλημέρα κόσμε"),
("en", "Hello World"),
("en$reverse", "Olleh Dlrow"),
("eo", "Saluton, Mondo"),
("fa", "سلام دنیا‎"),
("fi", "hei maailma"),
("is", "Halló, heimur"),
("ja", "こんにちは世界"),
("ja$reverse", "界世はちにんこ"),
("la", "Ave, munde"),
("pt", "Olá, mundo"),
("ro", "Salut, lume"),
Expand Down Expand Up @@ -190,11 +211,7 @@ impl BufferProvider for HelloWorldJsonProvider {
impl icu_provider::datagen::IterableDataProvider<HelloWorldV1Marker> for HelloWorldProvider {
fn supported_locales(&self) -> Result<Vec<DataLocale>, DataError> {
#[allow(clippy::unwrap_used)] // datagen
Ok(Self::DATA
.iter()
.map(|(s, _)| s.parse::<icu_locid::LanguageIdentifier>().unwrap())
.map(DataLocale::from)
.collect())
Ok(Self::DATA.iter().map(|(s, _)| s.parse().unwrap()).collect())
}
}

Expand Down Expand Up @@ -309,11 +326,13 @@ fn test_iter() {
locale!("de").into(),
locale!("el").into(),
locale!("en").into(),
"en$reverse".parse().unwrap(),
locale!("eo").into(),
locale!("fa").into(),
locale!("fi").into(),
locale!("is").into(),
locale!("ja").into(),
"ja$reverse".parse().unwrap(),
locale!("la").into(),
locale!("pt").into(),
locale!("ro").into(),
Expand Down
3 changes: 3 additions & 0 deletions provider/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ pub use crate::key::DataKey;
pub use crate::key::DataKeyHash;
pub use crate::key::DataKeyMetadata;
pub use crate::key::DataKeyPath;
pub use crate::request::AuxiliaryKey;
pub use crate::request::DataLocale;
pub use crate::request::DataRequest;
pub use crate::request::DataRequestMetadata;
Expand Down Expand Up @@ -206,6 +207,8 @@ pub mod prelude {
#[doc(no_inline)]
pub use crate::AsDynamicDataProviderAnyMarkerWrap;
#[doc(no_inline)]
pub use crate::AuxiliaryKey;
#[doc(no_inline)]
pub use crate::BufferMarker;
#[doc(no_inline)]
pub use crate::BufferProvider;
Expand Down
Loading