Skip to content

Multi-Language Display Terms

BabelFHIR-TS supports generating localized display strings for ValueSet codes using a terminology server's $expand operation.

Usage

Use --display-language together with --tx-server:

bash
# Single language — replaces all concept displays with German terms
babelfhir-ts install hl7.fhir.us.core@8.0.0 \
  --tx-server https://tx.fhir.org/r4 \
  --display-language de

# Multiple languages — generates a display map with getDisplay() helper
babelfhir-ts install hl7.fhir.us.core@8.0.0 \
  --tx-server https://tx.fhir.org/r4 \
  --display-language de,fr,en

How It Works

Single Language

When a single language code is provided (e.g., de), the terminology server is queried with that language preference. All concept display values in the generated ValueSet modules are replaced with the localized version.

Multiple Languages

When comma-separated language codes are provided (e.g., de,fr,en):

  1. The first language is used as the primary display language
  2. A multi-language display map is generated for each ValueSet
  3. A getDisplay() helper function is generated

The tx server is queried once per language. Translations that are identical to the canonical (English) display are filtered out — this means the tx server didn't have a real translation for that code.

Generated Output

Display Map

Each ValueSet with translations gets an additional export:

ts
/** Multi-language display translations */
export const AdministrativeGenderDisplays: Record<string, Record<string, string>> = {
  "male": { "de": "Männlich", "fr": "Masculin" },
  "female": { "de": "Weiblich", "fr": "Féminin" },
  "other": { "de": "Anderes", "fr": "Autre" },
  "unknown": { "de": "Unbekannt", "fr": "Inconnu" },
};

getDisplay() Helper

ts
import {
  getAdministrativeGenderDisplay,
  AdministrativeGenderDisplays,
} from "my-ig-generated/valuesets/ValueSet-AdministrativeGender";

// Get a single translation
const label = getAdministrativeGenderDisplay("male", "de"); // "Männlich"

// Access the full map
const allTranslations = AdministrativeGenderDisplays["female"];
// { de: "Weiblich", fr: "Féminin" }

Requirements

  • A terminology server (--tx-server) is required — translations come from the server's $expand response
  • Language codes must be BCP-47 formatted (e.g., de, fr, en-US)
  • Not all ValueSets have translations — the tx server may return English for languages it doesn't support

INFO

The --display-language setting is stored in the generated package's metadata (see Package Metadata) and is automatically reused by babelfhir-ts update.

Released under the ISC License.