German Deutsch

BCP 47 language tag: de

Lokalized supports cardinality, cardinality range, and ordinality rules for German.

Additional modeled concepts for German: grammatical gender; grammatical case.

German is most often spoken in Germany, the Netherlands, Austria, Poland, and Switzerland.

Cardinalities

  • CARDINALITY_ONE

    Matches i = 1 and v = 0

    Example Integers: 1

  • CARDINALITY_OTHER

    Matches all other values

    Example Integers: 0, 2, 16, 100, 1000, 10000, 100000, 1000000, …

    Example Decimals: 0.0, 1.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …

Cardinality example

This localized strings file selects the localized form of “day” for a delivery estimate. Raw numbers choose the CLDR category; values formatted for display are interpolated.

Sample localized strings file
de.json Localized Strings File (German)
{
  "Delivery.LeadTime": {
    "commentary": "Estimated delivery time, expressed in days.",
    "translation": "{{leadTime}}",
    "placeholders": {
      "leadTime": {
        "value": "dayCount",
        "translations": {
          "CARDINALITY_ONE": "{{formattedDayCount}} Tag",
          "CARDINALITY_OTHER": "{{formattedDayCount}} Tage"
        }
      }
    }
  }
}
Usage and expected results

JavaScript

The JavaScript code passes each raw number for cardinality selection and formats its display value separately with Intl.NumberFormat.

import { cardinalityForNumber, createStrings } from "lokalized";
import { readStringsFromDirectory } from "lokalized/node";

const locale = "de";

const strings = createStrings({
  localizedStringSupplier: () => readStringsFromDirectory("strings").catalogs,
  fallbackLocale: locale,
  localeSupplier: () => locale,
});

const numberFormat = new Intl.NumberFormat(locale);

// Raw numbers select language forms; Intl.NumberFormat produces the display values

// CARDINALITY_ONE
const oneDayCount = 1;
const oneFormattedDayCount = numberFormat.format(oneDayCount);

cardinalityForNumber(oneDayCount, locale).name;   // => "CARDINALITY_ONE"
strings.get("Delivery.LeadTime", {
  dayCount: oneDayCount,
  formattedDayCount: oneFormattedDayCount,
});   // => "1 Tag"

// CARDINALITY_OTHER
const otherDayCount = 0;
const otherFormattedDayCount = numberFormat.format(otherDayCount);

cardinalityForNumber(otherDayCount, locale).name;   // => "CARDINALITY_OTHER"
strings.get("Delivery.LeadTime", {
  dayCount: otherDayCount,
  formattedDayCount: otherFormattedDayCount,
});   // => "0 Tage"

Java

The Java code passes each raw number for cardinality selection and formats its display value separately with NumberFormat.

Locale locale = Locale.forLanguageTag("de");

Strings strings = Strings.withFallbackLocale(locale)
  .localizedStringSupplier(() -> LocalizedStringLoader.loadFromFilesystem(Paths.get("strings")))
  .localeSupplier((matcher) -> matcher.bestMatchFor(locale))
  .build();

NumberFormat numberFormat = NumberFormat.getNumberInstance(locale);

// Raw numbers select language forms; NumberFormat produces the display values

// CARDINALITY_ONE
Number oneDayCount = 1;
String oneFormattedDayCount = numberFormat.format(oneDayCount);

assertEquals(Cardinality.ONE, Cardinality.forNumber(oneDayCount, locale));

// Expected: 1 Tag
assertEquals(oneFormattedDayCount + " Tag", strings.get(
  "Delivery.LeadTime", Map.of("dayCount", oneDayCount, "formattedDayCount", oneFormattedDayCount)
));

// CARDINALITY_OTHER
Number otherDayCount = 0;
String otherFormattedDayCount = numberFormat.format(otherDayCount);

assertEquals(Cardinality.OTHER, Cardinality.forNumber(otherDayCount, locale));

// Expected: 0 Tage
assertEquals(otherFormattedDayCount + " Tage", strings.get(
  "Delivery.LeadTime", Map.of("dayCount", otherDayCount, "formattedDayCount", otherFormattedDayCount)
));

Swift

Swift uses pinned CLDR rules for raw numeric values. The display strings in these assertions are fixed examples; applications format display values separately with Foundation. Default .rtlLocales bidi isolation adds FSI/PDI to interpolated values in right-to-left output.

import Foundation
import Lokalized

let locale = try LocaleTag("de")
let files = try LocalizedStringLoader.loadFromDirectory(URL(fileURLWithPath: "strings"))
let catalogs = files.mapValues { LocalizedCatalog(strings: $0.strings) }

let strings = try DefaultStrings(configuration: StringsConfiguration(
  localizedStringSupplier: { catalogs }, localeSupplier: { _ in locale },
  fallbackLocale: locale
))

// CARDINALITY_ONE
let number1 = try NumericValue.forDecimal("1")
let category1 = try Cardinality.forNumber(number1, locale: locale.tag)
assert(category1 == .one)
// This fixed display value makes the translation assertion reproducible.
let display1 = "1"
let message1 = try strings.get("Delivery.LeadTime", placeholders: [
  "dayCount": .number(number1),
  "formattedDayCount": .text(display1),
])
assert(ExactString(message1) == ExactString("1 Tag"))

// CARDINALITY_OTHER
let number2 = try NumericValue.forDecimal("0")
let category2 = try Cardinality.forNumber(number2, locale: locale.tag)
assert(category2 == .other)
// This fixed display value makes the translation assertion reproducible.
let display2 = "0"
let message2 = try strings.get("Delivery.LeadTime", placeholders: [
  "dayCount": .number(number2),
  "formattedDayCount": .text(display2),
])
assert(ExactString(message2) == ExactString("0 Tage"))

Cardinality Ranges

These are CLDR's explicit range mappings. For any start/end pair not listed, the range falls back to the ending cardinality.

  • CARDINALITY_ONE - CARDINALITY_OTHER

    Matches CARDINALITY_OTHER

  • CARDINALITY_OTHER - CARDINALITY_ONE

    Matches CARDINALITY_ONE

  • CARDINALITY_OTHER - CARDINALITY_OTHER

    Matches CARDINALITY_OTHER

Cardinality range example

The start and end cardinalities select the locale's CLDR range result. The selected form wraps a separately formatted display range.

Sample localized strings file
de.json Localized Strings File (German)
{
  "Delivery.Window": {
    "commentary": "Estimated delivery window, expressed as a range of days.",
    "translation": "{{window}}",
    "placeholders": {
      "window": {
        "range": {
          "start": "minDays",
          "end": "maxDays"
        },
        "translations": {
          "CARDINALITY_ONE": "{{formattedDayRange}} Tag",
          "CARDINALITY_OTHER": "{{formattedDayRange}} Tage"
        }
      }
    }
  }
}
Usage and expected results

JavaScript

The JavaScript code passes raw range endpoints for selection, formats both endpoints separately with Intl.NumberFormat, and joins them for display; choose range punctuation appropriate to your application. Range rules are an optional import, lokalized/data/ranges.

import { cardinalityForNumber, createStrings } from "lokalized";
import { cardinalRangeData, cardinalityForRange } from "lokalized/data/ranges";
import { readStringsFromDirectory } from "lokalized/node";

const locale = "de";

const strings = createStrings({
  localizedStringSupplier: () => readStringsFromDirectory("strings").catalogs,
  fallbackLocale: locale,
  localeSupplier: () => locale,
  pluralData: { ranges: cardinalRangeData },
});

const numberFormat = new Intl.NumberFormat(locale);

// Raw numbers select language forms; Intl.NumberFormat produces the display values

// CARDINALITY_OTHER range
const minDays = 1;
const formattedMinDays = numberFormat.format(minDays);
const maxDays = 2;
const formattedMaxDays = numberFormat.format(maxDays);
const formattedDayRange = formattedMinDays + "-" + formattedMaxDays;

cardinalityForRange(
  cardinalityForNumber(minDays, locale),
  cardinalityForNumber(maxDays, locale),
  locale
).name;   // => "CARDINALITY_OTHER"
strings.get("Delivery.Window", { minDays, maxDays, formattedDayRange });   // => "1-2 Tage"

Java

The Java code passes raw range endpoints for selection. Because NumberFormat formats one number at a time, it formats both endpoints separately and joins them for display; choose range punctuation appropriate to your application.

Locale locale = Locale.forLanguageTag("de");

Strings strings = Strings.withFallbackLocale(locale)
  .localizedStringSupplier(() -> LocalizedStringLoader.loadFromFilesystem(Paths.get("strings")))
  .localeSupplier((matcher) -> matcher.bestMatchFor(locale))
  .build();

NumberFormat numberFormat = NumberFormat.getNumberInstance(locale);

// Raw numbers select language forms; NumberFormat produces the display values

// CARDINALITY_OTHER range
Number minDays = 1;
String formattedMinDays = numberFormat.format(minDays);
Number maxDays = 2;
String formattedMaxDays = numberFormat.format(maxDays);
String formattedDayRange = formattedMinDays + "-" + formattedMaxDays;

assertEquals(Cardinality.OTHER, Cardinality.forRange(
  Cardinality.forNumber(minDays, locale),
  Cardinality.forNumber(maxDays, locale),
  locale
));

// Expected: 1-2 Tage
assertEquals(formattedDayRange + " Tage", strings.get(
  "Delivery.Window",
  Map.of("minDays", minDays, "maxDays", maxDays, "formattedDayRange", formattedDayRange)
));

Swift

