@hebcal/core
    Preparing search index...

    Class Locale

    A locale in Hebcal is used for translations/transliterations of holidays. @hebcal/hdate supports four locales by default

    • en - default, Sephardic transliterations (e.g. "Shabbat")
    • ashkenazi - Ashkenazi transliterations (e.g. "Shabbos")
    • he - Hebrew (e.g. "שַׁבָּת")
    • he-x-NoNikud - Hebrew without nikud (e.g. "שבת")

    The locale set that ships here covers only what this package needs: month names, a handful of connective words, and the parts of speech used by HDate.render. Packages built on top of it (such as @hebcal/core) register their own holiday translations into the same locales with Locale.addTranslations.

    Every method is static — Locale is a namespace, not something you instantiate. Locale names are matched case-insensitively, and the single letters h, a and s are accepted as aliases for he, ashkenazi and en respectively.

    import {Locale, HDate, months} from '@hebcal/hdate';

    Locale.gettext('Cheshvan', 'he'); // 'חֶשְׁוָן'
    Locale.gettext('Cheshvan', 'ashkenazi'); // 'Cheshvan'
    Locale.ordinal(15, 'en'); // '15th'

    const hd = new HDate(15, months.CHESHVAN, 5769);
    hd.render('en'); // '15th of Cheshvan, 5769'
    hd.render('he'); // '15 חֶשְׁוָן, 5769'
    Index
    • Register locale translations, replacing the locale entirely if it was already registered. Use Locale.addTranslations to merge into an existing locale instead.

      Parameters

      • locale: string

        Locale name (i.e.: 'he', 'fr')

      • data: LocaleData

        parsed data from a .po file.

      Returns void

      if data is not in the compact .po format

      import {Locale} from '@hebcal/hdate';
      // typically `import poFr from './fr.po'` — inlined here for clarity
      const poFr = {headers: {}, contexts: {'': {Shabbat: ['Chabbat']}}};
      Locale.addLocale('fr', poFr);
      Locale.gettext('Shabbat', 'fr'); // 'Chabbat'
    • Adds a translation to locale, replacing any previous translation.

      Parameters

      • locale: string

        Locale name (i.e: 'he', 'fr').

      • id: string

        Message ID to translate

      • translation: string | string[]

        Translation text

      Returns void

      Locale.addTranslation('ashkenazi', 'Foobar', 'Quux');
      Locale.gettext('Foobar', 'ashkenazi'); // 'Quux'
    • Adds multiple translations to locale, replacing any previous translations.

      The locale must already be registered (typically via addLocale); to register a brand-new locale instead, call addLocale directly. Use this method to merge an additional .po file (e.g. holiday translations supplied by a separate @hebcal/* package) into an existing locale.

      Parameters

      • locale: string

        Locale name (i.e: 'he', 'fr').

      • data: LocaleData

        parsed data from a .po file.

      Returns void

      if locale has not been registered

      if data is not in the compact .po format

      import {Locale} from '@hebcal/hdate';
      Locale.addTranslations('ashkenazi', {
      headers: {},
      contexts: {'': {Sukkot: ['Sukkos'], Shavuot: ['Shavuos']}},
      });
      Locale.gettext('Sukkot', 'ashkenazi'); // 'Sukkos'
      Locale.gettext('Tevet', 'ashkenazi'); // 'Teves' (existing translations kept)
    • Returns a new LocaleData derived from data with niqqud (vowel points) stripped from every translation value. The input is not modified.

      This is the helper used internally to build the he-x-NoNikud locale from he; call it when registering a derived "no nikud" variant of a custom Hebrew-script locale.

      Parameters

      Returns LocaleData

      a new LocaleData with niqqud removed

      import {Locale} from '@hebcal/hdate';
      const withNikud = {
      headers: {},
      contexts: {'': {Elul: ['אֱלוּל']}},
      };
      const stripped = Locale.copyLocaleNoNikud(withNikud);
      stripped.contexts[''].Elul[0]; // 'אלול'
      withNikud.contexts[''].Elul[0]; // 'אֱלוּל' (input unchanged)
    • Returns the names of registered locales

      Returns string[]

      Locale.getLocaleNames(); // ['ashkenazi', 'en', 'he', 'he-x-nonikud']
      
    • By default, if no translation was found, returns id.

      Parameters

      • id: string

        Message ID to translate

      • Optionallocale: string

        Optional locale name (i.e: 'he', 'fr'). Defaults to no-op locale.

      Returns string

      Locale.gettext('Elul', 'he');          // 'אֱלוּל'
      Locale.gettext('Tevet', 'ashkenazi'); // 'Teves'
      Locale.gettext('Unknown', 'he'); // 'Unknown' (falls back to id)
    • Checks whether a locale has been registered

      Parameters

      • locale: string

        Locale name (i.e: 'he', 'fr').

      Returns boolean

      Locale.hasLocale('he'); // true
      Locale.hasLocale('fr'); // false
    • Removes nekudot from Hebrew string

      Parameters

      • str: string

      Returns string

      Locale.hebrewStripNikkud('אֱלוּל'); // 'אלול'
      
    • Returns true if locale is a Hebrew locale (i.e. he or he-x-NoNikud)

      Parameters

      • Optionallocale: string

      Returns boolean

      Locale.isHebrewLocale('he');           // true
      Locale.isHebrewLocale('he-x-NoNikud'); // true
      Locale.isHebrewLocale('en'); // false
    • Returns translation only if locale offers a non-empty translation for id. Otherwise, returns undefined.

      Parameters

      • id: string

        Message ID to translate

      • Optionallocale: string

        Optional locale name (i.e: 'he', 'fr'). Defaults to no-op locale.

      Returns string | undefined

      Locale.lookupTranslation('Adar II', 'he-x-NoNikud'); // 'אדר ב׳'
      Locale.lookupTranslation('Foobar', 'he-x-NoNikud'); // undefined
    • Renders a number in ordinal, such as 1st, 2nd or 3rd

      Parameters

      • n: number
      • Optionallocale: string

        Optional locale name (i.e: 'he', 'fr'). Defaults to no-op locale.

      Returns string

      Locale.ordinal(3, 'en'); // '3rd'
      Locale.ordinal(3, 'es'); // '3º'
      Locale.ordinal(3, 'fr'); // '3.'
      Locale.ordinal(3, 'he'); // '3'