Détail du package

babel-plugin-transform-format-message

format-message23.3kMIT6.2.4

Pre-generate ids from default messages or inline a single language translation

format-message

readme

babel-plugin-transform-format-message

Pre-generate ids from default messages or inline a single language translation

npm Version JS Standard Style MIT License

Installation

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

Usage

Via .babelrc (Recommended)

.babelrc

{
  "plugins": [ "transform-format-message", {
    "generateId": "underscored_crc32",
    "inline": false
  } ]
}

Via CLI

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

Via Node API

require("babel-core").transform("code", {
  plugins: [
    [ "transform-format-message", {
      "generateId": "underscored_crc32",
      "translations": "./locales",
      "locale": "pt-BR"
    } ]
  ]
})

Options

  • generateId is either a function string -> string, or one of "literal", "normalized", "underscored", "underscored_crc32". Default is "underscored_crc32".
  • inline is a boolean. If true, the full translated message will be inlined and optimized, otherwise only generated ids will be added. Default is false.
  • locale is the BCP 47 Language Tag string specifying the target language to inline. This is only used with inline: true. Default is "en".
  • translations is an object of the form: { [locale]: { [id]: { message: '...' }, ... } }. This is an object with keys for each locale, with values matching the extract-format-message json output. This can also be a string path to require a module that exports a matching object.
  • missingTranslation is one of "ignore", "warning", "error". Default is "warning".
  • missingReplacement is an optional string to use in place of missing translations. By default the default message will be used.

License

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

changelog

Changelog

6.1.0

Uses babel 7.

6.0.3

Use var declarations for wider compatibility.

6.0.0

Support formatMessage.rich(). Use that as the translate='yes' target instead of formatChildren().

5.2.6

Fix IE11 compat by removing template literals.

5.2.5

Made formatChildren more lenient in parsing.

5.2.3

Fix a bug affecting react-native apps.

5.2.1

Updated CLDR plural rules.

5.1.4

  • Fixed placeholder style names with spaces or other special characters.
  • Fixed warnings about needing keys on transformed translate="yes" children.

5.1.0

Supports namespaced formatMessage.

5.0.0

New Feature

  • Transform messages from JSX marked with translate="yes"
  • Allow missingReplacement to be a function
  • Remove format-message import if all uses were inlined

4.1.0

New Feature

  • import {default as __} from 'format-message' works as expected