phensley / cldr-engine

Internationalization and localization in Typescript with Unicode CLDR, batteries included
https://phensley.github.io/cldr-engine/
Apache License 2.0
48 stars 3 forks source link

Can this library tell me properties like `groupSeparator` and `decimalSeparator` #6

Closed ryall closed 2 years ago

ryall commented 2 years ago

I need them to pass to a currency input, so that I can match the input format to the locale. I've had a look but the data format is quite complex, so though I would ask if/how I would go about retrieving this data for a specific locale?

phensley commented 2 years ago

These properties are not available via the public api, but they are accessible via the Schema which provides a type-safe accessor to all values in the resource pack. This is used by the library internally to fetch the various strings, formats, and number parameters.

Here's a quick sandbox example of fetching the number params for the Latin number system ("latn"). Click "English" or "German" buttons, or enter a language tag, to see the parameters for that locale. The code for accessing the params is between the ===== comments. https://codesandbox.io/s/phensley-cldr-usage-example-forked-03qci

If you aren't using this library in your app you could use this code to extract the separators you need ahead of time and create lightweight mapping of locale -> separators JS/JSON.

ryall commented 2 years ago

Fantastic, thanks so much. Really loving this library so far! Kudos for all the hard work!