npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rollup-plugin-messageformat

v3.0.0

Published

Rollup plugin for MessageFormat

Downloads

279

Readme

Rollup Plugin for MessageFormat

Plugin for Rollup that lets you import JSON, YAML & .properties files containing ICU MessageFormat messages, turning them into message functions to use e.g. with @messageformat/react.

Installation

npm install --save-dev rollup-plugin-messageformat

If you're intending to publish a library with external dependencies, you should also include the runtime as a dependency:

npm install @messageformat/runtime

Usage

With this config:

// rollup.config.js
import { messageformat } from 'rollup-plugin-messageformat'

export default {
  entry: 'src/app.js',
  external: /^@messageformat\/runtime\b/,
  output: { format: 'es' },
  plugins: [messageformat({ locales: ['en', 'fr'] })]
}

And these source files:

# messages/fr.yaml
message_intro: |
  {count, plural,
    one {Votre message se trouve ici.}
    other {Vos # messages se trouvent ici.}
  }
// src/app.js
import fr from '../messages/fr.yaml'

fr.message_intro({ count: 3 })
// 'Vos 3 messages se trouvent ici.'

You'll get this output:

import { plural, number } from '@messageformat/runtime';
import { fr as fr$1 } from '@messageformat/runtime/lib/cardinals';

var fr = {
  message_intro: (d) => plural(d.count, 0, fr$1, {
    one: "Votre message se trouve ici.",
    other: "Vos " + number("fr", d.count, 0) + " messages se trouvent ici."
  }) + "\\n"
};

fr.message_intro({ count: 3 });
// 'Vos 3 messages se trouvent ici.'

Options

In addition to the options accepted by @messageformat/core, the plugin supports the following. All are optional.

| Option | Type | Default | Description | | ------------- | --------------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------- | | exclude | FilterPattern | | Files to exclude. A valid minimatch pattern, or an array of such patterns. | | include | FilterPattern | (see below) | Files to include. A valid minimatch pattern, or an array of such patterns. | | locales | string[] | ['en'] | Define the message locale or locales using CLDR language codes. If given multiple valid locales, the first will be the default. | | propKeyPath | boolean | true | Parse dots . in .properties file keys as path separators, resulting in a multi-level message object. |

include

By default, includes all .properties files and .json, .yaml & .yml files that include messages before the extension. If locales are defined, also matches messages[./_-]lc.ext where lc is the locale and ext one of the above extensions.

Examples of default matches: foo.properties, messages.json, bar-messages.yaml, messages/en.json (if the en locale is explicitly set)

locales

As MessageFormat is often used to provide multi-language support, it's important to include all of your supported locales in the locales value. For example, using locales: ['en', 'fr'] would allow for imports from foo.en.properties and foo.fr.properties to have their messages' locale set correctly, based on the file name. Using a locale identifier as a key within the message file contents will also select that locale within it.

If locales has the special value '*', it will match all available locales. This may be useful if you want your messages to be completely determined by your data, but may provide surprising results if your input message object includes any 2-3 character keys that are not locale identifiers.


Messageformat is an OpenJS Foundation project, and we follow its Code of Conduct.