Skip to main content
Enhanced MS supports multiple languages for formatting and parsing durations. You can use built-in languages or create custom language definitions.

Supported languages

The following languages are currently supported:
LanguageKey
English (default)en
Germande
Russianru
Māorimi
Spanishes
Dutchnl
Italianit
Frenchfr
Czechcs
Polishpl
Chinese (Simplified)zh-CN

languages export

The languages object contains all built-in language definitions.
const languages: Record<Locale, LanguageDefinition> = {
  cs,
  de,
  en,
  es,
  fr,
  it,
  mi,
  nl,
  pl,
  ru,
  'zh-CN': zhCN,
};

Usage

You can import the languages object to access individual language definitions:
import { languages } from 'enhanced-ms';

// Get the English language definition
const english = languages.en;

// Get the German language definition
const german = languages.de;

Using languages

You can specify a language when creating an ms instance with createMs():
import { createMs } from 'enhanced-ms';

// Create a German instance
const ms = createMs({ language: 'de' });

ms(90061) // "1 Minute 30 Sekunden"
ms("1 Minute 30 Sekunden") // 90061

Formatting in different languages

import { createMs } from 'enhanced-ms';

const enMs = createMs({ language: 'en' });
const frMs = createMs({ language: 'fr' });
const esMs = createMs({ language: 'es' });

enMs(90061) // "1 minute 30 seconds"
frMs(90061) // "1 minute 30 secondes"
esMs(90061) // "1 minuto 30 segundos"

Parsing in different languages

import { createMs } from 'enhanced-ms';

const deMs = createMs({ language: 'de' });
const ruMs = createMs({ language: 'ru' });

deMs("1 Minute 30 Sekunden") // 90061
ruMs("1 минута 30 секунд") // 90061

Custom language definitions

You can create a custom language definition by implementing the LanguageDefinition interface:
import { createMs, type LanguageDefinition } from 'enhanced-ms';

const customLanguage: LanguageDefinition = {
  decimal: '.',
  and: 'and',
  units: {
    nanosecond: {
      name: (c) => c === 1 ? 'nanosecond' : 'nanoseconds',
      abbreviation: 'ns',
      matches: ['nanosecond', 'nanoseconds', 'ns'],
    },
    microsecond: {
      name: (c) => c === 1 ? 'microsecond' : 'microseconds',
      abbreviation: 'μs',
      matches: ['microsecond', 'microseconds', 'μs'],
    },
    millisecond: {
      name: (c) => c === 1 ? 'millisecond' : 'milliseconds',
      abbreviation: 'ms',
      matches: ['millisecond', 'milliseconds', 'ms'],
    },
    second: {
      name: (c) => c === 1 ? 'second' : 'seconds',
      abbreviation: 's',
      matches: ['second', 'seconds', 's', 'sec'],
    },
    minute: {
      name: (c) => c === 1 ? 'minute' : 'minutes',
      abbreviation: 'm',
      matches: ['minute', 'minutes', 'm', 'min'],
    },
    hour: {
      name: (c) => c === 1 ? 'hour' : 'hours',
      abbreviation: 'h',
      matches: ['hour', 'hours', 'h', 'hr'],
    },
    day: {
      name: (c) => c === 1 ? 'day' : 'days',
      abbreviation: 'd',
      matches: ['day', 'days', 'd'],
    },
    week: {
      name: (c) => c === 1 ? 'week' : 'weeks',
      abbreviation: 'w',
      matches: ['week', 'weeks', 'w', 'wk'],
    },
    month: {
      name: (c) => c === 1 ? 'month' : 'months',
      abbreviation: 'mo',
      matches: ['month', 'months', 'mo'],
    },
    year: {
      name: (c) => c === 1 ? 'year' : 'years',
      abbreviation: 'y',
      matches: ['year', 'years', 'y', 'yr'],
    },
    decade: {
      name: (c) => c === 1 ? 'decade' : 'decades',
      abbreviation: 'dec',
      matches: ['decade', 'decades', 'dec'],
    },
    century: {
      name: (c) => c === 1 ? 'century' : 'centuries',
      abbreviation: 'c',
      matches: ['century', 'centuries', 'c'],
    },
    millennium: {
      name: (c) => c === 1 ? 'millennium' : 'millennia',
      abbreviation: 'mil',
      matches: ['millennium', 'millennia', 'mil'],
    },
  },
};

const ms = createMs({ language: customLanguage });

Language definition structure

Each language definition must include:
decimal
'.' | ','
The decimal separator used in the language (e.g., '.' for English, ',' for German).
and
string | ((words: string[]) => string[])
The conjunction word or function used to join duration parts (e.g., 'and' for English, 'und' for German).
units
Record<Unit, LanguageUnitDefinition>
Definitions for all time units. Each unit must have:
  • name: String or function returning the unit name (with pluralization)
  • abbreviation: String or function returning the abbreviated form
  • matches: Array of lowercase strings used for parsing
See the LanguageDefinition type for complete details.

Contributing languages

We welcome contributions of new language support! To add a new language:
  1. Create a new file in the src/languages/ directory of the GitHub repository
  2. Follow the structure of existing language files (e.g., en.ts)
  3. Include all time units with proper translations
  4. Add parsing matches for common variations
  5. Submit a pull request
Your contribution will help make Enhanced MS accessible to more developers worldwide.

Build docs developers (and LLMs) love