Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-extract-format-message

Package Overview
Dependencies
Maintainers
4
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-extract-format-message

Generate a message id from the default message pattern

  • 6.2.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created
Source

babel-plugin-extract-format-message

Extract messages from formatMessage calls

npm Version JS Standard Style MIT License

Installation

$ npm install babel-plugin-extract-format-message

Usage

.babelrc

{
  "plugins": [ "extract-format-message", {
    "generateId": "underscored_crc32",
    "outFile": "locales/en.json"
  } ]
}

Via CLI

$ babel --plugins extract-format-message script.js

Via Node API

require("babel-core").transform("code", {
  plugins: [
    [ "extract-format-message", {
      "generateId": "underscored_crc32",
      "outFile": "locales/en-US/messages.yml",
      "locale": "en-US"
    } ]
  ]
})

Options

  • generateId is either a function string -> string, or one of "literal", "normalized", "underscored", "underscored_crc32". Defaults to "underscored_crc32"
  • outFile is a path (relative to cwd) to the output file containing extracted messages. Defaults to stdout.
  • format is a string specifying the target file format. By default the format is inferred from the file extension of outFile.
  • locale is the BCP 47 Language Tag string specifying the language of the default messages. This is only used in the yaml format, to match the Rails conventions. Defaults to "en".

Formats

json

The structure of the file matches the conventions of Chrome's i18n tools. This is also the default format used if an unrecognized format is specified.

Note that format-message apis expecting all of the translations requires a higher level object with locale keys. The value for each locale matches this format.

{
  "hello_67b127a": {
    "message": "Hello!",
    "description": "Greeting shown on the home page."
  }
}
js

Aliases: javascript, commonjs, node

Uses the same structure as json, but uses Node.js's module.exports idiom to export the messages.

module.exports = {
  "hello_67b127a": {
    "message": "Hello!",
    "description": "Greeting shown on the home page."
  }
}
es6

Uses the same structure as json, but uses ES6 module syntax to export the messages.

export default {
  "hello_67b127a": {
    "message": "Hello!",
    "description": "Greeting shown on the home page."
  }
}
yaml

Aliases: yml, rails

Follows the Ruby on Rails i18n conventions for internationalization messages. Descriptions are added as a comment above the messages they describe.

Note that unlike the other formats, yaml requires the locale to be at the top level.

en:
  # Greeting shown on the home page.
  hello_67b127a: Hello!

License

This software is free to use under the MIT license. See the LICENSE-MIT file for license text and copyright information.

Keywords

FAQs

Package last updated on 17 Feb 2022

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