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

MissingLocale error when creating Collator from BlobDataProvider #3654

Closed
ajtribick opened this issue Jul 9, 2023 · 2 comments
Closed

MissingLocale error when creating Collator from BlobDataProvider #3654

ajtribick opened this issue Jul 9, 2023 · 2 comments

Comments

@ajtribick
Copy link

Running on Ubuntu 23.04:

Cargo.toml

[package]
name = "icu4xtest"
version = "0.1.0"
edition = "2021"

[dependencies]
icu = { version = "1.2.0", features = ["serde"] }
icu_provider_blob = "1.2.0"

main.rs

use icu::collator::{Collator, CollatorOptions};
use icu::locid::locale;
use icu_provider_blob::BlobDataProvider;

static DATA: &[u8] = include_bytes!("loc_data.postcard");

fn main() {
    let locale = locale!("en_GB");

    let provider = BlobDataProvider::try_new_from_static_blob(DATA).unwrap();

    let options = CollatorOptions::new();
    let collator =
        Collator::try_new_with_buffer_provider(&provider, &locale.into(), options).unwrap();
}

icu4x-datagen command:

$ icu4x-datagen --version
icu4-datagen 1.2.5
$ icu4x-datagen --overwrite --keys all --locales full --format blob --out src/loc_data.postcard

Output:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Data(DataError { kind: MissingLocale, key: Some(DataKey{collator/meta@1}), str_context: None, silent: false })', src/main.rs:14:84

The above occurs for all locales I have tried so far. It also occurs if I pass the locale explicitly to icu4x-datagen. As a test, I also tried creating a DateTimeFormatter from the postcard file and this worked successfully, so seems specific to Collator.

@sffc
Copy link
Member

sffc commented Jul 9, 2023

You need to add the locale fallback provider. I have a PR open to add a tutorial for this: #3334

@ajtribick
Copy link
Author

Thanks, that works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants