Recipe Book0.6.0

3.6Core reference

Label packs

Reference for the label packs in @recipe-book/core/labels, which write units, durations, temperatures, and sizes in German, French, Dutch, Swedish, Danish, Norwegian, Italian, or Spanish.

§ 3.617 min readView as Markdown

Use these exports from @recipe-book/core/labels to write units, durations, temperatures, and sizes in another language. Pass a pack as labels to a formatting function, with a locale for its numbers. Each pack is a frozen LabelPack. Localize recipes walks through using one. In a React app, import these exports from @recipe-book/react/core/labels, and pass the parts the pack for your language from @recipe-book/react/labels, which covers their controls too. The terms of <Recipe.Times> and <Recipe.Nutrition> and the label of <Recipe.CookMode> stay in English unless you set them. Under every pack, <Recipe.Times> writes its durations in English, <Recipe.Nutrition> writes kcal, g, and mg, and the parts show temperatures as °C and °F. A pack from here can’t pass from a Server Component to a Client Component: React drops the symbol key that holds its words, so a formatting function throws invalid_argument for the copy. Import the pack in the Client Component that formats with it.

TypeScript
import {
  formatDuration,
  formatQuantity,
  formatTemperature,
} from '@recipe-book/core'
import { de } from '@recipe-book/core/labels'

const german = { locale: 'de-DE', labels: de }

formatQuantity({ amount: 2, unit: 'tbsp' }, german) // '2 EL'
formatQuantity({ amount: 1.5, unit: 'pinch' }, german) // '1 ½ Prisen'
formatDuration(90, german) // '1 Std. 30 Min.'
formatTemperature({ value: 180, unit: 'C' }, { ...german, unitDisplay: 'long' }) // '180 Grad Celsius'

Each pack is its own module, so a bundler keeps only the packs you import: import { de } adds about 1.0 kB gzipped to a page that formats quantities. The CommonJS build has all eight in one file (about 3.8 kB gzipped). require() loads it in Jest, in Node.js 22.0 to 22.11, in Cloudflare Workers that Wrangler bundles, and in the code Bun runs, including code that bun build bundles with --target=bun or --target=node. When Jest runs ES modules natively, with --experimental-vm-modules, from Jest 30.5 on Node.js 24.9 and later, its require() loads the ES module build instead. Unbundled ESM, as in Node, loads the eight packs, an index, and three shared helpers as twelve modules (about 7.3 kB gzipped in total) on a page that already formats quantities, or 17 (about 11.7 kB) loaded alone.

What a pack holds

Every pack labels the four duration units, and every unit but the twelve in the next paragraph, in a short and a long form, each with a singular (one) and a plural (other). It also has the words of a temperature’s long form: degree, singular and plural, and the name of each scale. The formatters pick the form as LabelWords describes. A pack’s aliases are other spellings of a unit, such as 'Teel.' for TL. The formatters never write them. Every pack also has its size words, which end a count unit’s size in place of “each” and “total”, as in 2 Dosen (425 g pro Stück).

No pack labels the US units, oz, lb, fl-oz, cup, pint, quart, and gallon, because each language’s own word for them names another size. Nor does any pack label the 250 mL cup-metric. So de.units.cup is undefined. These eight keep their English labels from the registry. The registry gives cup-metric the same labels as cup. No pack labels the containers handful, jar, stalk, and bag yet either, so they also keep their English labels. The 20 mL tbsp-au writes the pack’s tbsp labels without its aliases.

No pack holds these words, as a label or an alias:

Words Why
German “Tasse”, Dutch “kopje” and “kop”, French “tasse”, Italian “tazza”, Spanish “taza”, Swedish and Norwegian “kopp”, Danish “kop” A cup of no fixed size.
German “Pfund”, Dutch “pond”, French “livre”, Danish and Norwegian “pund” 500 g, not the 454 g of lb.
Dutch “ons” 100 g, not the 28 g of oz.
French “bouquet” It names the herbs in “bouquet garni”.
French “cc” It also means cubic centimeters.
Italian “chilo” Its plural, “chili”, is an English ingredient.
German “gr” “gr.” also abbreviates “groß” (large). nl, it, and es have it as an alias of g.

