globalizejs / globalize

A JavaScript library for internationalization and localization that leverages the official Unicode CLDR JSON data
https://globalizejs.com
MIT License
4.8k stars 605 forks source link

unitFormatter throw exception for locale "pl" with cldr-data 35 #934

Closed LilyLi2019 closed 1 year ago

LilyLi2019 commented 1 year ago

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\nodemodules\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.

rxaviers commented 1 year ago

Thank you for filing the issue. Please, is it a dup of #932? I see the new data has additional forms (link) compared to v34 (link). We need to figure out what's missing from the data that the current code considers present but is undefined. We may also want to check updated specs https://www.unicode.org/reports/tr35/tr35-numbers.html so that code updates match specs.

I am open for PR fixing it.

LilyLi2019 commented 1 year ago

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.

rxaviers commented 1 year ago

No problem and thank you