diff --git a/__tests__/datePicker.localization.test.js b/__tests__/datePicker.localization.test.js index 86ffa8b..43e1ce6 100644 --- a/__tests__/datePicker.localization.test.js +++ b/__tests__/datePicker.localization.test.js @@ -2,9 +2,10 @@ import DatePicker from "../src/datePicker"; jest.useFakeTimers(); +const containerId = 'test-container'; +let datePicker; + describe('Localization', () => { - let datePicker; - const containerId = 'test-container'; beforeEach(() => { document.body.innerHTML = `
`; @@ -184,50 +185,756 @@ describe('Localization', () => { }); }); -describe('Localization with Page Language', () => { + +describe('Localization for Bulgarian (bg-BG)', () => { let datePicker; - const containerId = 'test-container'; beforeEach(() => { document.body.innerHTML = ``; + datePicker = new DatePicker(containerId, { + mode: 'single', + onSelect: jest.fn(), + blockedDays: [0, 6], // Sundays and Saturdays + showDayNames: true + }); + datePicker.init(); }); - const setHtmlLangAttribute = (lang) => { - document.documentElement.lang = lang; - }; + test('displays day names correctly in Bulgarian', () => { + datePicker.options.language = 'bg-BG'; + datePicker.init(); + const dayNames = datePicker.element.querySelector('.datepicker-day-names').textContent; + expect(dayNames).toContain('Нд'); // Sunday in Bulgarian + expect(dayNames).toContain('Пн'); // Monday in Bulgarian + }); - const testPageLanguageSetting = (lang, expectedDayName, expectedMonthName) => { - test(`adapts to page language ${lang}`, () => { - setHtmlLangAttribute(lang); - datePicker = new DatePicker(containerId, { - mode: 'single', - onSelect: jest.fn(), - usePageLanguage: true - }); - datePicker.init(); - datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 - datePicker.render(); + test('displays month names correctly in Bulgarian', () => { + datePicker.options.language = 'bg-BG'; + datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 + datePicker.init(); + const monthDisplay = datePicker.element.querySelector('.month-display').textContent; + expect(monthDisplay).toContain('Януари 2023'); + }); +}); - const dayNames = datePicker.element.querySelector('.datepicker-day-names').textContent; - const monthDisplay = datePicker.element.querySelector('.month-display').textContent; +describe('Localization for Czech (cs)', () => { + let datePicker; - expect(dayNames).toContain(expectedDayName); - expect(monthDisplay).toContain(expectedMonthName); + + beforeEach(() => { + document.body.innerHTML = ``; + datePicker = new DatePicker(containerId, { + mode: 'single', + onSelect: jest.fn(), + blockedDays: [0, 6], // Sundays and Saturdays + showDayNames: true }); - }; + datePicker.init(); + }); + test('displays day names correctly in Czech', () => { + datePicker.options.language = 'cs'; + datePicker.init(); + const dayNames = datePicker.element.querySelector('.datepicker-day-names').textContent; + expect(dayNames).toContain('Ne'); // Sunday in Czech + expect(dayNames).toContain('Po'); // Monday in Czech + }); + + test('displays month names correctly in Czech', () => { + datePicker.options.language = 'cs'; + datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 + datePicker.init(); + const monthDisplay = datePicker.element.querySelector('.month-display').textContent; + expect(monthDisplay).toContain('Leden 2023'); + }); +}); + +describe('Localization for Danish (da)', () => { + let datePicker; + + + beforeEach(() => { + document.body.innerHTML = ``; + datePicker = new DatePicker(containerId, { + mode: 'single', + onSelect: jest.fn(), + blockedDays: [0, 6], // Sundays and Saturdays + showDayNames: true + }); + datePicker.init(); + }); + + test('displays day names correctly in Danish', () => { + datePicker.options.language = 'da'; + datePicker.init(); + const dayNames = datePicker.element.querySelector('.datepicker-day-names').textContent; + expect(dayNames).toContain('Søn'); // Sunday in Danish + expect(dayNames).toContain('Man'); // Monday in Danish + }); + + test('displays month names correctly in Danish', () => { + datePicker.options.language = 'da'; + datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 + datePicker.init(); + const monthDisplay = datePicker.element.querySelector('.month-display').textContent; + expect(monthDisplay).toContain('Januar 2023'); + }); +}); + +describe('Localization for Greek (el)', () => { + let datePicker; + + + beforeEach(() => { + document.body.innerHTML = ``; + datePicker = new DatePicker(containerId, { + mode: 'single', + onSelect: jest.fn(), + blockedDays: [0, 6], // Sundays and Saturdays + showDayNames: true + }); + datePicker.init(); + }); + + test('displays day names correctly in Greek', () => { + datePicker.options.language = 'el'; + datePicker.init(); + const dayNames = datePicker.element.querySelector('.datepicker-day-names').textContent; + expect(dayNames).toContain('Κυρ'); // Sunday in Greek + expect(dayNames).toContain('Δευ'); // Monday in Greek + }); + + test('displays month names correctly in Greek', () => { + datePicker.options.language = 'el'; + datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 + datePicker.init(); + const monthDisplay = datePicker.element.querySelector('.month-display').textContent; + expect(monthDisplay).toContain('Ιανουάριος 2023'); + }); +}); + + +describe('Localization for Finnish (fi)', () => { + let datePicker; + + + beforeEach(() => { + document.body.innerHTML = ``; + datePicker = new DatePicker(containerId, { + mode: 'single', + onSelect: jest.fn(), + blockedDays: [0, 6], // Sundays and Saturdays + showDayNames: true + }); + datePicker.init(); + }); + + test('displays day names correctly in Finnish', () => { + datePicker.options.language = 'fi'; + datePicker.init(); + const dayNames = datePicker.element.querySelector('.datepicker-day-names').textContent; + expect(dayNames).toContain('Su'); // Sunday in Finnish + expect(dayNames).toContain('Ma'); // Monday in Finnish + }); + + test('displays month names correctly in Finnish', () => { + datePicker.options.language = 'fi'; + datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 + datePicker.init(); + const monthDisplay = datePicker.element.querySelector('.month-display').textContent; + expect(monthDisplay).toContain('Tammikuu 2023'); + }); +}); + + +describe('Localization for Croatian (hr-HR)', () => { + let datePicker; + + + beforeEach(() => { + document.body.innerHTML = ``; + datePicker = new DatePicker(containerId, { + mode: 'single', + onSelect: jest.fn(), + blockedDays: [0, 6], // Sundays and Saturdays + showDayNames: true + }); + datePicker.init(); + }); + + test('displays day names correctly in Croatian', () => { + datePicker.options.language = 'hr-HR'; + datePicker.init(); + const dayNames = datePicker.element.querySelector('.datepicker-day-names').textContent; + expect(dayNames).toContain('Ned'); // Sunday in Croatian + expect(dayNames).toContain('Pon'); // Monday in Croatian + }); + + test('displays month names correctly in Croatian', () => { + datePicker.options.language = 'hr-HR'; + datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 + datePicker.init(); + const monthDisplay = datePicker.element.querySelector('.month-display').textContent; + expect(monthDisplay).toContain('Siječanj 2023'); + }); +}); + + +describe('Localization for Hungarian (hu)', () => { + let datePicker; + + + beforeEach(() => { + document.body.innerHTML = ``; + datePicker = new DatePicker(containerId, { + mode: 'single', + onSelect: jest.fn(), + blockedDays: [0, 6], // Sundays and Saturdays + showDayNames: true + }); + datePicker.init(); + }); + + test('displays day names correctly in Hungarian', () => { + datePicker.options.language = 'hu'; + datePicker.init(); + const dayNames = datePicker.element.querySelector('.datepicker-day-names').textContent; + expect(dayNames).toContain('V'); // Sunday in Hungarian + expect(dayNames).toContain('H'); // Monday in Hungarian + }); + + test('displays month names correctly in Hungarian', () => { + datePicker.options.language = 'hu'; + datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 + datePicker.init(); + const monthDisplay = datePicker.element.querySelector('.month-display').textContent; + expect(monthDisplay).toContain('Január 2023'); + }); +}); + + +describe('Localization for Indonesian (id)', () => { + let datePicker; + + + beforeEach(() => { + document.body.innerHTML = ``; + datePicker = new DatePicker(containerId, { + mode: 'single', + onSelect: jest.fn(), + blockedDays: [0, 6], // Sundays and Saturdays + showDayNames: true + }); + datePicker.init(); + }); + + test('displays day names correctly in Indonesian', () => { + datePicker.options.language = 'id'; + datePicker.init(); + const dayNames = datePicker.element.querySelector('.datepicker-day-names').textContent; + expect(dayNames).toContain('Min'); // Sunday in Indonesian + expect(dayNames).toContain('Sen'); // Monday in Indonesian + }); + + test('displays month names correctly in Indonesian', () => { + datePicker.options.language = 'id'; + datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 + datePicker.init(); + const monthDisplay = datePicker.element.querySelector('.month-display').textContent; + expect(monthDisplay).toContain('Januari 2023'); + }); +}); + + +describe('Localization for Korean (ko)', () => { + let datePicker; + + + beforeEach(() => { + document.body.innerHTML = ``; + datePicker = new DatePicker(containerId, { + mode: 'single', + onSelect: jest.fn(), + blockedDays: [0, 6], // Sundays and Saturdays + showDayNames: true + }); + datePicker.init(); + }); + + test('displays day names correctly in Korean', () => { + datePicker.options.language = 'ko'; + datePicker.init(); + const dayNames = datePicker.element.querySelector('.datepicker-day-names').textContent; + expect(dayNames).toContain('일'); // Sunday in Korean + expect(dayNames).toContain('월'); // Monday in Korean + }); + + test('displays month names correctly in Korean', () => { + datePicker.options.language = 'ko'; + datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 + datePicker.init(); + const monthDisplay = datePicker.element.querySelector('.month-display').textContent; + expect(monthDisplay).toContain('1월 2023'); + }); +}); + + +describe('Localization for Lithuanian (lt-LT)', () => { + let datePicker; + + + beforeEach(() => { + document.body.innerHTML = ``; + datePicker = new DatePicker(containerId, { + mode: 'single', + onSelect: jest.fn(), + blockedDays: [0, 6], // Sundays and Saturdays + showDayNames: true + }); + datePicker.init(); + }); + + test('displays day names correctly in Lithuanian', () => { + datePicker.options.language = 'lt-LT'; + datePicker.init(); + const dayNames = datePicker.element.querySelector('.datepicker-day-names').textContent; + expect(dayNames).toContain('Sek'); // Sunday in Lithuanian + expect(dayNames).toContain('Pir'); // Monday in Lithuanian + }); + + test('displays month names correctly in Lithuanian', () => { + datePicker.options.language = 'lt-LT'; + datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 + datePicker.init(); + const monthDisplay = datePicker.element.querySelector('.month-display').textContent; + expect(monthDisplay).toContain('Sausis 2023'); + }); +}); + + +describe('Localization for Norwegian Bokmål (nb)', () => { + let datePicker; + + + beforeEach(() => { + document.body.innerHTML = ``; + datePicker = new DatePicker(containerId, { + mode: 'single', + onSelect: jest.fn(), + blockedDays: [0, 6], // Sundays and Saturdays + showDayNames: true + }); + datePicker.init(); + }); + + test('displays day names correctly in Norwegian Bokmål', () => { + datePicker.options.language = 'nb'; + datePicker.init(); + const dayNames = datePicker.element.querySelector('.datepicker-day-names').textContent; + expect(dayNames).toContain('Søn'); // Sunday in Norwegian Bokmål + expect(dayNames).toContain('Man'); // Monday in Norwegian Bokmål + }); + + test('displays month names correctly in Norwegian Bokmål', () => { + datePicker.options.language = 'nb'; + datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 + datePicker.init(); + const monthDisplay = datePicker.element.querySelector('.month-display').textContent; + expect(monthDisplay).toContain('Januar 2023'); + }); +}); + + +describe('Localization for Polish (pl)', () => { + let datePicker; + + + beforeEach(() => { + document.body.innerHTML = ``; + datePicker = new DatePicker(containerId, { + mode: 'single', + onSelect: jest.fn(), + blockedDays: [0, 6], // Sundays and Saturdays + showDayNames: true + }); + datePicker.init(); + }); + + test('displays day names correctly in Polish', () => { + datePicker.options.language = 'pl'; + datePicker.init(); + const dayNames = datePicker.element.querySelector('.datepicker-day-names').textContent; + expect(dayNames).toContain('N'); // Sunday in Polish + expect(dayNames).toContain('Pn'); // Monday in Polish + }); + + test('displays month names correctly in Polish', () => { + datePicker.options.language = 'pl'; + datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 + datePicker.init(); + const monthDisplay = datePicker.element.querySelector('.month-display').textContent; + expect(monthDisplay).toContain('Styczeń 2023'); + }); +}); + +describe('Localization for Brazilian Portuguese (pt-BR)', () => { + let datePicker; + + + beforeEach(() => { + document.body.innerHTML = ``; + datePicker = new DatePicker(containerId, { + mode: 'single', + onSelect: jest.fn(), + blockedDays: [0, 6], // Sundays and Saturdays + showDayNames: true + }); + datePicker.init(); + }); + + test('displays day names correctly in Brazilian Portuguese', () => { + datePicker.options.language = 'pt-BR'; + datePicker.init(); + const dayNames = datePicker.element.querySelector('.datepicker-day-names').textContent; + expect(dayNames).toContain('Dom'); // Sunday in Brazilian Portuguese + expect(dayNames).toContain('Seg'); // Monday in Brazilian Portuguese + }); + + test('displays month names correctly in Brazilian Portuguese', () => { + datePicker.options.language = 'pt-BR'; + datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 + datePicker.init(); + const monthDisplay = datePicker.element.querySelector('.month-display').textContent; + expect(monthDisplay).toContain('Janeiro 2023'); + }); +}); + +describe('Localization for European Portuguese (pt-PT)', () => { + let datePicker; + + + beforeEach(() => { + document.body.innerHTML = ``; + datePicker = new DatePicker(containerId, { + mode: 'single', + onSelect: jest.fn(), + blockedDays: [0, 6], // Sundays and Saturdays + showDayNames: true + }); + datePicker.init(); + }); + + test('displays day names correctly in European Portuguese', () => { + datePicker.options.language = 'pt-PT'; + datePicker.init(); + const dayNames = datePicker.element.querySelector('.datepicker-day-names').textContent; + expect(dayNames).toContain('Dom'); // Sunday in European Portuguese + expect(dayNames).toContain('Seg'); // Monday in European Portuguese + }); + + test('displays month names correctly in European Portuguese', () => { + datePicker.options.language = 'pt-PT'; + datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 + datePicker.init(); + const monthDisplay = datePicker.element.querySelector('.month-display').textContent; + expect(monthDisplay).toContain('Janeiro 2023'); + }); +}); + +describe('Localization for Romanian (ro-RO)', () => { + let datePicker; + + + beforeEach(() => { + document.body.innerHTML = ``; + datePicker = new DatePicker(containerId, { + mode: 'single', + onSelect: jest.fn(), + blockedDays: [0, 6], // Sundays and Saturdays + showDayNames: true + }); + datePicker.init(); + }); + + test('displays day names correctly in Romanian', () => { + datePicker.options.language = 'ro-RO'; + datePicker.init(); + const dayNames = datePicker.element.querySelector('.datepicker-day-names').textContent; + expect(dayNames).toContain('Dum'); // Sunday in Romanian + expect(dayNames).toContain('Lun'); // Monday in Romanian + }); + + test('displays month names correctly in Romanian', () => { + datePicker.options.language = 'ro-RO'; + datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 + datePicker.init(); + const monthDisplay = datePicker.element.querySelector('.month-display').textContent; + expect(monthDisplay).toContain('Ianuarie 2023'); + }); +}); + +describe('Localization for Slovak (sk-SK)', () => { + let datePicker; + + + beforeEach(() => { + document.body.innerHTML = ``; + + datePicker = new DatePicker(containerId, { + mode: 'single', + onSelect: jest.fn(), + blockedDays: [0, 6], + showDayNames: true + }); + datePicker.init(); + }); + + test('displays day names correctly in Slovak', () => { + datePicker.options.language = 'sk-SK'; + datePicker.init(); + const dayNames = datePicker.element.querySelector('.datepicker-day-names').textContent; + expect(dayNames).toContain('Ne'); // Sunday in Slovak + expect(dayNames).toContain('Po'); // Monday in Slovak + }); + + test('displays month names correctly in Slovak', () => { + datePicker.options.language = 'sk-SK'; + datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 + datePicker.init(); + + const monthDisplay = datePicker.element.querySelector('.month-display').textContent; + expect(monthDisplay).toContain('Január 2023'); + }); +}); + +describe('Localization for Slovenian (sl-SL)', () => { + let datePicker; + + + beforeEach(() => { + document.body.innerHTML = ``; + datePicker = new DatePicker(containerId, { + mode: 'single', + onSelect: jest.fn(), + blockedDays: [0, 6], // Sundays and Saturdays + showDayNames: true + }); + datePicker.init(); + }); + + test('displays day names correctly in Slovenian', () => { + datePicker.options.language = 'sl-SL'; + datePicker.init(); + const dayNames = datePicker.element.querySelector('.datepicker-day-names').textContent; + expect(dayNames).toContain('Ned'); // Sunday in Slovenian + expect(dayNames).toContain('Pon'); // Monday in Slovenian + }); + + test('displays month names correctly in Slovenian', () => { + datePicker.options.language = 'sl-SL'; + datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 + datePicker.init(); + const monthDisplay = datePicker.element.querySelector('.month-display').textContent; + expect(monthDisplay).toContain('Januar 2023'); + }); +}); + +describe('Localization for Swedish (sv)', () => { + let datePicker; + + + beforeEach(() => { + document.body.innerHTML = ``; + datePicker = new DatePicker(containerId, { + mode: 'single', + onSelect: jest.fn(), + blockedDays: [0, 6], // Sundays and Saturdays + showDayNames: true + }); + datePicker.init(); + }); + + test('displays day names correctly in Swedish', () => { + datePicker.options.language = 'sv'; + datePicker.init(); + const dayNames = datePicker.element.querySelector('.datepicker-day-names').textContent; + expect(dayNames).toContain('Sön'); // Sunday in Swedish + expect(dayNames).toContain('Mån'); // Monday in Swedish + }); + + test('displays month names correctly in Swedish', () => { + datePicker.options.language = 'sv'; + datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 + datePicker.init(); + const monthDisplay = datePicker.element.querySelector('.month-display').textContent; + expect(monthDisplay).toContain('Januari 2023'); + }); +}); + +describe('Localization for Thai (th)', () => { + let datePicker; + + + beforeEach(() => { + document.body.innerHTML = ``; + datePicker = new DatePicker(containerId, { + mode: 'single', + onSelect: jest.fn(), + blockedDays: [0, 6], // Sundays and Saturdays + showDayNames: true + }); + datePicker.init(); + }); + + test('displays day names correctly in Thai', () => { + datePicker.options.language = 'th'; + datePicker.init(); + const dayNames = datePicker.element.querySelector('.datepicker-day-names').textContent; + expect(dayNames).toContain('อา.'); // Sunday in Thai + expect(dayNames).toContain('จ.'); // Monday in Thai + }); + + test('displays month names correctly in Thai', () => { + datePicker.options.language = 'th'; + datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 + datePicker.init(); + const monthDisplay = datePicker.element.querySelector('.month-display').textContent; + expect(monthDisplay).toContain('มกราคม 2023'); + }); +}); + +describe('Localization for Turkish (tr)', () => { + let datePicker; + + + beforeEach(() => { + document.body.innerHTML = ``; + datePicker = new DatePicker(containerId, { + mode: 'single', + onSelect: jest.fn(), + blockedDays: [0, 6], // Sundays and Saturdays + showDayNames: true + }); + datePicker.init(); + }); + + test('displays day names correctly in Turkish', () => { + datePicker.options.language = 'tr'; + datePicker.init(); + const dayNames = datePicker.element.querySelector('.datepicker-day-names').textContent; + expect(dayNames).toContain('Paz'); // Sunday in Turkish + expect(dayNames).toContain('Pzt'); // Monday in Turkish + }); + + test('displays month names correctly in Turkish', () => { + datePicker.options.language = 'tr'; + datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 + datePicker.init(); + const monthDisplay = datePicker.element.querySelector('.month-display').textContent; + expect(monthDisplay).toContain('Ocak 2023'); + }); +}); + + +describe('Localization for Vietnamese (vi)', () => { + let datePicker; + + + beforeEach(() => { + document.body.innerHTML = ``; + datePicker = new DatePicker(containerId, { + mode: 'single', + onSelect: jest.fn(), + blockedDays: [0, 6], // Sundays and Saturdays + showDayNames: true + }); + datePicker.init(); + }); + + test('displays day names correctly in Vietnamese', () => { + datePicker.options.language = 'vi'; + datePicker.init(); + const dayNames = datePicker.element.querySelector('.datepicker-day-names').textContent; + expect(dayNames).toContain('CN'); // Sunday in Vietnamese + expect(dayNames).toContain('T2'); // Monday in Vietnamese + }); + + test('displays month names correctly in Vietnamese', () => { + datePicker.options.language = 'vi'; + datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 + datePicker.init(); + const monthDisplay = datePicker.element.querySelector('.month-display').textContent; + expect(monthDisplay).toContain('Tháng Một 2023'); + }); +}); + + +describe('Localization with Page Language', () => { + let datePicker; + + + beforeEach(() => { + document.body.innerHTML = ``; + }); + + const setHtmlLangAttribute = (lang) => { + document.documentElement.lang = lang; + }; + + const testPageLanguageSetting = (lang, expectedDayName, expectedMonthName) => { + test(`adapts to page language ${lang}`, () => { + setHtmlLangAttribute(lang); + datePicker = new DatePicker(containerId, { + mode: 'single', + onSelect: jest.fn(), + usePageLanguage: true + }); + datePicker.init(); + datePicker.currentDate = new Date(2023, 0, 1); // January 1, 2023 + datePicker.render(); + + const dayNames = datePicker.element.querySelector('.datepicker-day-names').textContent; + const monthDisplay = datePicker.element.querySelector('.month-display').textContent; + + expect(dayNames).toContain(expectedDayName); + expect(monthDisplay).toContain(expectedMonthName); + }); + }; + + + testPageLanguageSetting('en', 'Sun', 'January 2023'); + testPageLanguageSetting('fr', 'Dim', 'Janvier 2023'); + testPageLanguageSetting('es', 'Dom', 'Enero 2023'); + testPageLanguageSetting('de', 'So', 'Januar 2023'); + testPageLanguageSetting('it', 'Dom', 'Gennaio 2023'); + testPageLanguageSetting('nl', 'Zo', 'Januari 2023'); + testPageLanguageSetting('pt', 'Dom', 'Janeiro 2023'); + testPageLanguageSetting('ja', '日', '一月 2023'); + testPageLanguageSetting('zh-CN', '日', '一月 2023'); + testPageLanguageSetting('zh-TW', '日', '一月 2023'); + testPageLanguageSetting('ru', 'Вс', 'Январь 2023'); + testPageLanguageSetting('bg-BG', 'Нд', 'Януари 2023'); + testPageLanguageSetting('cs', 'Ne', 'Leden 2023'); + testPageLanguageSetting('da', 'Søn', 'Januar 2023'); + testPageLanguageSetting('el', 'Κυρ', 'Ιανουάριος 2023'); + testPageLanguageSetting('fi', 'Su', 'Tammikuu 2023'); + testPageLanguageSetting('hr-HR', 'Ned', 'Siječanj 2023'); + testPageLanguageSetting('hu', 'V', 'Január 2023'); + testPageLanguageSetting('id', 'Min', 'Januari 2023'); + testPageLanguageSetting('ko', '일', '1월 2023'); + testPageLanguageSetting('lt-LT', 'Sek', 'Sausis 2023'); + testPageLanguageSetting('nb', 'Søn', 'Januar 2023'); + testPageLanguageSetting('pl', 'N', 'Styczeń 2023'); + testPageLanguageSetting('pt-BR', 'Dom', 'Janeiro 2023'); + testPageLanguageSetting('pt-PT', 'Dom', 'Janeiro 2023'); + testPageLanguageSetting('ro-RO', 'Dum', 'Ianuarie 2023'); + testPageLanguageSetting('sk-SK', 'Ne', 'Január 2023'); + testPageLanguageSetting('sl-SL', 'Ned', 'Januar 2023'); + testPageLanguageSetting('sv', 'Sön', 'Januari 2023'); + testPageLanguageSetting('th', 'อา.', 'มกราคม 2023'); + testPageLanguageSetting('tr', 'Paz', 'Ocak 2023'); + testPageLanguageSetting('vi', 'CN', 'Tháng Một 2023'); - testPageLanguageSetting('en', 'Sun', 'January 2023'); - testPageLanguageSetting('fr', 'Dim', 'Janvier 2023'); - testPageLanguageSetting('es', 'Dom', 'Enero 2023'); - testPageLanguageSetting('de', 'So', 'Januar 2023'); - testPageLanguageSetting('it', 'Dom', 'Gennaio 2023'); - testPageLanguageSetting('nl', 'Zo', 'Januari 2023'); - testPageLanguageSetting('pt', 'Dom', 'Janeiro 2023'); - testPageLanguageSetting('ja', '日', '一月 2023'); - testPageLanguageSetting('zh-CN', '日', '一月 2023'); - testPageLanguageSetting('zh-TW', '日', '一月 2023'); - testPageLanguageSetting('ru', 'Вс', 'Январь 2023'); afterEach(() => { setHtmlLangAttribute('en'); diff --git a/dist/datepicker.bundle.js b/dist/datepicker.bundle.js index 8d1a2fe..768c6c5 100644 --- a/dist/datepicker.bundle.js +++ b/dist/datepicker.bundle.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.DatePicker=t():e.DatePicker=t()}(this,(()=>(()=>{"use strict";var e={d:(t,n)=>{for(var a in n)e.o(n,a)&&!e.o(t,a)&&Object.defineProperty(t,a,{enumerable:!0,get:n[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};function n(e,t,n){var a=e.querySelector(".prev-month"),i=e.querySelector(".next-month"),r=e.querySelector(".datepicker-calendar-container"),l=e.querySelector(".datepicker-days");function o(n,a){return function(i){i.stopPropagation();var r=document.activeElement;t(n),requestAnimationFrame((function(){r&&r.className.includes(a)&&e.querySelector(".".concat(a)).focus()}))}}a.removeEventListener("click",a.listener),i.removeEventListener("click",i.listener),l.removeEventListener("click",l.listener),l.removeEventListener("keydown",l.listener),document.removeEventListener("click",document.listener),a.listener=o(-1,"prev-month"),i.listener=o(1,"next-month"),a.addEventListener("click",a.listener),i.addEventListener("click",i.listener),l.listener=function(e){if("click"===e.type||"keydown"===e.type&&"Enter"===e.key){var t=e.target.closest(".datepicker-day");if(t&&!t.classList.contains("blocked")){var a=parseInt(t.getAttribute("data-day"),10),i=parseInt(t.getAttribute("data-month"),10);n(a,i)}}},document.listener=function(t){r.contains(t.target)||e.querySelector(".datepicker-input").contains(t.target)||(r.style.display="none")},a.addEventListener("click",a.listener),i.addEventListener("click",i.listener),l.addEventListener("click",l.listener),l.addEventListener("keydown",l.listener),document.addEventListener("click",document.listener)}e.d(t,{default:()=>h});var a={en:"Choose a date",fr:"Choisissez une date",es:"Elige una fecha",de:"Wählen Sie ein Datum",it:"Scegli una data",nl:"Kies een datum",pt:"Escolha uma data",ja:"日付を選択","zh-CN":"选择日期","zh-TW":"選擇日期",ru:"Выберите дату"},i={en:{prevMonth:"Go to previous month",nextMonth:"Go to next month"},fr:{prevMonth:"Aller au mois précédent",nextMonth:"Aller au mois suivant"},es:{prevMonth:"Ir al mes anterior",nextMonth:"Ir al siguiente mes"},de:{prevMonth:"Gehe zum vorherigen Monat",nextMonth:"Gehe zum nächsten Monat"},it:{prevMonth:"Vai al mese precedente",nextMonth:"Vai al mese successivo"},nl:{prevMonth:"Ga naar de vorige maand",nextMonth:"Ga naar de volgende maand"},pt:{prevMonth:"Ir para o mês anterior",nextMonth:"Ir para o próximo mês"},ja:{prevMonth:"前の月へ",nextMonth:"次の月へ"},"zh-CN":{prevMonth:"转到上一个月",nextMonth:"转到下一个月"},"zh-TW":{prevMonth:"轉到上一個月",nextMonth:"轉到下一個月"},ru:{prevMonth:"Перейти к предыдущему месяцу",nextMonth:"Перейти к следующему месяцу"}},r={en:["January","February","March","April","May","June","July","August","September","October","November","December"],fr:["Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre"],es:["Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"],de:["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"],it:["Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre"],nl:["Januari","Februari","Maart","April","Mei","Juni","Juli","Augustus","September","Oktober","November","December"],pt:["Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro"],ja:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],"zh-CN":["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],"zh-TW":["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],ru:["Январь","Февраль","Март","Апрель","Май","Июнь","Июль","Август","Сентяюрь","Октябрь","Ноябрь","Декабрь"]},l={en:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],fr:["Dim","Lun","Mar","Mer","Jeu","Ven","Sam"],es:["Dom","Lun","Mar","Mié","Jue","Vie","Sáb"],de:["So","Mo","Di","Mi","Do","Fr","Sa"],it:["Dom","Lun","Mar","Mer","Gio","Ven","Sab"],nl:["Zo","Ma","Di","Wo","Do","Vr","Za"],pt:["Dom","Seg","Ter","Qua","Qui","Sex","Sáb"],ja:["日","月","火","水","木","金","土"],"zh-CN":["日","一","二","三","四","五","六"],"zh-TW":["日","一","二","三","四","五","六"],ru:["Вс","Пн","Вт","Ср","Чт","Пт","Сб"]},o={1:"一",2:"二",3:"三",4:"四",5:"五",6:"六",7:"七",8:"八",9:"九",10:"十",11:"十一",12:"十二",13:"十三",14:"十四",15:"十五",16:"十六",17:"十七",18:"十八",19:"十九",20:"二十",21:"二十一",22:"二十二",23:"二十三",24:"二十四",25:"二十五",26:"二十六",27:"二十七",28:"二十八",29:"二十九",30:"三十",31:"三十一"},s={"zh-CN":{1:"一",2:"二",3:"三",4:"四",5:"五",6:"六",7:"七",8:"八",9:"九",10:"十",11:"十一",12:"十二",13:"十三",14:"十四",15:"十五",16:"十六",17:"十七",18:"十八",19:"十九",20:"二十",21:"廿一",22:"廿二",23:"廿三",24:"廿四",25:"廿五",26:"廿六",27:"廿七",28:"廿八",29:"廿九",30:"三十",31:"三十一"},"zh-TW":{1:"一",2:"二",3:"三",4:"四",5:"五",6:"六",7:"七",8:"八",9:"九",10:"十",11:"十一",12:"十二",13:"十三",14:"十四",15:"十五",16:"十六",17:"十七",18:"十八",19:"十九",20:"二十",21:"廿一",22:"廿二",23:"廿三",24:"廿四",25:"廿五",26:"廿六",27:"廿七",28:"廿八",29:"廿九",30:"三十",31:"三十一"}};function c(e){var t=document.documentElement.lang;return["en","fr","es","de","it","nl","pt","ja","zh-CN","zh-TW","ru"].includes(t)?t:e}function d(e,t,n,a,i,r,l){var c=new Date(e,t,n),d=n;"ja"===l.language?d=o[n]:"zh-CN"!==l.language&&"zh-TW"!==l.language||(d=s[l.language][n]);var u=a?"datepicker-day current-month":"datepicker-day";return l.blockedDays.includes(c.getDay())?u+=" blocked":a&&i(c)?u+=" selected":a&&r(c)&&(u+=" in-range"),'