---
title: "Locale files"
description: "Load glossaries, style rules and machine translation state for a locale."
canonical_url: "https://diglot.sh/store/locale-files"
---
# Locale files

> Load glossaries, style rules and machine translation state for a locale.

Each locale directory can hold a glossary, a style file and a state file. All three are optional, and the loaders return an empty or undefined result when a file is missing.

## Glossary

`loadGlossary(root, locale, { shared? })` reads the shared glossary named by `shared` (relative to `root`, or absolute) and `<locale>/glossary.yml`, and merges them. Entries in the locale file replace shared entries with the same term, compared ignoring case. It returns `undefined` when neither file exists.

Both files accept diglot's shape, an object with `terms` and optionally `style`, and [x18n](https://github.com/x18n-dev/x18n)'s shape, a list of entries or an object with a `glossary` list. x18n entries are converted for the locale. See [glossary and style](https://diglot.sh/machine-translation/glossary-and-style) for the mapping, and the [guide](https://diglot.sh/guide/how-to/glossary-and-style) for how to write the files.

## Style

`loadStyle(root, locale)` reads `<locale>/style.yml` and returns `rules`, `typography` and `lengthRatio`, or `undefined` when there is no file. It checks that `rules` is a list of strings, that `lengthRatio` is a pair of numbers and that the typography values are strings.

## Locale state

`loadLocaleState(root, locale)` reads `<locale>/locale.yml` and returns an empty state when there is none. It validates `mt.enabled` and the `governance` metrics. `mtEnabled(state)` is true only when `mt.enabled` is `true`, and it is the switch the Action reads. See [review and status](https://diglot.sh/guide/concepts/review-and-status#machine-translation-per-locale).

## Parsing data from anywhere

The loaders read files from disk. When your YAML comes from somewhere else, such as an API or an archive, the parsers behind them do the same work on parsed data, and they are also exported from `@diglot/store/runtime`:

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

<tbody>
  <tr>
    <td>
      <code>
        parseGlossary(data, locale, file?)
      </code>
    </td>
    
    <td>
      Converts a glossary in either shape for one locale. Errors name the file and the term
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        mergeGlossary(shared, own)
      </code>
    </td>
    
    <td>
      Merges a shared glossary below a locale's own, as <code>
        loadGlossary
      </code>
      
       does. The style rules are those of <code>
        own
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        parseLocaleState(data, file?)
      </code>
    </td>
    
    <td>
      Validates a <code>
        locale.yml
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        parseStyle(data, file?)
      </code>
    </td>
    
    <td>
      Validates a <code>
        style.yml
      </code>
    </td>
  </tr>
</tbody>
</table>


## Sitemap

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