labelPack

TypeScript
function labelPack(labels: LabelWords): LabelPack

Checks your own words and makes them into a pack that the formatting functions take as labels. @recipe-book/core/labels also exports the types LabelWords and LabelPack, as @recipe-book/core does, so you can import them with import type next to labelPack.

Name Type Default Description
labels LabelWords Required The words to write. Any unit or duration unit it leaves out keeps its English labels, as does a temperature’s long form without temperature, and without size, a count unit’s size ends with “each” or “total”.

Returns a frozen copy of labels. Apart from a function, and an array whose map or constructor isn’t the built-in one, which the next paragraph covers, every object and array inside it is copied and frozen too, so labelPack never changes labels, and a later change to labels doesn’t reach the pack. An object’s copy holds only its own string keys, so a Map loses its entries and a Date its time. A copy of a pack made with a spread isn’t a pack, so pass the copy to labelPack, as Localize recipes does. TypeScript rejects the spread copy itself as labels.

A function inside labels stays the same function, which labelPack doesn’t freeze, so a change to it reaches the pack. An array inside labels is copied with its map method. When its map and constructor are the built-in ones, its copy is a new frozen plain array, which labelPack doesn’t change and a later change to the array doesn’t reach. Otherwise the copy is whatever they make: by default, one from a subclass of Array keeps its class, and one with a map of its own becomes whatever that returns, frozen.

TypeScript
import { formatQuantity } from '@recipe-book/core'
import { labelPack } from '@recipe-book/core/labels'

const spoons = labelPack({
  language: 'de',
  units: {
    tbsp: {
      short: { one: 'Essl.', other: 'Essl.' },
      long: { one: 'Esslöffel', other: 'Esslöffel' },
    },
  },
})

formatQuantity({ amount: 2, unit: 'tbsp' }, { labels: spoons }) // '2 Essl.'

Throws a RecipeBookError with the code invalid_argument when labels isn’t an object, when its language is given and isn’t a language tag starting with a two- or three-letter code, such as 'German', or when a group or entry it reads is given but isn’t an object, is missing a label it needs, or has one that isn’t a string. The groups and entries it reads are units and each registry unit in it, durations and each duration unit in it, temperature, and size, not only the ones a formatting function writes. In a runtime without Intl or without Intl.PluralRules, it checks only that a language starts with a two- or three-letter code, so a language such as 'de-$$' or 'de-DE-DE' doesn’t throw. It ignores any other key, so a unit keyed by one of its other spellings in the registry, such as cups for cup, keeps its English labels. An error thrown by a getter or proxy in labels passes through.

de

TypeScript
const de: LabelPack

German words, with language: 'de'.

Unit Short Long Aliases
mg mg Milligramm —
g g Gramm —
kg kg Kilogramm —
ml ml Milliliter —
cl cl Zentiliter —
dl dl Deziliter —
l l Liter —
tsp TL Teelöffel Teel.
tbsp EL Esslöffel Eßlöffel
pinch Prise / Prisen As short —
dash Spritzer As short —
clove Zehe / Zehen As short —
slice Scheibe / Scheiben As short —
piece Stück As short Stk.
can Dose / Dosen As short —
package Pck. As short —
stick Stange / Stangen As short —
sprig Zweig / Zweige As short —
bunch Bund As short Bd.
head Kopf / Köpfe As short —
Duration Short Long
day Tag / Tage Tag / Tage
hour Std. Stunde / Stunden
minute Min. Minute / Minuten
second Sek. Sekunde / Sekunden

In unitDisplay: 'long', temperatures use Grad, Celsius, and Fahrenheit.

