-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
x/text/number: provide way to query number system #53872
Comments
cc @mpvl as per https://dev.golang.org/owners |
There is some overlap here with #19787 (decimal in language) and #30870 (decimal in database/sql). Probably we're not ready to move forward on either of those. The reason it's internal in x/text is to make sure any eventual public API is consistent with the general approach. Putting on hold for the others (it will be a while). |
Placed on hold. |
'm not sure there's much overlap? I've edited the proposal down. It's about l11n, not Go's language support for numbers. Hopefully this can go back into Incoming |
@rsc requesting this goes back into Incoming for next proposals review |
Is the proposed API:
Is String really the only necessary method on number.System? language.Region has many, and language.Script has at least one other than String. ? /cc @mpvl |
This proposal has been added to the active column of the proposals project |
Yes - for now, but not forever There are methods implemented at /x/text/internal/number, in particular Digit, IsDecimal, Symbol. I'd like to see them, but perhaps at a later date - I don't want to block this deciding if they are ready to be exported. Although happy if that discussion happens. Those methods are quite easy to extract from a single Unicode data file, whereas String() is difficult to duplicate (many data files, in a hierarchy, plus needing to re-implement Go locale parsing) |
Any thoughts about this API, @mpvl? |
Does anyone object to this proposal? #53872 (comment) |
No change in consensus, so accepted. 🎉 |
Change https://go.dev/cl/465735 mentions this issue: |
CC @thanm for /x/text reviews |
Friendly bump to see if we can get reviewers on this. CC @thanm |
(edited to reduce scope)
/x/text/language
lets you query Region and Script:func (t Tag) Region() (Region, Confidence)
func (t Tag) Script() (Script, Confidence)
There should also be a way to query the Number System that Go has matched for the locale. Currently, this can be done with the Extensions method on a
language.Tag
but only if the number system has been specified explicitly in the locale string. Otherwise, there is no easy way to know what the default Number System chosen is.This is probably best implemented by
golang.org/x/text/number
exporting a function called "SystemFromTag". This should return a number.System, which should support the stringer interface.This is already done in
/x/text/internal/number
(InfoFromTag), and would be a trivial wrapper.In future, a
number.System
could export other useful information that the internalnumber.InfoFromTag
exposes, but this is not necessary for now.Use case
This would let client code match the number system selected for a locale by /x/text, and if it needs any more information, look it up in the Unicode CLDR data files, which is a simple file at
supplemental/numberingsystems.xml
.Without this, there's the much more involved process of reimplementing parsing the locale string, and re-implementing the mapping of a locale to its default number system, including the hierarchy of parent locales.
Example Usage
Example implementation
/x/text/number should change as follows:
Open questions
The documentation for Region.String says it returns "ZZ" for an unspecified region. Script.String returns "Zzzz" for an unspecified script. Would SystemFromTag ever fail to return a numbering system? Could it in the future? If so, what should that system's string representation be? Probably just the default, with an appropriate "No" confidence value?
/x/text/number currently doesn't support number system categories at all - e.g. "tamil-u-nu-native", "tamil-u-nu-traditio" or "zh-u-nu-finance" - only explicit matches e.g. "tamil-u-nu-tamldec". Should this be implemented first? It would probably impact the returned Confidence value. (See x/text/number: understands specific BCP-47 u-nu-extensions, but not general categories #54090)
References
The text was updated successfully, but these errors were encountered: