> For the complete documentation index, see [llms.txt](https://mkfont.gitbook.io/mkfont-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mkfont.gitbook.io/mkfont-docs/adding-a-language.md). Agents can also search and read this documentation through its [MCP server](https://mkfont.gitbook.io/mkfont-docs/~gitbook/mcp).

# Adding a Language

How to add an interface language to MkFont from its source code: where the text is kept, what a translation has to keep, and the checks it has to pass. For contributors.

MkFont's interface text is kept apart from its code, in one set of files per language. Adding a language means translating a copy of the English set, then naming the new language where MkFont lists the ones it has.

The work is done in MkFont's [source code](https://github.com/Nebukam/mkfont), with Git and Node.js installed. The files to translate are lists of messages, and this page covers the little code around them.

## Where the text is kept

*A folder of catalogs for the window, and one file for what the system draws.*

| Path                                                     | Holds                                                                                                                                         |
| -------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `src/renderer/src/locales/en/`                           | The English messages of the window, one file per area of the app: `browse.ts`, `inspector.ts`, `kerning.ts` and so on. `index.ts` joins them. |
| `src/main/locales/en.ts`                                 | The English messages the system draws for MkFont: the macOS menu and the native dialogs.                                                      |
| `src/renderer/src/locales/fr/`, `src/main/locales/fr.ts` | The same files in French. Every language MkFont has follows this layout, under its own code.                                                  |

English is the source. A translation has the keys of the English files and no others, and the comments in the English files say where a message appears when its key does not.

## Adding the language

*Copy the English files, translate them, register the language, run the checks.*

{% stepper %}
{% step %}

### Get the source running

Clone the repository, then install and start MkFont from its folder:

```
npm install
npm run dev
```

{% endstep %}

{% step %}

### Choose the code

The code names the folder and the file of the language. Use the base code of the language: `de`, `pt`, `ja`.

MkFont matches the system's languages on the part before the first hyphen, so `pt-BR` and `pt-PT` both select `pt`. A folder named with a region would never be selected by the **System** entry of the **Language** preference.
{% endstep %}

{% step %}

### Copy the English files

Copy the folder `src/renderer/src/locales/en` to `src/renderer/src/locales/<code>`, and the file `src/main/locales/en.ts` to `src/main/locales/<code>.ts`.

In the copied `index.ts`, rename the `en` constant to the code and delete the last line, the `Messages` type, which belongs to English. Nothing else in that file changes.
{% endstep %}

{% step %}

### Tie each file to English

Each area file starts with `export default {` and ends with `} as const`. Add two imports above the first, and replace the ending. For `browse.ts`:

```ts
import type en from '../en/browse'
import type { Catalog } from '../catalog'

export default {
  title: 'Parcourir',
  // the other messages
} satisfies Catalog<typeof en>
```

The import names the English file of the same area. In `src/main/locales/<code>.ts` the two imports are `'./en'` and `'./catalog'`.

With that ending in place, a key that is missing or misspelled is reported by the type check, with the file and the key.
{% endstep %}

{% step %}

### Translate the messages

Translate the text between the quotes and leave the keys as they are. [What a message has to keep](#what-a-message-has-to-keep) lists the parts of a message that stay as written.
{% endstep %}

{% step %}

### Register the language

| File                                      | Add                                                                                                                                                                                 |
| ----------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `src/renderer/src/i18n/index.ts`          | An import of the new folder, the code in `LANGUAGES`, the name of the language written in itself in `LANGUAGE_NAMES`, its language tag in `HTML_LANG`, and an entry in `resources`. |
| `src/main/i18n.ts`                        | An import of the new file, the code in `LANGUAGES`, and an entry in `resources`.                                                                                                    |
| `src/renderer/src/__tests__/i18n.test.ts` | An import of both catalogs, and a row in the list of translations, next to `['fr', fr, mainFr]`.                                                                                    |

Each line of `LANGUAGE_NAMES` carries an `// i18n-ignore:` comment. Copy it: without it, the check that looks for interface text written outside the catalogs reports the name.

The tag in `HTML_LANG` can say more than the code: Simplified Chinese has the code `zh` and the tag `zh-Hans`.

The **Language** list of the Preferences is built from `LANGUAGES`, so the new language appears in it with no other change.
{% endstep %}

{% step %}

### Run the checks

```
npm run typecheck
npm test
```

The type check reports missing and misspelled keys. The tests compare each language with English, message by message, and name every key that fails: a message that is missing, empty or not in English, a plural with the wrong forms, a value or a tag that was lost.

Then start MkFont, choose the language under **Language** in the Preferences, and read it in place. The preference is described on [Preferences](https://mkfont.gitbook.io/mkfont-docs/reference/preferences.md).
{% endstep %}

{% step %}

### Send it

Open a pull request on the [repository](https://github.com/Nebukam/mkfont/pulls) with the new files and the three edited ones.
{% endstep %}
{% endstepper %}

## What a message has to keep

*Values, tags and plural keys are read by the app, and the tests fail when one is lost.*

| In a message                       | What it is                                                                                                               | In a translation                                                      |
| ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------- |
| `{{filter}}`, `{{count, number}}`  | A value MkFont fills in. The word after a comma is how it is written: `number` writes a count the way the language does. | Kept as written, at the place the sentence needs it.                  |
| `<n>` and `</n>`, `<k>` and `</k>` | Tags around the part of the sentence that is styled, such as a count or a key.                                           | Kept, around the words that translate that part.                      |
| A key ending in `_one` or `_other` | One form of a plural.                                                                                                    | One key per form the language has. See [Plural forms](#plural-forms). |
| A `//` comment                     | A note for translators.                                                                                                  | Left in English, or removed.                                          |

## Plural forms

*Each language has its own set of forms, and a plural needs all of them.*

English has two, so an English plural is two keys: `glyphs_one` and `glyphs_other`. French and Spanish have `_one`, `_many` and `_other`. Chinese has `_other` alone. A translation writes one key for each form of its language, under the same name before the underscore.

This command prints the forms of a language, here Polish:

```
node -e "console.log(new Intl.PluralRules('pl').resolvedOptions().pluralCategories)"
```

A plural form may leave the count out where the language does not write it: the French `_one` of a message can read "un glyphe". Its other values stay.

## Messages that are more than a translation

*A few messages follow the language's keyboards and habits.*

| Message                                      | In a translation                                                                                                                                                          |
| -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| The names of keys, under `keys` in `help.ts` | The names printed on the language's keyboards: `Shift` is `Maj` in French.                                                                                                |
| `preview.defaultText` in `sidebar.ts`        | The sentence the **Text preview** panel shows until one is typed. English has a pangram, and so do French and Spanish. A language without one keeps the English sentence. |
| Quotation marks and punctuation              | The language's own. French messages use guillemets, and Chinese ones full-width punctuation.                                                                              |

The Unicode names of characters and of blocks have no catalog: they stay in English in every language.

{% hint style="info" %}

## A language is kept up

When MkFont gains a message, the message is added to every language in the same change. Until it is, the tests fail.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://mkfont.gitbook.io/mkfont-docs/adding-a-language.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
