> ## Documentation Index
> Fetch the complete documentation index at: https://hyperlocalise.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# pack

> Prepare translation JSON by stripping metadata or grouping duplicate strings.

## Usage

```bash theme={null}
hyperlocalise pack [translation-file] [flags]
```

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`:

```json theme={null}
{
  "src.components.app-header.title": {
    "defaultMessage": "Dashboard"
  },
  "src.components.hero.title": {
    "defaultMessage": "Dashboard"
  }
}
```

For plain nested JSON, the default output is a flat id-to-string map:

```json theme={null}
{
  "home.title": "Dashboard",
  "nav.title": "Dashboard"
}
```

Use `--group-by-value` to invert the shape and group ids that share the same translation string:

```json theme={null}
{
  "Dashboard": ["src.components.app-header.title", "src.components.hero.title"]
}
```

### 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:

```bash theme={null}
hyperlocalise pack lang/en.json --out-file lang/en.json
```

Write packed files with a suffix during batch discovery:

```bash theme={null}
hyperlocalise pack --out-suffix .packed
```

Pack every react-intl translation file from the default i18n config:

```bash theme={null}
hyperlocalise pack
```

Use a custom config path:

```bash theme={null}
hyperlocalise pack --config path/to/i18n.yml
```

Group duplicate strings for review:

```bash theme={null}
hyperlocalise pack lang/en.json --group-by-value --out-file lang/duplicates.json
```

Strip prefixed ids while grouping:

```bash theme={null}
hyperlocalise pack lang/en.json --group-by-value --prefix-id --out-file lang/packed.json
```

Strip prefixed ids and keep the first value when duplicates collapse to the same id:

```bash theme={null}
hyperlocalise pack lang/en.json --prefix-id --ignore-duplicate-id --out-file lang/packed.json
```
