UNPKG

@hebcal/hdate

Version:

converts between Hebrew and Gregorian dates using Rata Die (R.D.) algorithm by Dershowitz and Reingold

120 lines (119 loc) 4.87 kB
export interface Headers { 'content-type'?: string; 'plural-forms'?: string; } export type StringArrayMap = Record<string, string[]>; export interface LocaleData { headers: Headers; contexts: Record<string, StringArrayMap>; } /** * 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. "שבת") */ export declare class Locale { /** * Returns translation only if `locale` offers a non-empty translation for `id`. * Otherwise, returns `undefined`. * @param id Message ID to translate * @param [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to no-op locale. * @example * Locale.lookupTranslation('Adar II', 'he-x-NoNikud'); // 'אדר ב׳' * Locale.lookupTranslation('Foobar', 'he-x-NoNikud'); // undefined */ static lookupTranslation(id: string, locale?: string): string | undefined; /** * By default, if no translation was found, returns `id`. * @param id Message ID to translate * @param [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to no-op locale. * @example * Locale.gettext('Elul', 'he'); // 'אֱלוּל' * Locale.gettext('Tevet', 'ashkenazi'); // 'Teves' * Locale.gettext('Unknown', 'he'); // 'Unknown' (falls back to id) */ static gettext(id: string, locale?: string): string; /** * Register locale translations. * @param locale Locale name (i.e.: `'he'`, `'fr'`) * @param data parsed data from a `.po` file. * @example * import poFr from './fr.po'; * Locale.addLocale('fr', poFr); * Locale.gettext('Shabbat', 'fr'); // 'Chabbat' */ static addLocale(locale: string, data: LocaleData): void; /** * Adds a translation to `locale`, replacing any previous translation. * @param locale Locale name (i.e: `'he'`, `'fr'`). * @param id Message ID to translate * @param translation Translation text * @example * Locale.addTranslation('ashkenazi', 'Foobar', 'Quux'); * Locale.gettext('Foobar', 'ashkenazi'); // 'Quux' */ static addTranslation(locale: string, id: string, translation: string | string[]): void; /** * 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. * @param locale Locale name (i.e: `'he'`, `'fr'`). * @param data parsed data from a `.po` file. */ static addTranslations(locale: string, data: LocaleData): void; /** * Returns the names of registered locales * @example * Locale.getLocaleNames(); // ['ashkenazi', 'en', 'he', 'he-x-nonikud'] */ static getLocaleNames(): string[]; /** * Checks whether a locale has been registered * @param locale Locale name (i.e: `'he'`, `'fr'`). * @example * Locale.hasLocale('he'); // true * Locale.hasLocale('fr'); // false */ static hasLocale(locale: string): boolean; /** * Renders a number in ordinal, such as 1st, 2nd or 3rd * @param [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to no-op locale. * @example * Locale.ordinal(3, 'en'); // '3rd' * Locale.ordinal(3, 'es'); // '3º' * Locale.ordinal(3, 'fr'); // '3.' * Locale.ordinal(3, 'he'); // '3' */ static ordinal(n: number, locale?: string): string; /** * Removes nekudot from Hebrew string * @example * Locale.hebrewStripNikkud('אֱלוּל'); // 'אלול' */ static hebrewStripNikkud(str: string): string; /** * 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. */ static copyLocaleNoNikud(data: LocaleData): LocaleData; /** * Returns true if `locale` is a Hebrew locale (i.e. `he` or `he-x-NoNikud`) * @example * Locale.isHebrewLocale('he'); // true * Locale.isHebrewLocale('he-x-NoNikud'); // true * Locale.isHebrewLocale('en'); // false */ static isHebrewLocale(locale?: string): boolean; }