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

Confusing error when trying to create Collator for en-US #3331

Closed
autarch opened this issue Apr 15, 2023 · 2 comments · Fixed by #3334
Closed

Confusing error when trying to create Collator for en-US #3331

autarch opened this issue Apr 15, 2023 · 2 comments · Fixed by #3334

Comments

@autarch
Copy link
Contributor

autarch commented Apr 15, 2023

I'm encountering a surprising error when trying to create a Collator for the en-US locale.

Here's the entire code example:

extern crate alloc;

use icu::{
    collator::{Collator, CollatorOptions},
    locid::Locale,
};

struct UnstableProvider;
include!("./icu-data/mod.rs");
impl_data_provider!(UnstableProvider);

fn main() {
    let locale = Locale::try_from_bytes("en-US".as_bytes()).unwrap();
    let provider = UnstableProvider;
    let opts = CollatorOptions::new();
    Collator::try_new_unstable(&provider, &locale.into(), opts).unwrap();
}

The final unwrap fails with:

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:16:65

The data was generated like this:

$> icu4x-datagen --locales full --format mod --keys all --out ./src/icu-data --overwrite

I've created a test repo for this issue at https://github.com/autarch/datagen-issue

If I use en-US-POSIX I don't get an error. But surely en-US is a valid locale, right?

When I look at the generated data for collation, I see that it has a relatively small number of locale ids in it. It seems like maybe this isn't using the parent locales appropriately. Shouldn't en-US try en and then root?

@sffc
Copy link
Member

sffc commented Apr 15, 2023

Please wrap the UnstableProvider in a LocaleFallbackProvider.

@autarch
Copy link
Contributor Author

autarch commented Apr 15, 2023

Thanks! I'll close this. I would've suggested a doc update but you're already ahead of me.

@autarch autarch closed this as completed Apr 15, 2023
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

Successfully merging a pull request may close this issue.

2 participants