-
Notifications
You must be signed in to change notification settings - Fork 176
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
Design a cohesive solution for supported locales #58
Comments
Putting this on the Version 1 backlog. We still need help on this. |
Here's my current thinking. There are three levels of locale support in a data provider:
A particular provider must store metadata listing the resolved locales, which increases the complexity. I don't see a way around this. In the fs provider, the list is stored in the manifest.json file, and in the blob provider, it is stored alongside the big zeromap. The list is could be exposed through the following trait: pub trait SupportedLocales {
/// Returns resolved locales or MissingResourceKey if the key is not supported
fn supported_locales_for_key(&self, key: ResourceKey) -> Result<Vec<ResourceOptions>, DataError>;
} In ForkByKeyProvider, the implementation works the same as To answer the ECMA-402 question "what are the supported locales for NumberFormat", you use this API with the key Another mode that aligns closer to ECMA-402 is pub trait SupportedLocales {
/// Returns the subset of locales that are fallbackable locales.
fn supported_locales_of(&self, key: ResourceKey, locales: Vec<ResourceOptions>) -> Result<Vec<ResourceOptions>, DataError>;
} ForkByKeyProvider would again look for the first provider that supports the key, and then return its result. An issue here is that vertical fallback would need to be invoked. Therefore, rather than having this API, it may be better and cheaper to just run the full vertical fallback stack, but stop short of deserializing/downcasting. |
I propose considering what I proposed above as the course of action, and removing this from the 1.0 critical path. |
I've been implementing the From what I could see while implementing the locale resolution algorithms defined in the ECMA402 spec, what the API seems to try to accomplish is to determine if a specific locale will return "correct" results if used as the locale of a specific service. Everything else is just taking that and extending it to several different APIs that filter/choose/tune a list of user-provided locales to ensure that all locales passed to the services are always "valid" in a sense. Maybe this means that the providers don't explicitly need a |
Collator is special in the sense that in the absence of natural-language output,
(In Safari, the array is prepended with Boa currently logs the whole input array, because of " It's not clear to me how "Resolved Locales" above should capture the "root is known to be valid" concept. As I understand it, we don't currently store this information. To the extent the provider infrastructure supports aliases, I guess one possibility would be list |
We're landing |
Move this issue to needs-approval to discuss above point. |
Making clients poke into the internals and pick a key with DryDataProvider and be surprised by the results and break when we change things is just not a great solution. This is an ECMA-402 thing, so we should make an API (however minimal) for it. ECMA-402 only requires I posted my solution in #5504. DryDataProvider solves the problem, but only if it has retain-base-languages behavior. We rejected retain-base-languages for default compiled data in #5195 and I stand strongly by that. However, we should still be able to implement this function in |
My preferred fix is to make it such that |
If we cannot agree to an in-library solution, then:
|
If we can't agree on an in-library solution, we need to figure out a userland solution that doesn't involve duplicating data. A few approaches we could take:
|
I implemented a sketch of how option 3 could work in #5506. Another option is that we could use something similar to #5506 but just record the locales that were exported in the data exporter. This was suggested earlier in the thread. The downside is that it gives you the locales for the exporter overall, not the locales for a specific key, so it might not work for |
Some solutions:
Discussion:
Proposal:
LGTM: @sffc @robertbastian |
What's left to do is to activate |
I very often see clients who want to use ICU as a default behavior, but fall back to custom logic if ICU does not support a given locale.
The main problem, of course, is that the locale fallback chain is an essential piece of whether or not a locale is supported. If you have locale data for "en" and "en_001", but request "en_US" or "en_GB", the answer is that both of those locales are supported, even though they both load their data from a fallback locale.
I'm not 100% confident, but I think the prevailing use case is that programmers want to know whether the locale falls back all the way to root. If it gets "caught" by an intermediate language, then that's fine, as long as we don't use the stub data in root.
ECMA-402 has the concept of supportedLocalesOf. Although it's not clear in the MDN, it appears that this method has the ability to check for locale fallbacks. This is better than ICU4C's behavior of getAvailableLocales, which returns a string list and requires the user to figure out how to do fallbacks and matching on that list.
We could consider whether this use case fits in with the data provider, or whether we want to put it on APIs directly.
The text was updated successfully, but these errors were encountered: