Skip to content

v3.0.0-beta.1

Pre-release
Pre-release
Compare
Choose a tag to compare
@eemeli eemeli released this 23 Jul 17:54

BREAKING CHANGES

messageformat/compile-module

  • Split compileModule() from compile(). This refactors a core API, separating the compilation of individual messages vs. collections of messages.

  • Output module string directly from compileModule(). Before, compiled modules could be directly used, and included a built-in stringifier. Now, compiled modules are output as the source code of an ES module.

  • Make compileModule() into a separate function. The module compiler now needs to be imported separately when used.

    Before:

    import MessageFormat from 'messageformat'
    const mf = new MessageFormat('en')
    mf.compile(...)

    Now:

    import MessageFormat from 'messageformat'
    import compileModule from 'messageformat/compile-module'
    const mf = new MessageFormat('en')
    compileModule(mf, ...)

messageformat-runtime

  • Move runtime to its package; split stringify-dependencies from it
  • Add runtime dependency on messageformat-runtime
  • Add runtime dependency on make-plural@6. This change introduces import statements into the module output.
  • Merge formatters into runtime. This drops/deprecates the messageformat-formatters package, moving its exports to messageformat-runtime/lib/formatters.
  • Merge messages into runtime. Previously, messages were a part of the core messageformat package. To use them, messageformat needed to be installed as a runtime rather than dev dependency.
  • Stop reusing runtime. This removes the MessageFormat#runtime instance
  • runtime: Refactor, dropping class wrapper. This drops the error-throwing from the non-strict number() variant.

Options

  • Drop MessageFormat#addFormatters(). Use the customFormatters constructor option instead.

  • Drop MessageFormat#setBiDiSupport() & #setStrictNumberSign(). Use the biDiSupport & strictNumberSign constructor options instead.

  • Use the options object to set the default currency. This changes the API

    Before:

    import MessageFormat from 'messageformat'
    const mf = new MessageFormat('en')
    mf.currency = 'EUR'
    const msg = mf.compile('{V, number, currency}')

    Now:

    import MessageFormat from 'messageformat'
    const mf = new MessageFormat('en', { currency: 'EUR' })
    const msg = mf.compile('{V, number, currency}')

Other Breaking Changes

  • Refactor plurals, and a few other things. This drops the second locale arg of MessageFormat#compile(), and removes the default of supporting all locales if initialised with an empty locale. Also, the API for custom plural categorisation functions now expects an array rather than an object of functions.
  • Always format # as number. Previously, non-numeric values used as plural arguments could be referred to using # while keeping their original value. With this change, they now get converted to numbers and then formatted, probably coming out as "NaN" instead.
  • Refactor formatter caching during compilation. This drops MessageFormat.formatters as well as MessageFormat#fmt, which had public visibility but were not explicitly documented as public.
  • Always apply locale-specific checks to plural cases. This removes both the pluralKeyChecks option, as well as the disablePluralKeyChecks() method. To avoid the checks, pass in your own plural category function.

Features

  • Add choice between string & values array output (#242)
  • Add special-casing for common number formatters
  • Add special locale "*" to match all of them
  • Use cardinal-only plurals where appropriate
  • Add static supportedLocalesOf() method
  • Import formatters in runtime
  • Move getFormatter() to compiler.js
  • Publish identifier utils as safe-identifier
  • Refactor compiler output
  • Refactor/clean up compile() internals

Bug Fixes

  • Adjust for formatter API change
  • Support selectordinal with offset
  • runtime: Cache Intl.NumberFormat instances for #