Swift uses pinned CLDR rules for raw numeric values. The display strings in these assertions are fixed examples; applications format display values separately with Foundation. Default .rtlLocales bidi isolation adds FSI/PDI to interpolated values in right-to-left output.

import Foundation
import Lokalized

let locale = try LocaleTag("de")
let files = try LocalizedStringLoader.loadFromDirectory(URL(fileURLWithPath: "strings"))
let catalogs = files.mapValues { LocalizedCatalog(strings: $0.strings) }

let strings = try DefaultStrings(configuration: StringsConfiguration(
  localizedStringSupplier: { catalogs }, localeSupplier: { _ in locale },
  fallbackLocale: locale
))

let start = try NumericValue.forDecimal("1")
let end = try NumericValue.forDecimal("2")
let startForm = try Cardinality.forNumber(start, locale: locale.tag)
let endForm = try Cardinality.forNumber(end, locale: locale.tag)
let rangeForm = try Cardinality.forRange(startForm, endForm, locale: locale.tag)
assert(rangeForm == .other)
let message1 = try strings.get("Delivery.Window", placeholders: [
  "minDays": .number(start),
  "maxDays": .number(end),
  "formattedDayRange": .text("1-2"),
])
assert(ExactString(message1) == ExactString("1-2 Tage"))

Ordinalities

All ordinal numbers use ORDINALITY_OTHER; no value selects a different form.

Example: 2. Abzweigung nach rechts nehmen.

Language-Specific Examples

These examples show how Lokalized models grammatical choices and translation behavior that commonly affect German application copy. Each example identifies the Lokalized language forms and other library features it uses.

One brand name with three accepted genders

Duden accepts Nutella as feminine, neuter, or masculine. Passing a German article preference selects the corresponding complete noun phrase while the referent stays the same.

Language reference: Duden - Nutella with three accepted genders

Language forms used: gender

Sample localized strings file
de.json Localized Strings File (German)
{
  "Where is the Nutella?": {
    "translation": "Wo ist {{nutella}}?",
    "placeholders": {
      "nutella": {
        "value": "articlePreference",
        "translations": {
          "GENDER_FEMININE": "die Nutella",
          "GENDER_NEUTER": "das Nutella",
          "GENDER_MASCULINE": "der Nutella"
        }
      }
    }
  }
}
Usage and expected results

JavaScript

import { GENDER_FEMININE, GENDER_MASCULINE, GENDER_NEUTER, createStrings } from "lokalized";
import { readStringsFromDirectory } from "lokalized/node";

const locale = "de";

const strings = createStrings({
  localizedStringSupplier: () => readStringsFromDirectory("strings").catalogs,
  fallbackLocale: locale,
  localeSupplier: () => locale,
});

strings.get("Where is the Nutella?", { articlePreference: GENDER_FEMININE });   // => "Wo ist die Nutella?"
strings.get("Where is the Nutella?", { articlePreference: GENDER_NEUTER });   // => "Wo ist das Nutella?"
strings.get("Where is the Nutella?", { articlePreference: GENDER_MASCULINE });   // => "Wo ist der Nutella?"

Java

Locale locale = Locale.forLanguageTag("de");

Strings strings = Strings.withFallbackLocale(locale)
  .localizedStringSupplier(() -> LocalizedStringLoader.loadFromFilesystem(Paths.get("strings")))
  .localeSupplier((matcher) -> matcher.bestMatchFor(locale))
  .build();

assertEquals("Wo ist die Nutella?", strings.get(
  "Where is the Nutella?", Map.of("articlePreference", Gender.FEMININE)
));

assertEquals("Wo ist das Nutella?", strings.get(
  "Where is the Nutella?", Map.of("articlePreference", Gender.NEUTER)
));

assertEquals("Wo ist der Nutella?", strings.get(
  "Where is the Nutella?", Map.of("articlePreference", Gender.MASCULINE)
));

Swift

Swift uses pinned CLDR rules for raw numeric values. The display strings in these assertions are fixed examples; applications format display values separately with Foundation. Default .rtlLocales bidi isolation adds FSI/PDI to interpolated values in right-to-left output.

import Foundation
import Lokalized

let locale = try LocaleTag("de")
let files = try LocalizedStringLoader.loadFromDirectory(URL(fileURLWithPath: "strings"))
let catalogs = files.mapValues { LocalizedCatalog(strings: $0.strings) }

let strings = try DefaultStrings(configuration: StringsConfiguration(
  localizedStringSupplier: { catalogs }, localeSupplier: { _ in locale },
  fallbackLocale: locale
))

let message1 = try strings.get("Where is the Nutella?", placeholders: [
  "articlePreference": .languageForm(.gender(.feminine)),
])
assert(ExactString(message1) == ExactString("Wo ist die Nutella?"))