A count unit’s size ends with “pro Stück” in place of “each” and “insgesamt” in place of “total”.

fr

TypeScript
const fr: LabelPack

French words, with language: 'fr'.

Unit Short Long Aliases
mg mg milligramme / milligrammes —
g g gramme / grammes —
kg kg kilogramme / kilogrammes —
ml ml millilitre / millilitres —
cl cl centilitre / centilitres —
dl dl décilitre / décilitres —
l l litre / litres —
tsp c. à café cuillère à café / cuillères à café c. à c., càc, c.à.c, c.c, cuill. à café
tbsp c. à soupe cuillère à soupe / cuillères à soupe c. à s., càs, c.à.s, c.s, cs, cuill. à soupe
pinch pincée / pincées As short —
dash trait / traits As short —
clove gousse / gousses As short —
slice tranche / tranches As short tran.
piece pièce / pièces As short —
can boîte / boîtes As short —
package sachet / sachets As short —
stick bâton / bâtons As short —
sprig brin / brins As short —
bunch botte / bottes As short —
head tête / têtes As short —
Duration Short Long
day jour / jours jour / jours
hour h heure / heures
minute min minute / minutes
second s seconde / secondes

In unitDisplay: 'long', temperatures use degré / degrés, Celsius, and Fahrenheit.

A count unit’s size ends with “par pièce” in place of “each” and “au total” in place of “total”.

nl

TypeScript
const nl: LabelPack

Dutch words, with language: 'nl'.

Unit Short Long Aliases
mg mg milligram —
g g gram gr
kg kg kilogram —
ml ml milliliter —
cl cl centiliter —
dl dl deciliter —
l l liter —
tsp tl theelepel / theelepels —
tbsp el eetlepel / eetlepels —
pinch snufje / snufjes As short snuifje
dash scheutje / scheutjes As short —
clove teen / tenen As short teentje, teentjes
slice plakje / plakjes As short plak, plakken
piece stuk / stuks As short —
can blikje / blikjes As short —
package pak / pakken As short —
stick stengel / stengels As short —
sprig takje / takjes As short —
bunch bosje / bosjes As short —
head krop / kroppen As short —
Duration Short Long
day dag / dagen dag / dagen
hour uur uur
minute min minuut / minuten
second s seconde / seconden

In unitDisplay: 'long', temperatures use graad / graden, Celsius, and Fahrenheit.

A count unit’s size ends with “per stuk” in place of “each” and “in totaal” in place of “total”.

sv

TypeScript
const sv: LabelPack

Swedish words, with language: 'sv'.

Unit Short Long Aliases
mg mg milligram —
g g gram —
kg kg kilogram —
ml ml milliliter krm
cl cl centiliter —
dl dl deciliter —
l l liter —
tsp tsk tesked / teskedar —
tbsp msk matsked / matskedar —
pinch nypa / nypor As short —
dash skvätt / skvättar As short —
clove klyfta / klyftor As short —
slice skiva / skivor As short —
piece st styck —
can burk / burkar As short —
package pkt paket —
stick stång / stänger As short —
sprig kvist / kvistar As short —
bunch knippe / knippen As short —
head huvud / huvuden As short —
Duration Short Long
day dag / dagar dag / dagar
hour tim timme / timmar
minute min minut / minuter
second sek sekund / sekunder

In unitDisplay: 'long', temperatures use grad / grader, Celsius, and Fahrenheit.

A count unit’s size ends with “per styck” in place of “each” and “totalt” in place of “total”.

da

TypeScript
const da: LabelPack

Danish words, with language: 'da'.

