Language definition structure
A language definition is an object that conforms to theLanguageDefinition interface:
Required properties
decimal
The decimal separator the language uses.
- Use
'.'for English, Chinese, etc. - Use
','for German, Italian, French, etc.
units
Definitions for all time units in the language. Must include all units:
nanosecond, microsecond, millisecond, second, minute, hour, day, week, month, year, decade, century, millennium.name
name
The full name of the unit. Can be a string or a function that returns different forms based on count (for pluralization).
abbreviation
abbreviation
The abbreviated form of the unit. Can be a string or a function. Omitting this will cause errors if you use
useAbbreviations: true.matches
matches
Array of lowercase strings to match when parsing duration strings. Should include the full name, plural forms, abbreviations, and common variations.
Optional properties
and
The word to use for “and” in formatted output. Omitting this will cause errors if you use
insertAnd: true (if that option exists in your version).Creating a custom language
Here’s a complete example of creating a custom language definition:Real-world example: German
Here’s how you might create a German language definition:Using built-in languages
Enhanced MS includes built-in support for several languages. Instead of creating a custom definition, you can use a language key:Contributing languages
If you create a language definition for a language that isn’t supported, consider contributing it to the project! You can make a pull request at the Enhanced MS repository.Type information
Language definition types are located insrc/languages/helpers/definition-types.ts:3. The English language definition in src/languages/en.ts:1 serves as a good reference implementation.