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

extractUnitPatterns returns data for missing locales #23

Closed
slavafomin opened this issue Apr 5, 2015 · 8 comments
Closed

extractUnitPatterns returns data for missing locales #23

slavafomin opened this issue Apr 5, 2015 · 8 comments

Comments

@slavafomin
Copy link

Hello!

Thank you for your module, it works great.

However, it looks like extractUnitPatterns function is always returns some data, even if missing locale is specified, e.g.: extractUnitPatterns('djfhjsdhfkjhsdfkjl). Why this is happening and how do I detect if real data is present for the specified locale?

Thank you!

@papandreou
Copy link
Owner

You're getting the data from the root locale, which all locales inherit from.

require('cldr').localeIds should be a list of locales that have data available. Does that solve your problem? I could also make the extract... functions throw or return nothing (not even the root data) in this case.

@slavafomin
Copy link
Author

I think the best course of action would be to throw exception or just return null value. I'm not sure if every locale from localeIds actually has data (for example not all locales has pluralization function).

@papandreou
Copy link
Owner

I landed a fix for this, but it turned out to be problematic when extracting from the supplemental folder where not every locale has its own file. I might revisit it later.

@papandreou papandreou reopened this Dec 17, 2015
@rotsee
Copy link
Collaborator

rotsee commented Feb 11, 2019

+1 on this.

At least it would be good to have a “strict mode”, where the library does not silently fall back to root. Even if this is only partially implemented (not working on supplemental data extraction), it would be an improvement, imho.

A typical use case is when working on a fallback chain of languages, e.g. ["nn", "no", "nb"] (nn has less than 100 % coverage in CLDR).

Here the English list pattern suddenly pops up out of nowhere...

@papandreou
Copy link
Owner

Hmm, it would be fairly easy to just throw when attempting to extract data for a locale that does not exist in CLDR at all, but I'm not sure how to implement a strict mode like that. Since nn is in there: https://github.com/papandreou/node-cldr/blob/master/3rdparty/cldr/common/main/nn.xml it's hard to tell if the fallback to root is intentional or not.

For example, en.xml does not contain an entry for the America/Coral_Harbour time zone, so that will fall back to the entry in root.xml. Which is probably perfectly fine -- then the exemplar city will be Atikokan in the Englishes.

That being said I don't have a full overview of everything in the CLDR -- it could be that there's some information in there that would help detect when the fallback isn't intentional. Please prove me wrong :)

@papandreou
Copy link
Owner

Implemented the easy one here: #73

@rotsee
Copy link
Collaborator

rotsee commented Feb 18, 2019

For example, en.xml does not contain an entry for the America/Coral_Harbour time zone, so that will fall back to the entry in root.xml. Which is probably perfectly fine -- then the exemplar city will be Atikokan in the Englishes.

I see, reality is more complex than I imagined. As always.
I guess if there was a way to know what fallback level was actually used, the client could use that information for decide whether the fallback was appropriate for their particular situation, but I have no idea how that would work...

@papandreou
Copy link
Owner

I dug around a bit, but CLDR docs are pretty sparse. The closest thing I could find was that some of the incomplete locales, such as nn, are littered with draft="unconfirmed" attributes:

<listPatternPart type="start" draft="unconfirmed">{0}, {1}</listPatternPart>

That doesn't really solve the <listPattern type="or"> problem though, as that is completely absent from the nn locale.

I'm out of ideas, so I'll close this for now. The "easy" fix was released in 5.0.0.

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

3 participants