Skip to main content

Usage

Pass a single translation file, or omit it to discover react-intl locale JSON files from your i18n config.

Behavior

By default, pack prepares a translation file for downstream workflows by removing description metadata while preserving id-keyed output. For FormatJS message JSON, the default output keeps each message id and its defaultMessage:
For plain nested JSON, the default output is a flat id-to-string map:
Use --group-by-value to invert the shape and group ids that share the same translation string:

Automatic discovery

When no translation file is passed, pack loads your i18n config (i18n.yml or i18n.jsonc in the working directory by default) and packs every react-intl translation file referenced by bucket to paths for the selected target locales. Only JSON files in strict FormatJS shape (defaultMessage per id) are packed; plain nested JSON, non-JSON files, and missing files are skipped. Batch discovery writes the packed output back to each input file in place by default. Use --out-suffix to write separate output files instead (for example, --out-suffix .packed turns lang/es-ES.json into lang/es-ES.packed.json). Progress is printed to stderr.

Flags

  • --group-by-value: group ids by shared translation string instead of preserving id-keyed output. Use with a single input file only.
  • --out-file <path>: write the packed JSON to a file instead of stdout. Use with a single input file only.
  • --prefix-id: strip extract --prefix-id filename prefixes from ids. For example, src.components.app-header.title becomes title.
  • --ignore-duplicate-id: ignore duplicate packed ids and keep the first value. This is useful when --prefix-id causes multiple source ids to strip to the same packed id.
  • --config <path>: optional path to i18n config when discovering locale files (default: i18n.yml or i18n.jsonc).
  • --group <name>: filter config discovery by group name.
  • --bucket <name>: filter config discovery by bucket name.
  • --out-suffix <suffix>: optional output filename suffix when packing multiple files. When omitted, each input file is overwritten in place.

Examples

Strip descriptions from an extracted catalog:
Write packed files with a suffix during batch discovery:
Pack every react-intl translation file from the default i18n config:
Use a custom config path:
Group duplicate strings for review:
Strip prefixed ids while grouping:
Strip prefixed ids and keep the first value when duplicates collapse to the same id: