cibernox / svelte-intl-precompile

I18n library for Svelte.js that analyzes your keys at build time for max performance and minimal footprint
https://svelte-intl-precompile.com
ISC License
274 stars 13 forks source link

Support number skeleton #45

Closed icalvin102 closed 2 years ago

icalvin102 commented 2 years ago

I'm currently migrating one of my projects from svelte-i18n to svelte-intl-precompile and got the following error.

foo/locales/de-DE.json: Property value expected type of string but got object
TypeError: foo/locales/de-DE.json: Property value expected type of string but got object
    at Object.validate (foo/node_modules/@babel/types/lib/definitions/utils.js:159:13)
    at validateField (foo/node_modules/@babel/types/lib/validators/validate.js:24:9)
    at validate (foo/node_modules/@babel/types/lib/validators/validate.js:17:3)
    at String.builder (foo/node_modules/@babel/types/lib/builders/builder.js:39:27)
    at Object.stringLiteral (foo/node_modules/@babel/types/lib/builders/generated/index.js:357:27)
    at buildCallExpression (foo/node_modules/babel-plugin-precompile-intl/src/index.js:52:42)
    at buildTemplateLiteral (foo/node_modules/babel-plugin-precompile-intl/src/index.js:110:30)
    at buildFunction (foo/node_modules/babel-plugin-precompile-intl/src/index.js:160:67)
    at PluginPass.ObjectProperty (foo/node_modules/babel-plugin-precompile-intl/src/index.js:202:26)
    at newFn (foo/node_modules/@babel/traverse/lib/visitors.js:177:21)

After some digging I found out that the use of number skeletons (e.g Account balance {balance, number, ::currency/EUR}) is causing this error.

IMO the number skeletons are a very important part of the ICU Message Format and it would be nice if they where supported by svelte-intl-precompile

cibernox commented 2 years ago

Agreed. I must have missed that one as it's one I haven't used myself. I'm going to check https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html and see if I can get an initial implementation by the end of the week. When I do I'll ping you so you can test if works as you expect

cibernox commented 2 years ago

Work on the compiler is done in https://github.com/cibernox/babel-plugin-precompile-intl/pull/18

Tomorrow I'll implement the runtime part.

cibernox commented 2 years ago

I released 0.10.0-beta.0 with some initial support. Try it out and let me know if anything is not working as you expect.

cibernox commented 2 years ago

I released 0.10.0-beta.2 that has better support. Notably it supports scale, which is transformed in build time to division like number / 100. At this point i think the feature is pretty usable. I added documentation in https://svelte-intl-precompile.com/en/docs/icu-crash-course

If you don't find any problem I might release a non-beta version this week

cibernox commented 2 years ago

Closing since this has been released in 0.10