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

@digidem/extract-react-intl-messages

v2.0.2

Published

Extract react-intl messages

Downloads

10

Readme

extract-react-intl-messages

Build Status tested with jest styled with prettier MIT License All Contributors

This is forked from extract-react-intl-messages. It removes un-used options (custom delimiter, exporting nested files, and yaml export), and adds an option to export messages in the same format that Chrome Apps use. We use this because the translation service we use, crowdin.com, accepts this format of file, and will include the description as context for the translator.

This package will generate json from a glob. It will generate one file per locale, with the ids of each message defined by the defineMessages function of react-intl. The value of each of these keys will be an empty string, or an object with the property message an empty string, except for your defaultLocale which will be populated with the defaultMessage.

Dependencies

Babel

  • 2.x works with Babel 7
  • 1.x works with Babel 7
  • 0.x works with Babel 6

Install

$ npm install --save-dev @digidem/extract-react-intl-messages

Usage

app/components/App/messages.js

import { defineMessages } from 'react-intl'

export default defineMessages({
  hello: {
    id: 'a.hello',
    defaultMessage: 'hello'
  },
  world: {
    id: 'a.world',
    defaultMessage: 'world'
  }
})

Run Script

$ extract-messages -l=en,ja -o app/translations -d en 'app/**/!(*.test).js'

Output

app/translations/en.json

{
  "a.hello": "hello",
  "a.world": "world",
  "b.hello": "hello",
  "b.world": "world"
  }
}

app/translations/ja.json

{
  "a.hello": "",
  "a.world": "",
  "b.hello": "",
  "b.world": ""
  }
}

Recommend

Use with babel-plugin-react-intl-auto: i18n for the component age. Auto management react-intl ID.

CLI

$ extract-messages --help

  Extract react-intl messages

  Usage
  $ extract-react-intl-messages <input>
  $ extract-messages <input>

  Options
  -o, --output       Output directory [require: true]
  -l, --locales      locales [require: true]
  --descriptions     include descriptions in output [default: false]
  --default-locale   default locale [default: en]
  --module-name      module source name from where components are imported [default: react-intl]

  Example
  $ extract-messages --locales=ja,en --output app/translations 'app/**/*.js'
  $ extract-messages -l=ja,en -o i18n 'src/**/*.js'

create-react-app user

create .babelrc like this.

{
  "presets": ["react-app"]
}

Run with NODE_ENV=development.

$ NODE_ENV=development extract-messages ...

API

extractReactIntlMessages(locales, input, buildDir, [options])

locales

Type: Array<string>

Example: ['en', 'ja']

input

Type: Array<string>

Target files. glob.

buildDir

Type: string

Export directory.

options

defaultLocale

Type: string Default: en

moduleName

Type: string Default: react-intl

Set from where defineMessages, <FormatterMessage /> and <FormattedHTML /> are imported.

descriptions

Type: boolean Default: false

Includes message descriptions in the returned object. Each message id property will be an object with properties message and description instead of a message string e.g.

{
  en: {
    'components/App/hello': {
      message: 'hello',
      description: 'hello message description'
    },
    'components/App/welcome': {
      message: 'welcome to extract-react-intl',
      description: 'welcome message description
    }
  },
  ja: {
    'components/App/hello': {
      message: '',
      description: 'hello message description'
    },
    'components/App/welcome': {
      message: '',
      description: 'welcome message description
    }
  }
}

Contributors

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT © akameco