Skip to content

Commit

Permalink
feat(datepicker): add hebrew i18n
Browse files Browse the repository at this point in the history
Closes #2606
  • Loading branch information
maxokorokov authored and pkozlowski-opensource committed Aug 30, 2018
1 parent 71e39d9 commit 2d68122
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/datepicker/datepicker.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export {NgbCalendarIslamicCivil} from './hijri/ngb-calendar-islamic-civil';
export {NgbCalendarIslamicUmalqura} from './hijri/ngb-calendar-islamic-umalqura';
export {NgbCalendarPersian} from './jalali/ngb-calendar-persian';
export {NgbCalendarHebrew} from './hebrew/ngb-calendar-hebrew';
export {NgbDatepickerI18nHebrew} from './hebrew/datepicker-i18n-hebrew';
export {NgbDatepickerMonthView} from './datepicker-month-view';
export {NgbDatepickerDayView} from './datepicker-day-view';
export {NgbDatepickerNavigation} from './datepicker-navigation';
Expand Down
76 changes: 76 additions & 0 deletions src/datepicker/hebrew/datepicker-i18n-hebrew.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import {TestBed} from '@angular/core/testing';
import {NgbDate} from '../ngb-date';
import {NgbDatepickerI18nHebrew} from './datepicker-i18n-hebrew';

describe('datepicker-i18n-hebrew', () => {

let i18n: NgbDatepickerI18nHebrew;

beforeEach(() => {
TestBed.configureTestingModule({providers: [NgbDatepickerI18nHebrew]});
i18n = TestBed.get(NgbDatepickerI18nHebrew);
});

it('should return abbreviated month name', () => {
expect(i18n.getMonthShortName(0, 5778)).toBe(undefined);
expect(i18n.getMonthShortName(1, 5778)).toBe('תשרי');
expect(i18n.getMonthShortName(6, 5778)).toBe('אדר');
expect(i18n.getMonthShortName(7, 5778)).toBe('ניסן');
expect(i18n.getMonthShortName(12, 5778)).toBe('אלול');
expect(i18n.getMonthShortName(13, 5778)).toBe(undefined);
});

it('should return abbreviated month name (leap year)', () => {
expect(i18n.getMonthShortName(0, 5779)).toBe(undefined);
expect(i18n.getMonthShortName(1, 5779)).toBe('תשרי');
expect(i18n.getMonthShortName(6, 5779)).toBe('אדר א׳');
expect(i18n.getMonthShortName(7, 5779)).toBe('אדר ב׳');
expect(i18n.getMonthShortName(12, 5779)).toBe('אב');
expect(i18n.getMonthShortName(13, 5779)).toBe('אלול');
expect(i18n.getMonthShortName(14, 5779)).toBe(undefined);
});

it('should return wide month name', () => {
expect(i18n.getMonthFullName(0, 5778)).toBe(undefined);
expect(i18n.getMonthFullName(1, 5778)).toBe('תשרי');
expect(i18n.getMonthFullName(6, 5778)).toBe('אדר');
expect(i18n.getMonthFullName(7, 5778)).toBe('ניסן');
expect(i18n.getMonthFullName(12, 5778)).toBe('אלול');
expect(i18n.getMonthFullName(13, 5778)).toBe(undefined);
});

it('should return wide month name (leap year)', () => {
expect(i18n.getMonthFullName(0, 5779)).toBe(undefined);
expect(i18n.getMonthFullName(1, 5779)).toBe('תשרי');
expect(i18n.getMonthFullName(6, 5779)).toBe('אדר א׳');
expect(i18n.getMonthFullName(7, 5779)).toBe('אדר ב׳');
expect(i18n.getMonthFullName(12, 5779)).toBe('אב');
expect(i18n.getMonthFullName(13, 5779)).toBe('אלול');
expect(i18n.getMonthFullName(14, 5779)).toBe(undefined);
});

it('should return weekday name', () => {
expect(i18n.getWeekdayShortName(0)).toBe(undefined);
expect(i18n.getWeekdayShortName(1)).toBe('ב׳');
expect(i18n.getWeekdayShortName(7)).toBe('א׳');
expect(i18n.getWeekdayShortName(8)).toBe(undefined);
});

it('should generate aria label for a date',
() => { expect(i18n.getDayAriaLabel(new NgbDate(5778, 10, 8))).toBe('ח׳ תמוז תשע״ח'); });

it('should generate week number numerals', () => {
expect(i18n.getWeekNumerals(1)).toBe('א׳');
expect(i18n.getWeekNumerals(50)).toBe('נ׳');
});

it('should generate day numerals', () => {
expect(i18n.getDayNumerals(new NgbDate(5778, 10, 1))).toBe('א׳');
expect(i18n.getDayNumerals(new NgbDate(5778, 10, 29))).toBe('כ״ט');
});

it('should generate year numerals', () => {
expect(i18n.getYearNumerals(0)).toBe('');
expect(i18n.getYearNumerals(5778)).toBe('תשע״ח');
});
});
31 changes: 31 additions & 0 deletions src/datepicker/hebrew/datepicker-i18n-hebrew.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {NgbDatepickerI18n} from '../datepicker-i18n';
import {NgbDateStruct} from '../../index';
import {hebrewNumerals, isHebrewLeapYear} from './hebrew';
import {Injectable} from '@angular/core';


const WEEKDAYS = ['ב׳', 'ג׳', 'ד׳', 'ה׳', 'ו׳', 'ש׳', 'א׳'];
const MONTHS = ['תשרי', 'חשון', 'כסלו', 'טבת', 'שבט', 'אדר', 'ניסן', 'אייר', 'סיון', 'תמוז', 'אב', 'אלול'];
const MONTHS_LEAP =
['תשרי', 'חשון', 'כסלו', 'טבת', 'שבט', 'אדר א׳', 'אדר ב׳', 'ניסן', 'אייר', 'סיון', 'תמוז', 'אב', 'אלול'];

@Injectable()
export class NgbDatepickerI18nHebrew extends NgbDatepickerI18n {
getMonthShortName(month: number, year?: number): string { return this.getMonthFullName(month, year); }

getMonthFullName(month: number, year?: number): string {
return isHebrewLeapYear(year) ? MONTHS_LEAP[month - 1] : MONTHS[month - 1];
}

getWeekdayShortName(weekday: number): string { return WEEKDAYS[weekday - 1]; }

getDayAriaLabel(date: NgbDateStruct): string {
return `${hebrewNumerals(date.day)} ${this.getMonthFullName(date.month, date.year)} ${hebrewNumerals(date.year)}`;
}

getDayNumerals(date: NgbDateStruct): string { return hebrewNumerals(date.day); }

getWeekNumerals(weekNumber: number): string { return hebrewNumerals(weekNumber); }

getYearNumerals(year: number): string { return hebrewNumerals(year); }
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export {
NgbCalendarPersian,
NgbDatepickerModule,
NgbDatepickerI18n,
NgbDatepickerI18nHebrew,
NgbDatepickerConfig,
NgbDateStruct,
NgbDate,
Expand Down

0 comments on commit 2d68122

Please sign in to comment.