---
title: "Records and bundles"
description: "Read and write translation records, and build and parse the locale bundles."
canonical_url: "https://diglot.sh/store/records-and-bundles"
---
# Records and bundles

> Read and write translation records, and build and parse the locale bundles.

## Records

Records are stored one per file at `<locale>/segments/<hh>/<hash>.json`, and these functions work with them:

<table>
<thead>
  <tr>
    <th>
      Function
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        recordPath(locale, hash)
      </code>
    </td>
    
    <td>
      The path relative to the repository root
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        readRecord(root, locale, hash)
      </code>
    </td>
    
    <td>
      One record, or <code>
        undefined
      </code>
      
       if the file doesn't exist
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        writeRecord(root, locale, record)
      </code>
    </td>
    
    <td>
      Validates the record, writes it and returns its path
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        readRecords(root, locale)
      </code>
    </td>
    
    <td>
      Every record of a locale, sorted by hash
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        loadLocale(root, locale)
      </code>
    </td>
    
    <td>
      The same records in a <code>
        Map
      </code>
      
       keyed by hash
    </td>
  </tr>
</tbody>
</table>

`serialiseRecord` produces the file content: a fixed key order, two-space indentation and a trailing newline. Records are validated on read and write, and `readRecords` throws when a file is malformed or when a record's hash doesn't match its path, so a hand edit that breaks a record is caught early.

## Build bundles

`build(root, { locales, outDir?, only? })` writes `<outDir>/<locale>.json` for each locale and returns one result per locale. `outDir` is relative to `root` and defaults to `dist`. When `only` is given, only records with those hashes are included, typically `liveHashes` of all manifests.

Each result has `locale`, `path`, `records` (the count in the bundle), `rejected` (how many of those a reviewer rejected) and `skipped` (how many records were left out because their hash isn't live).

The bundle has the shape `{ version: 1, locale, records }`, with records keyed by hash.

## Parse a bundle

`parseBundle(content)` accepts the text of a bundle or the parsed object and returns a `Map<hash, record>`. It validates every record, throws `unsupported locale bundle` for an unknown version, and throws when a key doesn't match its record's hash. Bundles include rejected records so that consumers can show their status, and applying them still falls back to the source text. See [use translations in your site](https://diglot.sh/guide/how-to/use-translations).


## Sitemap

See the full [sitemap](https://diglot.sh/sitemap.md) for all pages.