let message2 = try strings.get("Where is the Nutella?", placeholders: [
  "articlePreference": .languageForm(.gender(.neuter)),
])
assert(ExactString(message2) == ExactString("Wo ist das Nutella?"))

let message3 = try strings.get("Where is the Nutella?", placeholders: [
  "articlePreference": .languageForm(.gender(.masculine)),
])
assert(ExactString(message3) == ExactString("Wo ist der Nutella?"))

One noun across four grammatical cases

One reusable localized noun phrase carries all four forms of the masculine noun Kunde. Passing the grammatical case selects the complete article-and-noun phrase without duplicating partial maps across sentence keys.

Language reference: Duden - the four German cases

Language forms used: grammatical case

Sample localized strings file
de.json Localized Strings File (German)
{
  "Customer": {
    "translation": "{{customer}}",
    "placeholders": {
      "customer": {
        "value": "grammaticalCase",
        "translations": {
          "CASE_NOMINATIVE": "der Kunde",
          "CASE_ACCUSATIVE": "den Kunden",
          "CASE_DATIVE": "dem Kunden",
          "CASE_GENITIVE": "des Kunden"
        }
      }
    }
  }
}
Usage and expected results

JavaScript

import { CASE_ACCUSATIVE, CASE_DATIVE, CASE_GENITIVE, CASE_NOMINATIVE, createStrings } from "lokalized";
import { readStringsFromDirectory } from "lokalized/node";

const locale = "de";

const strings = createStrings({
  localizedStringSupplier: () => readStringsFromDirectory("strings").catalogs,
  fallbackLocale: locale,
  localeSupplier: () => locale,
});

strings.get("Customer", { grammaticalCase: CASE_NOMINATIVE });   // => "der Kunde"
strings.get("Customer", { grammaticalCase: CASE_ACCUSATIVE });   // => "den Kunden"
strings.get("Customer", { grammaticalCase: CASE_DATIVE });   // => "dem Kunden"
strings.get("Customer", { grammaticalCase: CASE_GENITIVE });   // => "des Kunden"

Java

Locale locale = Locale.forLanguageTag("de");

Strings strings = Strings.withFallbackLocale(locale)
  .localizedStringSupplier(() -> LocalizedStringLoader.loadFromFilesystem(Paths.get("strings")))
  .localeSupplier((matcher) -> matcher.bestMatchFor(locale))
  .build();

assertEquals("der Kunde", strings.get(
  "Customer", Map.of("grammaticalCase", GrammaticalCase.NOMINATIVE)
));

assertEquals("den Kunden", strings.get(
  "Customer", Map.of("grammaticalCase", GrammaticalCase.ACCUSATIVE)
));

assertEquals("dem Kunden", strings.get(
  "Customer", Map.of("grammaticalCase", GrammaticalCase.DATIVE)
));

assertEquals("des Kunden", strings.get(
  "Customer", Map.of("grammaticalCase", GrammaticalCase.GENITIVE)
));

Swift

Swift uses pinned CLDR rules for raw numeric values. The display strings in these assertions are fixed examples; applications format display values separately with Foundation. Default .rtlLocales bidi isolation adds FSI/PDI to interpolated values in right-to-left output.

import Foundation
import Lokalized

let locale = try LocaleTag("de")
let files = try LocalizedStringLoader.loadFromDirectory(URL(fileURLWithPath: "strings"))
let catalogs = files.mapValues { LocalizedCatalog(strings: $0.strings) }

let strings = try DefaultStrings(configuration: StringsConfiguration(
  localizedStringSupplier: { catalogs }, localeSupplier: { _ in locale },
  fallbackLocale: locale
))

let message1 = try strings.get("Customer", placeholders: [
  "grammaticalCase": .languageForm(.grammaticalCase(.nominative)),
])
assert(ExactString(message1) == ExactString("der Kunde"))

let message2 = try strings.get("Customer", placeholders: [
  "grammaticalCase": .languageForm(.grammaticalCase(.accusative)),
])
assert(ExactString(message2) == ExactString("den Kunden"))

let message3 = try strings.get("Customer", placeholders: [
  "grammaticalCase": .languageForm(.grammaticalCase(.dative)),
])
assert(ExactString(message3) == ExactString("dem Kunden"))

let message4 = try strings.get("Customer", placeholders: [
  "grammaticalCase": .languageForm(.grammaticalCase(.genitive)),
])
assert(ExactString(message4) == ExactString("des Kunden"))

Addendum: Language Form Rules

The language form expressions above are specified by Unicode Technical Standard #35 and use the following notation:

  • n absolute value of the source number (integer and decimals)
  • i integer digits of n
  • v number of visible fraction digits in n, with trailing zeros
  • w number of visible fraction digits in n, without trailing zeros
  • f visible fractional digits in n, with trailing zeros
  • t visible fractional digits in n, without trailing zeros
  • c/e compact decimal exponent operands used by some CLDR compact-number rules