New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-intl-universal-extract

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-intl-universal-extract

A react-intl-universal message extractor

  • 1.0.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

react-intl-universal-extract

Extract react-intl-universal's default messages in source code to locale files.

image

For example, suppose you have a file:

  render() {
    const name = 'Tony';
    return (<>
      {intl.get('hello1').d('Hello World')}
      {intl.get('hello2', {name} ).d(`Hello ${name}`)}
    </>);
  }  

This tool will generate a json file which contains the extracted messages.

{
  "hello1": "Hello World",
  "hello2": "Hello {name}",
}

Note that if the default message contains variables in ES6 template strings format (Hello ${name}), it will be transformed to ICU format (Hello {name}).

Install

npm install --save-dev react-intl-universal-extract

Usage

CLI

In package.json, add a script:

"scripts": {
  "intl:extract": "npx react-intl-universal-extract --cmd extract --source-path ./src --output-path ./src/locales/en_US.json --verbose",
}

Then run npm run intl:extract.

Parameters:

  • cmd: only "extract" is supported currently.
  • source-path: The source code directory path such as "./src"
  • output-path: The extracted json file path such as "./src/locales/en_US.json"

Programmable

const intlTool = require('react-intl-universal-extract');
const result = intlTool.extract({
  sourcePath: './test-files',
});
console.log(result); 
/** result:
[{
  key: 'hello2',
  path: 'test-files/App.js',
  originalDefaultMessage: 'Hello ${name}',
  transformedDefaultMessage: 'Hello {name}'
}]
*/

License

This software is free to use under the BSD license.

Contributing

See "develop.md"

Keywords

FAQs

Package last updated on 10 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc