Repository: globalizejs/globalize

Issue #932: Unit formatting megabyte in Polish short form failed because cldr-data@36.0.1 has inconsistent data
Created: 2022-09-30T05:39:41Z
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:
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.<anonymous> (/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:
"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":
"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".

Duplicate issue #934: unitFormatter throw exception for locale "pl" with cldr-data 35
Created: 2022-11-03T09:22:34Z
var formatter = Globalize("pl-PL").unitFormatter( 'digital-petabyte', { form: 'long' } );
console.log(formatter( 2 ));
It throws exceptions:
PS C:\LilyLi\VMC\devCode\testCode> node .\test.ts
C:\LilyLi\VMC\devCode\testCode\node_modules\globalize\dist\globalize.js:73
message = message.replace( /{[0-9a-zA-Z-_. ]+}/g, function( name ) {
^
TypeError: Cannot read property 'replace' of undefined
at formatMessage (C:\LilyLi\VMC\devCode\testCode\node_modules\globalize\dist\globalize.js:73:20)
at unitFormat (C:\LilyLi\VMC\devCode\testCode\node_modules\globalize\dist\globalize\unit.js:89:9)
at unitFormatter (C:\LilyLi\VMC\devCode\testCode\node_modules\globalize\dist\globalize\unit.js:100:10)
at Object. (C:\LilyLi\VMC\devCode\testCode\test.ts:143:13)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
Please note:
It works good with cldr-data version 34.
But it failed with above exception with cldr-data version 35, 36.

Closing comment (2022-11-04T01:45:11Z): Thanks @rxaviers  for checking this issue.
Yes, it is a dup of #932. Sorry I did not search existing issue carefully.
I will close this one and track the fix on #932.