Skip to content

Languages ​

Introduction ​

nepdate includes English (en) and Nepali (ne). A locale covers digits, month and weekday names, button labels, shortcut names and error messages.

ts
import { bsDate, formatDate } from '@nepdatejs/core';

const date = bsDate(2083, 7, 1);

formatDate(date, 'full', 'en'); // → 'Sunday, 1 Kartik 2083'
formatDate(date, 'full', 'ne'); // → 'आइतबार, १ कार्तिक २०८३'

Choosing a language ​

For one call ​

Pass the locale as an argument, as above.

For the whole app ​

ts
import { configure } from '@nepdatejs/core';

configure({ defaultLocale: 'ne' });

For a component ​

Components take a locale option:

tsx
<DatePicker locale="ne" aria-label="मिति" />;
html
<nep-date-picker locale="ne"></nep-date-picker>

The React pickers also pick Nepali by themselves when the page has <html lang="ne">.

Month names ​

BS month names have more than one common spelling. nepdate uses these:

#EnglishNepaliRoughly
1BaisakhबैशाखApr–May
2JesthaजेठMay–Jun
3AsarअसारJun–Jul
4ShrawanसाउनJul–Aug
5BhadraभदौAug–Sep
6AshwinअसोजSep–Oct
7Kartikकार्तिकOct–Nov
8Mangsirमङ्सिरNov–Dec
9PoushपुसDec–Jan
10MaghमाघJan–Feb
11Falgunफाल्गुणFeb–Mar
12ChaitraचैतMar–Apr

To use different spellings, register a locale based on a built-in one, as shown next.

Adding or changing a language ​

registerLocale adds a language or replaces one. Start from an existing locale and change what you need:

ts
import { bsDate, formatDate, getLocale, registerLocale } from '@nepdatejs/core';

const en = getLocale('en');

registerLocale('en-school', {
  ...en,
  labels: { ...en.labels, today: 'Now' },
  months: {
    ...en.months,
    BS: {
      long: ['Baishakh', ...en.months.BS.long.slice(1)],
      short: en.months.BS.short,
    },
  },
});

formatDate(bsDate(2083, 1, 1), 'long', 'en-school'); // → '1 Baishakh 2083'

List lengths are checked: 10 digits, 7 weekdays and 12 months. A wrong length throws an error. A locale that hasn't been registered falls back to English.

What a locale contains ​

KeyContents
digitsTen digits, 0 to 9
monthsAD and BS, each with long and short lists
weekdayslong, short and narrow lists, starting on Sunday
calendarNamesThe names shown for AD and BS
labelsButton and field labels, such as today, clear and openCalendar
timeThe am and pm words
presetsNames of the built-in shortcuts
messagesValidation messages. {min} and {max} are filled in for you

Translating messages ​

Change any message the same way:

ts
import { getLocale, registerLocale } from '@nepdatejs/core';

const en = getLocale('en');

registerLocale('en', {
  ...en,
  messages: { ...en.messages, unavailable: 'Sorry, that day is closed.' },
});

getLocale('en').messages.unavailable; // → 'Sorry, that day is closed.'

Released under the MIT licence.