globalizejs / globalizejs/globalize
Unit formatting megabyte in Polish short form failed because cldr-data@36.0.1 has inconsistent data
- Dominant language
- JavaScript
- Stars
- 4.8k
- Forks
- 585
- PR merge metrics
- No merged PRs in 30d
Description
Following packages are installed (latest as of now):
- `cldr-data@36.0.1`
- `globalize@1.7.0`
- `iana-tz-data@2019.1.0`
When using the following code to format megabytes in short form in Polish, it failed:
```js
var Globalize = require('globalize');
Globalize.load(require('cldr-data').entireSupplemental());
Globalize.load(require('cldr-data').entireMainFor('pl'));
Globalize.loadTimeZone(require('iana-tz-data'));
console.log(Globalize('pl').unitFormatter('megabyte', { form: 'short' })(1));
```
The error is:
```
/home/johndoe/repos/experiment-globalize/node_modules/globalize/dist/globalize.js:73
message = message.replace( /{[0-9a-zA-Z-_. ]+}/g, function( name ) {
^
TypeError: Cannot read properties of undefined (reading 'replace')
at formatMessage (/home/johndoe/repos/experiment-globalize/node_modules/globalize/dist/globalize.js:73:20)
at unitFormat (/home/johndoe/repos/experiment-globalize/node_modules/globalize/dist/globalize/unit.js:90:9)
at unitFormatter (/home/johndoe/repos/experiment-globalize/node_modules/globalize/dist/globalize/unit.js:101:10)
at Object. (/home/johndoe/repos/experiment-globalize/src/index.js:7:73)
at Module._compile (node:internal/modules/cjs/loader:1126:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
at Module.load (node:internal/modules/cjs/loader:1004:32)
at Function.Module._load (node:internal/modules/cjs/loader:839:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
```
This is because the data in `cldr-data@36.0.1` is inconsistent. Under `node_modules/cldr-data/main/pl/units.json`, the `short.digital-megabyte` only contains strings for plural form of "other". It is lacking strings for "one", "few" and "many".
Excerpt from `pl/units.json` showing the short form of `digital-megabyte` only has string for "other" plural form:
```json
"digital-megabyte": {
"displayName": "MB",
"unitPattern-count-other": "{0} MB"
},
```
Excerpt from `supplemental/plurals.json` showing Polish has 4 plural forms of "one", "few", "many" and "other":
```json
"pl": {
"pluralRule-count-one": "i = 1 and v = 0 @integer 1",
"pluralRule-count-few": "v = 0 and i % 10 = 2..4 and i % 100 != 12..14 @integer 2~4, 22~24, 32~34, 42~44, 52~54, 62, 102, 1002, …",
"pluralRule-count-many": "v = 0 and i != 1 and i % 10 = 0..1 or v = 0 and i % 10 = 5..9 or v = 0 and i % 100 = 12..14 @integer 0, 5~19, 100, 1000, 10000, 100000, 1000000, …",
"pluralRule-count-other": " @decimal 0.0~1.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …"
},
```
However, when formatting `1.1`, it can format it into `"1,1 MB"`. When formatting `1` into long form, it can format it into `"1 megabajt"`.
Contributor guide
Assessment
This issue has not been assessed yet.