---
title: "Policy and config"
description: "Look up the policy fields that decide what is prose and the types of the configuration files."
canonical_url: "https://diglot.sh/core/policy-and-config"
---
# Policy and config

> Look up the policy fields that decide what is prose and the types of the configuration files.

## The policy

The `Policy` decides what an adapter extracts. `defaultPolicy` targets Nuxt UI and MDC documentation, and `resolvePolicy(partial)` fills a partial policy from it. A field you set replaces the default for that field as a whole. It doesn't merge with it.

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

<tbody>
  <tr>
    <td>
      <code>
        props
      </code>
    </td>
    
    <td>
      Component props whose string values are prose, by component name. Props that aren't listed aren't translated
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        layout
      </code>
    </td>
    
    <td>
      Containers that only lay out their children, so paragraphs inside them stay <code>
        paragraph
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        htmlText
      </code>
    </td>
    
    <td>
      HTML elements whose text content is translated as <code>
        html-block
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        frontmatter
      </code>
    </td>
    
    <td>
      Frontmatter paths that carry prose. A dotted path such as <code>
        navigation.title
      </code>
      
       matches a literal <code>
        navigation.title
      </code>
      
       key or a nested <code>
        navigation: { title }
      </code>
      
      , and <code>
        links[].label
      </code>
      
       walks every array item. Translations are written back to the key that was read
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        navigation
      </code>
    </td>
    
    <td>
      Keys of <code>
        .navigation.yml
      </code>
      
       files that carry prose
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        codeLabel
      </code>
    </td>
    
    <td>
      A function that decides whether a code block label reads as prose (<code>
        Directory Structure
      </code>
      
      ) and not as a path
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        codeComments
      </code>
    </td>
    
    <td>
      Whether to extract comments from fenced code blocks
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        salt
      </code>
    </td>
    
    <td>
      A function that returns a context salt for a segment, or <code>
        undefined
      </code>
      
       to keep the global hash
    </td>
  </tr>
</tbody>
</table>

Component names match in kebab-case or camel-case: `proseProps(policy, 'UButton')` finds the entry `u-button`. The defaults are listed in [segments](https://diglot.sh/guide/concepts/segments). `kindForContainers`, `isProseCodeLabel` and `kebabCase` are the helpers adapters use, and `BREAK_SOURCE` is the markdown that stands for hard breaks.

A `salt` function receives `{ kind, skeleton, file, containers, headingTrail, detail? }`.

## Snapshots

A server that applies translations at runtime has to extract segments exactly as the translations repository did, or the hashes won't match the records. The policy decides what is extracted and how it hashes, so it has to travel with the records. `snapshotPolicy(policy)` returns the serialisable part of a policy together with its `policyFingerprint`, and [`diglot extract`](https://diglot.sh/workflow/cli/extract) and the Action write that snapshot to `.diglot/policy.json`.

```ts
import { restorePolicy } from '@diglot/core'

const policy = restorePolicy(snapshot, { salt, codeLabel })
```

`restorePolicy(snapshot, functions)` rebuilds the policy for `extract` and `apply`. Functions can't be serialised, so when the policy has a custom `salt` or `codeLabel`, the snapshot lists them in `custom` and you pass the same functions in. Restoring throws when the snapshot is malformed, when a listed function is missing, or when the restored policy has a different fingerprint.

`policyFingerprint(policy)` is a hash of everything that changes what is extracted or how it hashes. Functions are compared by their results on a fixed set of inputs, so two functions that agree on those inputs share a fingerprint. Each manifest records the fingerprint of the policy it was extracted under in its `policy` field.

## The configuration types

`defineConfig(config)` returns its argument and exists to type `diglot.config.ts`. The options are described in [Configure diglot](https://diglot.sh/guide/how-to/configure). The same types are exported: `DiglotConfig`, `SourceConfig`, `MtConfig` and `LocaleState`, and the diff options type `DiffOptions`.

## Glossary and style types

`Glossary` has `terms` and an optional `style` list. Each `GlossaryEntry` has a `term`, an optional `match` regular expression source, `caseSensitive`, `note` and a decision: `keep`, `translate` with an optional `target` and `accept` patterns, or `keep-gloss` with a `gloss`. `LocaleStyle` has `rules`, `typography` and `lengthRatio`. The files that hold them are described in [glossary and style](https://diglot.sh/guide/how-to/glossary-and-style).

`matchGlossary(glossary, skeleton)` returns the entries whose term occurs in a skeleton outside placeholders, and `termPattern(entry)` returns the regular expression that finds one entry.

## Frontmatter helpers

`stringsAtPaths(data, paths)` yields `[path, value]` for each non-empty string at the given dotted paths, and `setAtPath(data, path, value)` sets the value at a path that exists. Adapters use them to read and write frontmatter.


## Sitemap

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