# Admin languages

Choose the language the whole admin speaks, give your own screens words in it, and add a language.

The admin speaks one language at a time, the same on every screen: buttons, messages, dates,
times and numbers. English and German are written for the screens of the family.

## Choose the language of an install

The install of the admin names it in `apps/admin/src/modules.ts`, as one of the languages the
admin speaks:

```text
export const language: Language = "de";
```

The admin refuses to start when a module's place in the sidebar has no name in that language.
Dates, times and numbers follow the same language, never the browser's settings.

## Where the words live

The languages are named once, in `packages/ui/src/language.tsx`:

```text
export const languages = ["en", "de"] as const;
```

Every package that has screens keeps its words in its own `words/` folder, one file per
language, so an install that uses only some products ships only their words:

```text
<package>/src/words/en.ts      the source: English, grouped by feature
<package>/src/words/de.ts      the same keys in German
<package>/src/words/index.ts   defineWords({ en, de })
```

## Give your own module words

English comes first, and every other language has to be complete by type:

```ts browser
import { defineWords } from "@orbcommerce/ui";

const en = {
  jobs: {
    newJob: "New fleet job",
    jobCount: (count: number) => (count === 1 ? "1 job" : `${count} jobs`),
  },
};

const de: typeof en = {
  jobs: {
    newJob: "Neuer Fuhrparkauftrag",
    jobCount: (count: number) => (count === 1 ? "1 Auftrag" : `${count} Aufträge`),
  },
};

export const { useWords: useFleetWords, wordsIn: fleetWordsIn } = defineWords({ en, de });
```

A screen reads them with `useFleetWords().jobs`. A label outside React, such as a place in
the sidebar, reads them with `fleetWordsIn(language).jobs`. A word missing in `de` is a type
error, not a gap on screen.

Write dates, times, relative times and numbers with `useFormats()` from `@orbcommerce/ui`, and
take a date, a time or both from the staff with `DateTimeField`. It is typed in the language's
own order and clock, and keeps the value a native date input would.

German uses the polite form (Sie) and short verbs for actions. One word stands for one concept
in every product: Bestellung, Termin, Standort, Produkt, Kategorie, Gutschein, Rabatt,
Mitarbeitende.

## Add a language

Add its code to `languages`. Typecheck then names every package whose words do not have it yet.
In each, copy `en.ts` to the new language's file, translate the text and add the file to
`defineWords({ en, de, fr })`. Then set the install's `language` to it.