Unit Short Long Aliases
mg mg milligram —
g g gram —
kg kg kilogram —
ml ml milliliter —
cl cl centiliter —
dl dl deciliter —
l l liter —
tsp tsk teske / teskeer —
tbsp spsk spiseske / spiseskeer —
pinch nip As short —
dash stænk As short —
clove fed As short —
slice skive / skiver As short —
piece stk. stykke / stykker —
can dåse / dåser As short ds
package pakke / pakker As short —
stick stang / stænger As short —
sprig kvist / kviste As short —
bunch bundt / bundter As short —
head hoved / hoveder As short —
Duration Short Long
day dag / dage dag / dage
hour t. time / timer
minute min. minut / minutter
second sek. sekund / sekunder

In unitDisplay: 'long', temperatures use grad / grader, celsius, and fahrenheit.

A count unit’s size ends with “pr. stk.” in place of “each” and “i alt” in place of “total”.

nb

TypeScript
const nb: LabelPack

Norwegian Bokmål words, with language: 'nb'.

Unit Short Long Aliases
mg mg milligram —
g g gram —
kg kg kilogram —
ml ml milliliter —
cl cl centiliter —
dl dl desiliter —
l l liter —
tsp ts teskje / teskjeer —
tbsp ss spiseskje / spiseskjeer —
pinch klype / klyper As short —
dash skvett / skvetter As short —
clove fedd As short —
slice skive / skiver As short —
piece stk stykke / stykker —
can boks / bokser As short —
package pk pakke / pakker —
stick stang / stenger As short —
sprig kvist / kvister As short —
bunch bunt / bunter As short —
head hode / hoder As short —
Duration Short Long
day dag / dager dag / dager
hour t time / timer
minute min minutt / minutter
second s sekund / sekunder

In unitDisplay: 'long', temperatures use grad / grader, celsius, and fahrenheit.

A count unit’s size ends with “per stk” in place of “each” and “totalt” in place of “total”.

it

TypeScript
const it: LabelPack

Italian words, with language: 'it'.

Unit Short Long Aliases
mg mg milligrammo / milligrammi —
g g grammo / grammi gr
kg kg chilogrammo / chilogrammi —
ml ml millilitro / millilitri —
cl cl centilitro / centilitri —
dl dl decilitro / decilitri —
l l litro / litri —
tsp cucchiaino / cucchiaini As short —
tbsp cucchiaio / cucchiai As short —
pinch pizzico / pizzichi As short —
dash spruzzo / spruzzi As short —
clove spicchio / spicchi As short —
slice fetta / fette As short —
piece pezzo / pezzi As short —
can lattina / lattine As short —
package bustina / bustine As short —
stick stecca / stecche As short —
sprig rametto / rametti As short —
bunch mazzetto / mazzetti As short —
head testa / teste As short —
Duration Short Long
day giorno / giorni giorno / giorni
hour h ora / ore
minute min minuto / minuti
second s secondo / secondi

In unitDisplay: 'long', temperatures use grado / gradi, Celsius, and Fahrenheit.

A count unit’s size ends with “al pezzo” in place of “each” and “in totale” in place of “total”.

es

TypeScript
const es: LabelPack

Spanish words, with language: 'es'.

Unit Short Long Aliases
mg mg miligramo / miligramos —
g g gramo / gramos gr
kg kg kilogramo / kilogramos —
ml ml mililitro / mililitros —
cl cl centilitro / centilitros —
dl dl decilitro / decilitros —
l l litro / litros —
tsp cucharadita / cucharaditas As short —
tbsp cucharada / cucharadas As short —
pinch pizca / pizcas As short —
dash chorrito / chorritos As short —
clove diente / dientes As short —
slice rodaja / rodajas As short —
piece trozo / trozos As short —
can lata / latas As short —
package sobre / sobres As short —
stick stick / sticks As short —
sprig ramita / ramitas As short —
bunch manojo / manojos As short —
head cabeza / cabezas As short —
Duration Short Long
day día / días día / días
hour h hora / horas
minute min minuto / minutos
second s segundo / segundos

In unitDisplay: 'long', temperatures use grado / grados, Celsius, and Fahrenheit.

A count unit’s size ends with “por unidad” in place of “each” and “en total” in place of “total”.

Contents