# Label packs

> Reference for the label packs in @recipe-book/react/labels, which write metric units and most of the parts' controls in German, French, Dutch, Swedish, Danish, Norwegian, Italian, or Spanish.

Source: https://recipe-book.siraj.page/reference/react/labels/

Use these exports from `@recipe-book/react/labels` to show a recipe in another language. Import your language and pass it as `labels` to a [`<Recipe.Provider>`](https://recipe-book.siraj.page/reference/react/provider.md), with a `locale` for its numbers. A pack holds the `language`, `units`, `durations`, `temperature`, and `size` of core's pack of the same name from [`@recipe-book/core/labels`](https://recipe-book.siraj.page/reference/core/labels.md), plus the text of the parts' controls. It leaves out the terms of [`<Recipe.Times>`](https://recipe-book.siraj.page/reference/react/times.md) and [`<Recipe.Nutrition>`](https://recipe-book.siraj.page/reference/react/nutrition.md) and the text of [`<Recipe.CookMode>`](https://recipe-book.siraj.page/reference/react/cook-mode.md), which stay in English unless you set them. No shipped pack labels the US units, such as `cup` and `oz`, because each language's own word for them names another size, so they keep their English labels. `handful`, `jar`, `stalk`, and `bag` stay English too, since the shipped packs don't label them. Each pack is frozen, and core's [`labelPack`](https://recipe-book.siraj.page/reference/core/labels.md#labelpack) made it, so core's formatting functions take it too in client code. A Server Component formats with core's pack instead, as [Imports on core's pages](https://recipe-book.siraj.page/reference/react/labels.md#imports-on-cores-pages) shows.

app/recipes/layout.tsx
```tsx title="app/recipes/layout.tsx" {2,7}
import * as Recipe from '@recipe-book/react'
import { de } from '@recipe-book/react/labels'
import type { ReactNode } from 'react'

export default function RecipesLayout({ children }: { children: ReactNode }) {
  return (
    <Recipe.Provider locale="de-DE" labels={de}>
      {children}
    </Recipe.Provider>
  )
}
```

Every [`<Recipe.Root>`](https://recipe-book.siraj.page/reference/react/root.md) inside then writes "2 EL" for 2 tbsp, names the servings select "Portionen", and names the toggle "Maßsystem". Set `lang` on `<html>` to the same language, so screen readers read the page in it.

The layout is a Server Component, and `@recipe-book/react/labels` is a client module, so `de` reaches the provider as a client reference, with its words. A pack you make can't cross that way: a pack holds its words under a symbol key, and React drops symbol keys from a Server Component's props. A copy that arrives without the key makes the Root or provider throw [`invalid_argument`](https://recipe-book.siraj.page/errors/invalid_argument.md), in every build, rather than write English. Make your own pack in a `'use client'` module, as in [Change one word](https://recipe-book.siraj.page/reference/react/labels.md#change-one-word).

Any serialization drops the key too, JSON included, so a pack can't go through a React Router loader's data or an Astro island's props: the page renders on the server, then the Root or provider throws in the browser. Send the language code instead, and map it to a pack you import in the component that gets it, such as with `{ de, fr }[language]`.

All eight packs ship in one module, but each is one call marked pure, so a bundler keeps only the packs you import: `import { de }` adds about 1.1 kB gzipped to a page that renders ingredients or steps, core's `de` included.

## Change one word

To change one unit, spread a pack into [`labelPack`](https://recipe-book.siraj.page/reference/react/labels.md#labelpack) with that unit changed, and pass the new pack as `labels` to a Root or an inner provider. The spread alone, as in `labels={{ ...de }}`, isn't a pack, and TypeScript rejects it: it loses the words, and the Root or provider throws [`invalid_argument`](https://recipe-book.siraj.page/errors/invalid_argument.md). A pack's words replace the outer pack's whole, so spread `de.units` too, and every other German word stays. Make the pack at module scope, in a `'use client'` module, so it keeps its identity between renders and keeps its words on the way to the Root.

```tsx
'use client'

import * as Recipe from '@recipe-book/react'
import type { Recipe as ParsedRecipe } from '@recipe-book/react/core'
import { de, labelPack } from '@recipe-book/react/labels'

const tbsp = {
  short: { one: 'Essl.', other: 'Essl.' },
  long: { one: 'Esslöffel', other: 'Esslöffel' },
}

const spoons = labelPack({
  ...de,
  units: { ...de.units, tbsp, 'tbsp-au': tbsp },
})

export function RecipeCard({ recipe }: { recipe: ParsedRecipe }) {
  return (
    <Recipe.Root recipe={recipe} labels={spoons}>
      <Recipe.Ingredients />
    </Recipe.Root>
  )
}
```

Under the provider above, `RecipeCard` writes "2 Essl." for 2 tbsp, also in a recipe [read with `units: { tbsp: 'tbsp-au' }`](https://recipe-book.siraj.page/guides/localize-recipes.md#write-your-own-pack) unless it's in `'us'`, where 2 of them show as "8 TL", and still "1 TL" for 1 tsp. Every shipped pack labels `tbsp-au` as `tbsp` in a separate entry, so change both. No shipped pack labels `cup` or `cup-metric`, so a pack that labels one leaves the other in English. [`RecipeLabelOverrides`](https://recipe-book.siraj.page/reference/react/provider.md#recipelabeloverrides) describes the merge.

## Imports on core's pages

Core's pages import from `@recipe-book/core`. In a React app, which installs only `@recipe-book/react`, `@recipe-book/core` becomes `@recipe-book/react/core`, and `@recipe-book/core/schema-org` becomes `@recipe-book/react/core/schema-org`, and `@recipe-book/core/labels` becomes `@recipe-book/react/core/labels`. None of them is a client module, so a Server Component calls them, as with [`formatQuantity`](https://recipe-book.siraj.page/reference/core/formatting.md#formatquantity) here:

```ts
import { formatQuantity } from '@recipe-book/react/core'
import { de } from '@recipe-book/react/core/labels'

const text = formatQuantity(
  { amount: 2, unit: 'tbsp' },
  { locale: 'de-DE', labels: de },
)
```

In a Server Component, a pack from `@recipe-book/react/labels` is a client reference, which a formatting function can't use. On Next.js 15 and later, the formatting function throws [`invalid_argument`](https://recipe-book.siraj.page/errors/invalid_argument.md). On Next.js 14, Next.js itself throws first: "Cannot read Symbol exports. Only named exports are supported on a client module imported on the server." Import core's pack from `@recipe-book/react/core/labels` there instead, as [Imports on core's pages](https://recipe-book.siraj.page/reference/react/labels.md#imports-on-cores-pages) shows.

## `labelPack`

```ts
const labelPack: (
  labels: RecipeLabelOverrides,
) => RecipeLabelPack
```

Core's [`labelPack`](https://recipe-book.siraj.page/reference/core/labels.md#labelpack), typed for `labels` on a Root or a provider, which take only a pack. It takes the controls' text as well as core's [`LabelWords`](https://recipe-book.siraj.page/reference/core/types.md#labelwords), and checks the words as core's does. Core's formatting functions take its pack too, as in [Write your own pack](https://recipe-book.siraj.page/guides/localize-recipes.md#write-your-own-pack). Call it in client code; to make a pack in a Server Component, which can only format, call core's from `@recipe-book/react/core/labels`. In client code, a Root or a provider takes core's packs too, its languages' and the ones its `labelPack` makes, with no error or warning, but the controls get no text from them: each key keeps the outer provider's value, then English. With `locale="de-DE"` and no outer provider that sets the controls, `<Recipe.ServingsSelect>` and `<Recipe.SystemToggle>` read "2 servings … Metric US" under core's `de`, where this module's [`de`](https://recipe-book.siraj.page/reference/react/labels.md#de) gives "2 Portionen … Metrisch USA". For translated controls, use the pack from `@recipe-book/react/labels`. A pack's type is [`RecipeLabelPack`](https://recipe-book.siraj.page/reference/react/provider.md#recipelabelpack).

## `de`

```ts
const de: RecipeLabelPack
```

German: core's [`de`](https://recipe-book.siraj.page/reference/core/labels.md#de), plus this text. Pass it with a German `locale`, such as `de-DE`.

| Label         | Text                |
| ------------- | ------------------- |
| `servings`    | Portionen           |
| `servingUnit` | Portion / Portionen |
| `system`      | Maßsystem           |
| `metric`      | Metrisch            |
| `us`          | USA                 |
| `fan`         | Umluft              |
| `optional`    | (optional)          |
| `to`          | bis                 |

## `fr`

```ts
const fr: RecipeLabelPack
```

French: core's [`fr`](https://recipe-book.siraj.page/reference/core/labels.md#fr), plus this text. Pass it with a French `locale`, such as `fr-FR`.

| Label         | Text               |
| ------------- | ------------------ |
| `servings`    | Portions           |
| `servingUnit` | portion / portions |
| `system`      | Système de mesure  |
| `metric`      | Métrique           |
| `us`          | US                 |
| `fan`         | chaleur tournante  |
| `optional`    | (facultatif)       |
| `to`          | à                  |

## `nl`

```ts
const nl: RecipeLabelPack
```

Dutch: core's [`nl`](https://recipe-book.siraj.page/reference/core/labels.md#nl), plus this text. Pass it with a Dutch `locale`, such as `nl-NL`.

| Label         | Text             |
| ------------- | ---------------- |
| `servings`    | Porties          |
| `servingUnit` | portie / porties |
| `system`      | Maatsysteem      |
| `metric`      | Metriek          |
| `us`          | VS               |
| `fan`         | hetelucht        |
| `optional`    | (optioneel)      |
| `to`          | tot              |

## `sv`

```ts
const sv: RecipeLabelPack
```

Swedish: core's [`sv`](https://recipe-book.siraj.page/reference/core/labels.md#sv), plus this text. Pass it with a Swedish `locale`, such as `sv-SE`.

| Label         | Text                |
| ------------- | ------------------- |
| `servings`    | Portioner           |
| `servingUnit` | portion / portioner |
| `system`      | Enhetssystem        |
| `metric`      | Metriskt            |
| `us`          | USA                 |
| `fan`         | varmluft            |
| `optional`    | (valfritt)          |
| `to`          | till                |

## `da`

```ts
const da: RecipeLabelPack
```

Danish: core's [`da`](https://recipe-book.siraj.page/reference/core/labels.md#da), plus this text. Pass it with a Danish `locale`, such as `da-DK`.

| Label         | Text                |
| ------------- | ------------------- |
| `servings`    | Portioner           |
| `servingUnit` | portion / portioner |
| `system`      | Målesystem          |
| `metric`      | Metrisk             |
| `us`          | USA                 |
| `fan`         | varmluft            |
| `optional`    | (valgfrit)          |
| `to`          | til                 |

## `nb`

```ts
const nb: RecipeLabelPack
```

Norwegian Bokmål: core's [`nb`](https://recipe-book.siraj.page/reference/core/labels.md#nb), plus this text. Pass it with a Norwegian Bokmål `locale`, such as `nb-NO`.

| Label         | Text                |
| ------------- | ------------------- |
| `servings`    | Porsjoner           |
| `servingUnit` | porsjon / porsjoner |
| `system`      | Målesystem          |
| `metric`      | Metrisk             |
| `us`          | USA                 |
| `fan`         | varmluft            |
| `optional`    | (valgfritt)         |
| `to`          | til                 |

## `it`

```ts
const it: RecipeLabelPack
```

Italian: core's [`it`](https://recipe-book.siraj.page/reference/core/labels.md#it), plus this text. Pass it with an Italian `locale`, such as `it-IT`.

| Label         | Text                   |
| ------------- | ---------------------- |
| `servings`    | Porzioni               |
| `servingUnit` | porzione / porzioni    |
| `system`      | Sistema di misurazione |
| `metric`      | Metrico                |
| `us`          | USA                    |
| `fan`         | ventilato              |
| `optional`    | (facoltativo)          |
| `to`          | a                      |

## `es`

```ts
const es: RecipeLabelPack
```

Spanish: core's [`es`](https://recipe-book.siraj.page/reference/core/labels.md#es), plus this text. Pass it with a Spanish `locale`, such as `es-ES`.

| Label         | Text                |
| ------------- | ------------------- |
| `servings`    | Raciones            |
| `servingUnit` | ración / raciones   |
| `system`      | Sistema de medición |
| `metric`      | Métrico             |
| `us`          | EE. UU.             |
| `fan`         | con ventilador      |
| `optional`    | (opcional)          |
| `to`          | a                   |
