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

react-intl-po

v2.2.2

Published

Extract POT from react-intl and convert back to json.

Downloads

19,583

Readme

react-intl-po

Extract POT from react-intl and convert back to json.

messages.json → POT → PO → translation.json

Travis Codecov Status npm package npm downloads

Dependency Status devDependency Status peerDependency Status

license prettier

Tutorial

Please take a look at standalone repo based on Create-React-App: https://github.com/evenchange4/react-intl-po-example

Installation

$ yarn add react-intl-po

Requirements and Workflow

RIP Workflow

Usage

There are two sub-commands of react-intl-po or rip:

  1. json2pot: Convert the json files extracted from babel-plugin-react-intl into one .pot file.
  2. po2json: Convert translated .po files back to .json format.

json2pot

$ rip json2pot '_translations/src/**/*.json' \
    -o ./mcs-public.pot

| Arguments | Description | | --------------------------------- | --------------------------------------------------------------------- | | srcPatterns | The pattern of .json files extracted from babel-plugin-react-intl | | -o, --output <path> | The output pathname of .pot file to be translated | | -k, --message-key [key] | [Optional] Translation message key (default key is defaultMessage) | | -c, --message-context [context] | [Optional] Translation message context (defaults to no context) |

po2json

Case 1: Output one file per locale if a directory is set

$ rip po2json './node_modules/mcs-translation/po/mcs-public*.po' \
     -m './_translations/src/**/*.json' \
     -o './translations'

Case 2: Output one merged file if a .json file is set

$ rip po2json './node_modules/mcs-translation/po/mcs-public*.po' \`
     -m './_translations/src/**/*.json' \
     -o './translations.json'

| Arguments | Description | | ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | srcPatterns | The pattern of translated .po files | | -m, --messages-pattern <path> | The pattern of .json files extracted from babel-plugin-react-intl | | -o, --output <path> | The output pathname of a file / directory | | -k, --message-key [key] | [Optional] Translation message key (default key is defaultMessage) | | -c, --message-context [context] | [Optional] Translation message context (defaults to no context) | | -l, --lang-mapper-pattern <pattern> | [Optional] Custom regex to use for lang mapping. PR#122 | | -i, --lang-mapper-pattern-index [index] | [Optional] When specifying a custom lang-mapper-pattern, the index of match to use for the lang mapping. Default is 1, index is ignored if not using a custom lang mapping regex. PR#122 | | --indentation <number\|char> | [Optional] Specify a number of spaces or a set of characters to be used before each entry of the resulting json file. Defaults to null, which means the entries are not prefixed with spaces. | | --sort-by-id | [Optional] If specified, the entries of each language are sorted by id before being output |

Property

Q&A

How to translate the same message into two different meanings?

Option 1 (Recommended):

Set the message-context (-c) to 'id' of message object from babel-plugin-react-intl (there is no context by default).

The advantage of this option over Option 2 (below) is that PO file editors that provide features such as translation suggestions or error-checking often expect the message key to be defaultMessage.

$ rip po2json './node_modules/mcs-translation/po/mcs-public*.po' \
     -m './_translations/src/**/*.json' \
     -o './translations' \
     -c 'id'

$ rip po2json './node_modules/mcs-translation/po/mcs-public*.po' \`
    -m './_translations/src/**/*.json' \
    -o './translations.json' \
    -c 'id'

Example: https://github.com/evenchange4/react-intl-po-example#option

Option 2: [Maybe deprecated next major release]

Set the message-key (-k) to 'id' of message object from babel-plugin-react-intl (default key is 'defaultMessage'). (#41)

$ rip po2json './node_modules/mcs-translation/po/mcs-public*.po' \
     -m './_translations/src/**/*.json' \
     -o './translations' \
     -k 'id'

$ rip po2json './node_modules/mcs-translation/po/mcs-public*.po' \`
    -m './_translations/src/**/*.json' \
    -o './translations.json' \
    -k 'id'

Development

$ yarn install --pure-lockfile

Ramda.js

You can use R.tap() for developing.

R.pipe(
  R.concat(...),
+ R.tap(e => console.log(e)),
  R.mergeAll,
);

Requirements

  • node >= 9.11.1
  • yarn >= 1.5.1

Test

$ yarn run format
$ yarn run eslint
$ yarn run test:watch

NPM Release

Any git tags.

  1. Create a new git tag
  2. Update CHANGELOG.md
$ npm version patch

CONTRIBUTING

  • ⇄ Pull requests and ★ Stars are always welcome.
  • For bugs and feature requests, please create an issue.
  • Pull requests must be accompanied by passing automated tests ($ yarn run test).

CHANGELOG

LICENSE

MIT: http://michaelhsu.mit-license.org