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"),'
').concat(d,"
")}function u(e,t,n,a){var o,s,c=document.createElement("div");return c.className="datepicker-calendar-container ".concat(null==a?void 0:a.language),c.style.display=a.textInputEnabled?"none":"block",c.innerHTML='\n
\n \n ').concat((o=e.getMonth(),s=a.language,r[s][o])," ").concat(e.getFullYear(),'\n \n
\n ').concat(a.showDayNames?function(e){var t=l[e];return'
'.concat(t.map((function(e){return"
".concat(e,"
")})).join(""),"
")}(a.language):"",'\n
\n ').concat(function(e,t,n,a){var i=e.getFullYear(),r=e.getMonth(),l=new Date(i,r,1),o=new Date(i,r,0).getDate(),s=new Date(i,r+1,0).getDate();1===r&&function(e){return e%4==0&&e%100!=0||e%400==0}(i)&&(s=29);for(var c='
',u=l.getDay();u>0;u--)c+=d(i,r-1,o-u+1,!1,t,n,a);for(var h=1;h<=s;h++)c+=d(i,r,h,!0,t,n,a);for(var p=new Date(i,r,s).getDay(),v=1;p<6;v++,p++)c+=d(i,r+1,v,!1,t,n,a);return c+"
"}(e,t,n,a),"\n
\n "),c}function h(e,t){var i,r,l,o,s,d,h,p,v,m,g;this.element=document.getElementById(e),this.currentDate=new Date,this.currentDate.setDate(1),this.selectedStartDate=null,this.selectedEndDate=null,this.options={mode:null!==(i=null==t?void 0:t.mode)&&void 0!==i?i:"single",onSelect:null!==(r=null==t?void 0:t.onSelect)&&void 0!==r?r:null,blockedDays:null!==(l=null==t?void 0:t.blockedDays)&&void 0!==l?l:[],showDayNames:null===(o=null==t?void 0:t.showDayNames)||void 0===o||o,textInputEnabled:null!==(s=null==t?void 0:t.textInputEnabled)&&void 0!==s&&s,darkMode:null!==(d=null==t?void 0:t.darkMode)&&void 0!==d&&d,usePageLanguage:null!==(h=null==t?void 0:t.usePageLanguage)&&void 0!==h&&h,usePageLanguageFallback:null!==(p=null==t?void 0:t.usePageLanguageFallback)&&void 0!==p?p:"en",language:null!=t&&t.usePageLanguage?c(null==t?void 0:t.usePageLanguageFallback):null!==(v=null==t?void 0:t.language)&&void 0!==v?v:"en",textInputPlaceholder:null!==(m=null==t?void 0:t.textInputPlaceholder)&&void 0!==m?m:a[null!=t&&t.usePageLanguage?c():null!==(g=null==t?void 0:t.language)&&void 0!==g?g:"en"]},this.init=function(){this.options.darkMode&&this.element.classList.add("dark"),this.calendarContainer=u(this.currentDate,this.isDateSelected.bind(this),this.isDateInRange.bind(this),this.options),this.options.textInputEnabled&&(this.input=document.createElement("input"),this.input.value=this.options.textInputPlaceholder,this.input.type="text",this.input.className="datepicker-input",this.input.readOnly=!0,this.element.appendChild(this.input)),this.element.appendChild(this.calendarContainer),this.render(),n(this.element,this.changeMonth.bind(this),this.handleDayClick.bind(this))},this.render=function(){this.element.innerHTML="";var e=u(this.currentDate,this.isDateSelected.bind(this),this.isDateInRange.bind(this),this.options);if(this.options.textInputEnabled&&!this.element.querySelector(".datepicker-input")){var t=document.createElement("input");if(t.value=this.options.textInputPlaceholder,t.type="text",t.id="datepicker-input",t.className="datepicker-input",t.readOnly=!0,this.selectedStartDate)if("single"===this.options.mode)t.value=this.localizedDate(this.selectedStartDate,this.options.language);else if("range"===this.options.mode){var a=this.localizedDate(this.selectedStartDate,this.options.language);this.selectedEndDate&&(a+=" - ".concat(this.localizedDate(this.selectedEndDate,this.options.language))),t.value=a}t.removeEventListener("click",t.listener),t.removeEventListener("keydown",t.listener),t.addEventListener("click",(function(){e.style.display="block"})),t.addEventListener("keydown",(function(t){"Enter"===t.key&&(e.style.display="block"===e.style.display?"none":"block")})),this.element.appendChild(t)}this.element.appendChild(e),n(this.element,this.changeMonth.bind(this),this.handleDayClick.bind(this))},this.localizedDate=function(e,t){return e.toLocaleDateString(t,{year:"numeric",month:"long",day:"numeric"})},this.isDateSelected=function(e){return this.selectedStartDate&&this.selectedStartDate.toDateString()===e.toDateString()||this.selectedEndDate&&this.selectedEndDate.toDateString()===e.toDateString()},this.isDateInRange=function(e){return this.selectedStartDate&&this.selectedEndDate&&e>this.selectedStartDate&&ethis.selectedStartDate?(this.selectedEndDate=i,this.element.querySelector(".datepicker-input")&&(this.element.querySelector(".datepicker-input").value="".concat(this.selectedStartDate.toDateString()," ").concat(void 0!==this.selectedEndDate.toDateString()?"- "+this.selectedEndDate.toDateString():"")),this.triggerSelectCallback(),this.render(),t.textInputEnabled&&(this.element.querySelector(".datepicker-calendar-container").style.display="none")):(this.selectedStartDate=i,this.render(),this.element.querySelector(".datepicker-calendar-container").style.display="block")))},this.changeMonth=function(e){var t,n={currentYear:(t=this.currentDate).getFullYear(),currentMonth:t.getMonth(),currentDay:t.getDate()},a=n.currentYear,i=n.currentDay,r=new Date(a,n.currentMonth+e,1),l=new Date(a,r.getMonth()+1,0).getDate();r.setDate(Math.min(i,l)),this.currentDate=r,this.render(),this.element.querySelector(".datepicker-calendar-container").style.display="block"},this.triggerSelectCallback=function(){this.options.onSelect&&this.options.onSelect(this.selectedStartDate,this.selectedEndDate)}}return t.default})())); \ No newline at end of file +!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"),o=e.querySelector(".datepicker-days");function s(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),o.removeEventListener("click",o.listener),o.removeEventListener("keydown",o.listener),document.removeEventListener("click",document.listener),a.listener=s(-1,"prev-month"),i.listener=s(1,"next-month"),a.addEventListener("click",a.listener),i.addEventListener("click",i.listener),o.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),o.addEventListener("click",o.listener),o.addEventListener("keydown",o.listener),document.addEventListener("click",document.listener)}e.d(t,{default:()=>m});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:"Выберите дату","bg-BG":"Изберете дата",cs:"Vyberte datum",da:"Vælg en dato",el:"Επιλέξτε μια ημερομηνία",fi:"Valitse päivämäärä","hr-HR":"Odaberite datum",hu:"Válasszon egy dátumot",id:"Pilih tanggal",ko:"날짜를 선택하세요","lt-LT":"Pasirinkite datą",nb:"Velg en dato",pl:"Wybierz datę","pt-BR":"Escolha uma data","pt-PT":"Escolha uma data","ro-RO":"Alegeți o dată","sk-SK":"Vyberte dátum","sl-SL":"Izberite datum",sv:"Välj ett datum",th:"เลือกวันที่",tr:"Bir tarih seçin",vi:"Chọn ngày"},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:"Перейти к следующему месяцу"},"bg-BG":{prevMonth:"Отиди на предишния месец",nextMonth:"Отиди на следващия месец"},cs:{prevMonth:"Přejít na předchozí měsíc",nextMonth:"Přejít na další měsíc"},da:{prevMonth:"Gå til forrige måned",nextMonth:"Gå til næste måned"},el:{prevMonth:"Μετάβαση στον προηγούμενο μήνα",nextMonth:"Μετάβαση στον επόμενο μήνα"},fi:{prevMonth:"Siirry edelliseen kuukauteen",nextMonth:"Siirry seuraavaan kuukauteen"},"hr-HR":{prevMonth:"Idi na prethodni mjesec",nextMonth:"Idi na sljedeći mjesec"},hu:{prevMonth:"Ugrás az előző hónaphoz",nextMonth:"Ugrás a következő hónaphoz"},id:{prevMonth:"Pergi ke bulan sebelumnya",nextMonth:"Pergi ke bulan berikutnya"},ko:{prevMonth:"이전 달로 가기",nextMonth:"다음 달로 가기"},"lt-LT":{prevMonth:"Eiti į ankstesnį mėnesį",nextMonth:"Eiti į kitą mėnesį"},nb:{prevMonth:"Gå til forrige måned",nextMonth:"Gå til neste måned"},pl:{prevMonth:"Przejdź do poprzedniego miesiąca",nextMonth:"Przejdź do następnego miesiąca"},"pt-BR":{prevMonth:"Ir para o mês anterior",nextMonth:"Ir para o próximo mês"},"pt-PT":{prevMonth:"Ir para o mês anterior",nextMonth:"Ir para o próximo mês"},"ro-RO":{prevMonth:"Mergi la luna anterioară",nextMonth:"Mergi la luna următoare"},"sk-SK":{prevMonth:"Prejsť na predchádzajúci mesiac",nextMonth:"Prejsť na nasledujúci mesiac"},"sl-SL":{prevMonth:"Pojdi na prejšnji mesec",nextMonth:"Pojdi na naslednji mesec"},sv:{prevMonth:"Gå till föregående månad",nextMonth:"Gå till nästa månad"},th:{prevMonth:"ไปยังเดือนก่อนหน้า",nextMonth:"ไปยังเดือนถัดไป"},tr:{prevMonth:"Önceki aya git",nextMonth:"Sonraki aya git"},vi:{prevMonth:"Đi đến tháng trước",nextMonth:"Đi đến tháng sau"}},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:["Январь","Февраль","Март","Апрель","Май","Июнь","Июль","Август","Сентяюрь","Октябрь","Ноябрь","Декабрь"],"bg-BG":["Януари","Февруари","Март","Април","Май","Юни","Юли","Август","Септември","Октомври","Ноември","Декември"],cs:["Leden","Únor","Březen","Duben","Květen","Červen","Červenec","Srpen","Září","Říjen","Listopad","Prosinec"],da:["Januar","Februar","Marts","April","Maj","Juni","Juli","August","September","Oktober","November","December"],el:["Ιανουάριος","Φεβρουάριος","Μάρτιος","Απρίλιος","Μάιος","Ιούνιος","Ιούλιος","Αύγουστος","Σεπτέμβριος","Οκτώβριος","Νοέμβριος","Δεκέμβριος"],fi:["Tammikuu","Helmikuu","Maaliskuu","Huhtikuu","Toukokuu","Kesäkuu","Heinäkuu","Elokuu","Syyskuu","Lokakuu","Marraskuu","Joulukuu"],"hr-HR":["Siječanj","Veljača","Ožujak","Travanj","Svibanj","Lipanj","Srpanj","Kolovoz","Rujan","Listopad","Studeni","Prosinac"],hu:["Január","Február","Március","Április","Május","Június","Július","Augusztus","Szeptember","Október","November","December"],id:["Januari","Februari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","November","Desember"],ko:["1월","2월","3월","4월","5월","6월","7월","8월","9월","10월","11월","12월"],"lt-LT":["Sausis","Vasaris","Kovas","Balandis","Gegužė","Birželis","Liepa","Rugpjūtis","Rugsėjis","Spalis","Lapkritis","Gruodis"],nb:["Januar","Februar","Mars","April","Mai","Juni","Juli","August","September","Oktober","November","Desember"],pl:["Styczeń","Luty","Marzec","Kwiecień","Maj","Czerwiec","Lipiec","Sierpień","Wrzesień","Październik","Listopad","Grudzień"],"pt-BR":["Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro"],"pt-PT":["Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro"],"ro-RO":["Ianuarie","Februarie","Martie","Aprilie","Mai","Iunie","Iulie","August","Septembrie","Octombrie","Noiembrie","Decembrie"],"sk-SK":["Január","Február","Marec","Apríl","Máj","Jún","Júl","August","September","Október","November","December"],"sl-SL":["Januar","Februar","Marec","April","Maj","Junij","Julij","Avgust","September","Oktober","November","December"],sv:["Januari","Februari","Mars","April","Maj","Juni","Juli","Augusti","September","Oktober","November","December"],th:["มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม"],tr:["Ocak","Şubat","Mart","Nisan","Mayıs","Haziran","Temmuz","Ağustos","Eylül","Ekim","Kasım","Aralık"],vi:["Tháng Một","Tháng Hai","Tháng Ba","Tháng Tư","Tháng Năm","Tháng Sáu","Tháng Bảy","Tháng Tám","Tháng Chín","Tháng Mười","Tháng Mười Một","Tháng Mười Hai"]},o={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:["Вс","Пн","Вт","Ср","Чт","Пт","Сб"],"bg-BG":["Нд","Пн","Вт","Ср","Чт","Пт","Сб"],cs:["Ne","Po","Út","St","Čt","Pá","So"],da:["Søn","Man","Tir","Ons","Tor","Fre","Lør"],el:["Κυρ","Δευ","Τρί","Τετ","Πέμ","Παρ","Σάβ"],fi:["Su","Ma","Ti","Ke","To","Pe","La"],"hr-HR":["Ned","Pon","Uto","Sri","Čet","Pet","Sub"],hu:["V","H","K","Sze","Cs","P","Szo"],id:["Min","Sen","Sel","Rab","Kam","Jum","Sab"],ko:["일","월","화","수","목","금","토"],"lt-LT":["Sek","Pir","Ant","Tre","Ket","Pen","Šeš"],nb:["Søn","Man","Tir","Ons","Tor","Fre","Lør"],pl:["N","Pn","Wt","Śr","Cz","Pt","Sob"],"pt-BR":["Dom","Seg","Ter","Qua","Qui","Sex","Sáb"],"pt-PT":["Dom","Seg","Ter","Qua","Qui","Sex","Sáb"],"ro-RO":["Dum","Lun","Mar","Mie","Joi","Vin","Sâm"],"sk-SK":["Ne","Po","Ut","St","Št","Pi","So"],"sl-SL":["Ned","Pon","Tor","Sre","Čet","Pet","Sob"],sv:["Sön","Mån","Tis","Ons","Tor","Fre","Lör"],th:["อา.","จ.","อ.","พ.","พฤ.","ศ.","ส."],tr:["Paz","Pzt","Sal","Çar","Per","Cum","Cts"],vi:["CN","T2","T3","T4","T5","T6","T7"]},s={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:"三十一"},l={"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:"三十一"}},u={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:"삼십일"},d={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","bg-BG","cs","da","el","fi","hr-HR","hu","id","ko","lt-LT","nb","pl","pt-BR","pt-PT","ro-RO","sk-SK","sl-SL","sv","th","tr","vi"].includes(t)?t:e}function h(e,t,n,a,i,r,o){var c=new Date(e,t,n),h=n;"ja"===o.language?h=s[n]:"zh-CN"===o.language||"zh-TW"===o.language?h=l[o.language][n]:"ko"===o.language?h=u[n]:"th"===o.language&&(h=d[n]);var p=a?"datepicker-day current-month":"datepicker-day";return o.blockedDays.includes(c.getDay())?p+=" blocked":a&&i(c)?p+=" selected":a&&r(c)&&(p+=" in-range"),'
').concat(h,"
")}function p(e,t,n,a){var s,l,u=document.createElement("div");return u.className="datepicker-calendar-container ".concat(null==a?void 0:a.language),u.style.display=a.textInputEnabled?"none":"block",u.innerHTML='\n
\n \n ').concat((s=e.getMonth(),l=a.language,r[l][s])," ").concat(e.getFullYear(),'\n \n
\n ').concat(a.showDayNames?function(e){var t=o[e];return'
'.concat(t.map((function(e){return"
".concat(e,"
")})).join(""),"
")}(a.language):"",'\n
\n ').concat(function(e,t,n,a){var i=e.getFullYear(),r=e.getMonth(),o=new Date(i,r,1),s=new Date(i,r,0).getDate(),l=new Date(i,r+1,0).getDate();1===r&&function(e){return e%4==0&&e%100!=0||e%400==0}(i)&&(l=29);for(var u='
',d=o.getDay();d>0;d--)u+=h(i,r-1,s-d+1,!1,t,n,a);for(var c=1;c<=l;c++)u+=h(i,r,c,!0,t,n,a);for(var p=new Date(i,r,l).getDay(),m=1;p<6;m++,p++)u+=h(i,r+1,m,!1,t,n,a);return u+"
"}(e,t,n,a),"\n
\n "),u}function m(e,t){var i,r,o,s,l,u,d,h,m,g,v;this.element=document.getElementById(e),this.currentDate=new Date,this.currentDate.setDate(1),this.selectedStartDate=null,this.selectedEndDate=null,this.options={mode:null!==(i=null==t?void 0:t.mode)&&void 0!==i?i:"single",onSelect:null!==(r=null==t?void 0:t.onSelect)&&void 0!==r?r:null,blockedDays:null!==(o=null==t?void 0:t.blockedDays)&&void 0!==o?o:[],showDayNames:null===(s=null==t?void 0:t.showDayNames)||void 0===s||s,textInputEnabled:null!==(l=null==t?void 0:t.textInputEnabled)&&void 0!==l&&l,darkMode:null!==(u=null==t?void 0:t.darkMode)&&void 0!==u&&u,usePageLanguage:null!==(d=null==t?void 0:t.usePageLanguage)&&void 0!==d&&d,usePageLanguageFallback:null!==(h=null==t?void 0:t.usePageLanguageFallback)&&void 0!==h?h:"en",language:null!=t&&t.usePageLanguage?c(null==t?void 0:t.usePageLanguageFallback):null!==(m=null==t?void 0:t.language)&&void 0!==m?m:"en",textInputPlaceholder:null!==(g=null==t?void 0:t.textInputPlaceholder)&&void 0!==g?g:a[null!=t&&t.usePageLanguage?c():null!==(v=null==t?void 0:t.language)&&void 0!==v?v:"en"]},this.init=function(){this.options.darkMode&&this.element.classList.add("dark"),this.calendarContainer=p(this.currentDate,this.isDateSelected.bind(this),this.isDateInRange.bind(this),this.options),this.options.textInputEnabled&&(this.input=document.createElement("input"),this.input.value=this.options.textInputPlaceholder,this.input.type="text",this.input.className="datepicker-input",this.input.readOnly=!0,this.element.appendChild(this.input)),this.element.appendChild(this.calendarContainer),this.render(),n(this.element,this.changeMonth.bind(this),this.handleDayClick.bind(this))},this.render=function(){this.element.innerHTML="";var e=p(this.currentDate,this.isDateSelected.bind(this),this.isDateInRange.bind(this),this.options);if(this.options.textInputEnabled&&!this.element.querySelector(".datepicker-input")){var t=document.createElement("input");if(t.value=this.options.textInputPlaceholder,t.type="text",t.id="datepicker-input",t.className="datepicker-input",t.readOnly=!0,this.selectedStartDate)if("single"===this.options.mode)t.value=this.localizedDate(this.selectedStartDate,this.options.language);else if("range"===this.options.mode){var a=this.localizedDate(this.selectedStartDate,this.options.language);this.selectedEndDate&&(a+=" - ".concat(this.localizedDate(this.selectedEndDate,this.options.language))),t.value=a}t.removeEventListener("click",t.listener),t.removeEventListener("keydown",t.listener),t.addEventListener("click",(function(){e.style.display="block"})),t.addEventListener("keydown",(function(t){"Enter"===t.key&&(e.style.display="block"===e.style.display?"none":"block")})),this.element.appendChild(t)}this.element.appendChild(e),n(this.element,this.changeMonth.bind(this),this.handleDayClick.bind(this))},this.localizedDate=function(e,t){return e.toLocaleDateString(t,{year:"numeric",month:"long",day:"numeric"})},this.isDateSelected=function(e){return this.selectedStartDate&&this.selectedStartDate.toDateString()===e.toDateString()||this.selectedEndDate&&this.selectedEndDate.toDateString()===e.toDateString()},this.isDateInRange=function(e){return this.selectedStartDate&&this.selectedEndDate&&e>this.selectedStartDate&&ethis.selectedStartDate?(this.selectedEndDate=i,this.element.querySelector(".datepicker-input")&&(this.element.querySelector(".datepicker-input").value="".concat(this.selectedStartDate.toDateString()," ").concat(void 0!==this.selectedEndDate.toDateString()?"- "+this.selectedEndDate.toDateString():"")),this.triggerSelectCallback(),this.render(),t.textInputEnabled&&(this.element.querySelector(".datepicker-calendar-container").style.display="none")):(this.selectedStartDate=i,this.render(),this.element.querySelector(".datepicker-calendar-container").style.display="block")))},this.changeMonth=function(e){var t,n={currentYear:(t=this.currentDate).getFullYear(),currentMonth:t.getMonth(),currentDay:t.getDate()},a=n.currentYear,i=n.currentDay,r=new Date(a,n.currentMonth+e,1),o=new Date(a,r.getMonth()+1,0).getDate();r.setDate(Math.min(i,o)),this.currentDate=r,this.render(),this.element.querySelector(".datepicker-calendar-container").style.display="block"},this.triggerSelectCallback=function(){this.options.onSelect&&this.options.onSelect(this.selectedStartDate,this.selectedEndDate)}}return t.default})())); \ No newline at end of file diff --git a/dist/datepicker.css b/dist/datepicker.css index 40e2635..f95f381 100644 --- a/dist/datepicker.css +++ b/dist/datepicker.css @@ -1 +1 @@ -@import url(https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap);.datepicker-calendar-container{border:1px solid #ddd}.datepicker-day{background-color:#f0f0f0}.datepicker-day:hover{background-color:#e0e0e0}.datepicker-day.in-range,.datepicker-day.selected{background-color:#4caf50;color:#fff}.datepicker-day.in-range{background-color:#a5d6a7}.datepicker-day.blocked{background-color:#f8f8f8;color:#ccc}.datepicker-day-names{background-color:#e0e0e0}.datepicker-day-names>div{color:#000}button.next-month:hover,button.prev-month:hover{background-color:#e0e0e0}.dark .datepicker-calendar-container{background-color:#222;border:1px solid #555;color:#eee}.dark .datepicker-header{border-bottom:1px solid #444}.dark .datepicker-day{background-color:#333;color:#ddd}.dark .datepicker-day:hover{background-color:#444}.dark .datepicker-day.in-range,.dark .datepicker-day.selected{background-color:#3a5fd8}.dark .datepicker-day.in-range{background-color:#5675d8}.dark .datepicker-day.blocked{background-color:#1c1c1c;color:#aaa}.dark .datepicker-day-names{background-color:#3a5fd8}.dark .datepicker-day-names>div{color:#ccc}.dark button.next-month,.dark button.prev-month{background-color:#3a5fd8;color:#ccc}.dark button.next-month:hover,.dark button.prev-month:hover{background-color:#2e4cae}.ja .datepicker-calendar-container{height:385px}.ja .datepicker-day{align-items:center;border-radius:5px;cursor:pointer;display:flex;font-size:smaller;height:50px;justify-content:center}.zh-CN .datepicker-calendar-container,.zh-TW .datepicker-calendar-container{height:385px}.zh-CN .datepicker-day,.zh-TW .datepicker-day{align-items:center;border-radius:5px;cursor:pointer;display:flex;font-size:smaller;height:50px;justify-content:center}.datepicker-input{border:1px solid #ddd;border-radius:5px;display:inline-block;font-family:Roboto,sans-serif;height:20px;padding:3px 7px}.datepicker-calendar-container{border-radius:5px;font-family:Roboto,sans-serif;margin-top:1px;padding:10px;width:275px}.datepicker-header{align-items:center;border-radius:5px;display:flex;justify-content:space-between;margin:0 0 10px;padding:5px}.datepicker-day{border-radius:50%;cursor:pointer;display:inline-block;height:30px;line-height:30px;margin:0 0 5px 5px;text-align:center;width:30px}.datepicker-day>span{display:block}.datepicker-day-names,.datepicker-week{display:grid;grid-template-columns:repeat(7,minmax(0,1fr));text-align:center}.datepicker-day-names{border-radius:5px;margin:0 3px 5px;padding:5px 0}.datepicker-day.blocked{cursor:not-allowed}button.next-month,button.prev-month{border:none;border-radius:5px;padding:5px 12px;transition:all .1s ease-in-out} \ No newline at end of file +@import url(https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap);.datepicker-calendar-container{border:1px solid #ddd}.datepicker-day{background-color:#f0f0f0}.datepicker-day:hover{background-color:#e0e0e0}.datepicker-day.in-range,.datepicker-day.selected{background-color:#4caf50;color:#fff}.datepicker-day.in-range{background-color:#a5d6a7}.datepicker-day.blocked{background-color:#f8f8f8;color:#ccc}.datepicker-day-names{background-color:#efefef}.datepicker-day-names>div{color:#000}button.next-month:hover,button.prev-month:hover{background-color:#e0e0e0}.dark .datepicker-calendar-container{background-color:#222;border:1px solid #555;color:#eee}.dark .datepicker-header{border-bottom:1px solid #444}.dark .datepicker-day{background-color:#333;color:#ddd}.dark .datepicker-day:hover{background-color:#444}.dark .datepicker-day.in-range,.dark .datepicker-day.selected{background-color:#3a5fd8}.dark .datepicker-day.in-range{background-color:#5675d8}.dark .datepicker-day.blocked{background-color:#1c1c1c;color:#aaa}.dark .datepicker-day-names{background-color:#3a5fd8}.dark .datepicker-day-names>div{color:#ccc}.dark button.next-month,.dark button.prev-month{background-color:#3a5fd8;color:#ccc}.dark button.next-month:hover,.dark button.prev-month:hover{background-color:#2e4cae}.ja .datepicker-calendar-container{height:385px}.ja .datepicker-day,.ko .datepicker-day{align-items:center;border-radius:5px;cursor:pointer;display:flex;font-size:smaller;height:50px;justify-content:center}.zh-CN .datepicker-calendar-container,.zh-TW .datepicker-calendar-container{height:385px}.ko .datepicker-day,.zh-CN .datepicker-day,.zh-TW .datepicker-day{align-items:center;border-radius:5px;display:flex;font-size:smaller;height:50px;justify-content:center}.datepicker-input{border:1px solid #ddd;border-radius:5px;display:inline-block;font-family:Roboto,sans-serif;height:20px;padding:3px 7px}.datepicker-calendar-container{border-radius:5px;font-family:Roboto,sans-serif;margin-top:1px;padding:10px;width:275px}.datepicker-header{align-items:center;border-radius:5px;display:flex;justify-content:space-between;margin:0 0 10px;padding:5px}.datepicker-day{border-radius:50%;cursor:pointer;display:inline-block;height:30px;line-height:30px;margin:0 0 5px 5px;text-align:center;width:30px}.datepicker-day>span{display:block}.datepicker-day-names,.datepicker-week{display:grid;grid-template-columns:repeat(7,minmax(0,1fr));text-align:center}.datepicker-day-names{border-radius:5px;margin:0 3px 5px;padding:5px 0}.datepicker-day.blocked{cursor:not-allowed}button.next-month,button.prev-month{border:none;border-radius:5px;padding:5px 12px;transition:all .1s ease-in-out} \ No newline at end of file diff --git a/example/index.html b/example/index.html index 1e30e83..fab28ea 100644 --- a/example/index.html +++ b/example/index.html @@ -1,5 +1,5 @@ - + @@ -25,7 +25,7 @@ blockedDays: [0, 6], // Prevent Saturday and Sunday from being selected showDayNames: true, textInputEnabled: true, // Show input field, calendar displays on click - darkMode: false, + darkMode: true, language: 'en', // language ISO code, defaults to en -> ignored if usePageLanguage is true usePageLanguage: true, // Looks for a lang attribute on the page, and if the language is supported, uses it usePageLanguageFallback: 'en', // If usePageLanguage is true, and the page language is not supported, use this language diff --git a/package.json b/package.json index 194bd10..d79c2e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "easy-dates-picker", - "version": "0.0.21", + "version": "0.0.22", "description": "A super lightweight vanilla JS date picker", "main": "dist/datepicker.bundle.js", "files": [ @@ -10,7 +10,7 @@ "build": "webpack", "test": "jest", "prettier": "prettier src/ --write && prettier example --write", - "prepare": "npm run prettier && npm run test && npm run build && git status" + "prep": "npm run prettier && npm run test && npm run build && git status" }, "jest": { "moduleNameMapper": { diff --git a/src/calendarGenerator.js b/src/calendarGenerator.js index 6777f80..7873e0a 100644 --- a/src/calendarGenerator.js +++ b/src/calendarGenerator.js @@ -1,5 +1,5 @@ import { isLeapYear } from './utils'; -import { dayNameTranslations, chineseDaysOfMonth, japaneseDaysOfMonth } from './localization'; +import { dayNameTranslations, chineseDaysOfMonth, japaneseDaysOfMonth, koreanDaysOfMonth, thaiDaysOfMonth } from './localization'; export function generateDayNames(language) { const dayNames = dayNameTranslations[language]; @@ -47,6 +47,10 @@ export function generateDayCell(year, month, day, isCurrentMonth, isDateSelected dayDisplay = japaneseDaysOfMonth[day]; } else if (options.language === 'zh-CN' || options.language === 'zh-TW') { dayDisplay = chineseDaysOfMonth[options.language][day]; + } else if (options.language === 'ko') { + dayDisplay = koreanDaysOfMonth[day]; + } else if (options.language === 'th') { + dayDisplay = thaiDaysOfMonth[day]; } let className = isCurrentMonth ? 'datepicker-day current-month' : 'datepicker-day'; diff --git a/src/localization.js b/src/localization.js index 101360b..77f841c 100644 --- a/src/localization.js +++ b/src/localization.js @@ -7,9 +7,30 @@ export const inputPlaceholderTranslations = { nl: 'Kies een datum', pt: 'Escolha uma data', ja: '日付を選択', - 'zh-CN': '选择日期', // Simplified Chinese - 'zh-TW': '選擇日期', // Traditional Chinese + 'zh-CN': '选择日期', + 'zh-TW': '選擇日期', ru: 'Выберите дату', + 'bg-BG': 'Изберете дата', + cs: 'Vyberte datum', + da: 'Vælg en dato', + el: 'Επιλέξτε μια ημερομηνία', + fi: 'Valitse päivämäärä', + 'hr-HR': 'Odaberite datum', + hu: 'Válasszon egy dátumot', + id: 'Pilih tanggal', + ko: '날짜를 선택하세요', + 'lt-LT': 'Pasirinkite datą', + nb: 'Velg en dato', + pl: 'Wybierz datę', + 'pt-BR': 'Escolha uma data', + 'pt-PT': 'Escolha uma data', + 'ro-RO': 'Alegeți o dată', + 'sk-SK': 'Vyberte dátum', + 'sl-SL': 'Izberite datum', + sv: 'Välj ett datum', + th: 'เลือกวันที่', + tr: 'Bir tarih seçin', + vi: 'Chọn ngày', }; export const ariaLabels = { @@ -21,9 +42,30 @@ export const ariaLabels = { 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: '转到下一个月' }, // Simplified Chinese - 'zh-TW': { prevMonth: '轉到上一個月', nextMonth: '轉到下一個月' }, // Traditional Chinese + 'zh-CN': { prevMonth: '转到上一个月', nextMonth: '转到下一个月' }, + 'zh-TW': { prevMonth: '轉到上一個月', nextMonth: '轉到下一個月' }, ru: { prevMonth: 'Перейти к предыдущему месяцу', nextMonth: 'Перейти к следующему месяцу' }, + 'bg-BG': { prevMonth: 'Отиди на предишния месец', nextMonth: 'Отиди на следващия месец' }, + cs: { prevMonth: 'Přejít na předchozí měsíc', nextMonth: 'Přejít na další měsíc' }, + da: { prevMonth: 'Gå til forrige måned', nextMonth: 'Gå til næste måned' }, + el: { prevMonth: 'Μετάβαση στον προηγούμενο μήνα', nextMonth: 'Μετάβαση στον επόμενο μήνα' }, + fi: { prevMonth: 'Siirry edelliseen kuukauteen', nextMonth: 'Siirry seuraavaan kuukauteen' }, + 'hr-HR': { prevMonth: 'Idi na prethodni mjesec', nextMonth: 'Idi na sljedeći mjesec' }, + hu: { prevMonth: 'Ugrás az előző hónaphoz', nextMonth: 'Ugrás a következő hónaphoz' }, + id: { prevMonth: 'Pergi ke bulan sebelumnya', nextMonth: 'Pergi ke bulan berikutnya' }, + ko: { prevMonth: '이전 달로 가기', nextMonth: '다음 달로 가기' }, + 'lt-LT': { prevMonth: 'Eiti į ankstesnį mėnesį', nextMonth: 'Eiti į kitą mėnesį' }, + nb: { prevMonth: 'Gå til forrige måned', nextMonth: 'Gå til neste måned' }, + pl: { prevMonth: 'Przejdź do poprzedniego miesiąca', nextMonth: 'Przejdź do następnego miesiąca' }, + 'pt-BR': { prevMonth: 'Ir para o mês anterior', nextMonth: 'Ir para o próximo mês' }, + 'pt-PT': { prevMonth: 'Ir para o mês anterior', nextMonth: 'Ir para o próximo mês' }, + 'ro-RO': { prevMonth: 'Mergi la luna anterioară', nextMonth: 'Mergi la luna următoare' }, + 'sk-SK': { prevMonth: 'Prejsť na predchádzajúci mesiac', nextMonth: 'Prejsť na nasledujúci mesiac' }, + 'sl-SL': { prevMonth: 'Pojdi na prejšnji mesec', nextMonth: 'Pojdi na naslednji mesec' }, + sv: { prevMonth: 'Gå till föregående månad', nextMonth: 'Gå till nästa månad' }, + th: { prevMonth: 'ไปยังเดือนก่อนหน้า', nextMonth: 'ไปยังเดือนถัดไป' }, + tr: { prevMonth: 'Önceki aya git', nextMonth: 'Sonraki aya git' }, + vi: { prevMonth: 'Đi đến tháng trước', nextMonth: 'Đi đến tháng sau' }, }; export const monthNameTranslations = { @@ -35,23 +77,169 @@ export const monthNameTranslations = { 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': ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'], // Simplified Chinese - 'zh-TW': ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'], // Traditional Chinese + 'zh-CN': ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'], + 'zh-TW': ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'], ru: ['Январь', 'Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентяюрь', 'Октябрь', 'Ноябрь', 'Декабрь'], + 'bg-BG': ['Януари', 'Февруари', 'Март', 'Април', 'Май', 'Юни', 'Юли', 'Август', 'Септември', 'Октомври', 'Ноември', 'Декември'], + cs: ['Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec'], + da: ['Januar', 'Februar', 'Marts', 'April', 'Maj', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'December'], + el: [ + 'Ιανουάριος', + 'Φεβρουάριος', + 'Μάρτιος', + 'Απρίλιος', + 'Μάιος', + 'Ιούνιος', + 'Ιούλιος', + 'Αύγουστος', + 'Σεπτέμβριος', + 'Οκτώβριος', + 'Νοέμβριος', + 'Δεκέμβριος', + ], + fi: [ + 'Tammikuu', + 'Helmikuu', + 'Maaliskuu', + 'Huhtikuu', + 'Toukokuu', + 'Kesäkuu', + 'Heinäkuu', + 'Elokuu', + 'Syyskuu', + 'Lokakuu', + 'Marraskuu', + 'Joulukuu', + ], + 'hr-HR': [ + 'Siječanj', + 'Veljača', + 'Ožujak', + 'Travanj', + 'Svibanj', + 'Lipanj', + 'Srpanj', + 'Kolovoz', + 'Rujan', + 'Listopad', + 'Studeni', + 'Prosinac', + ], + hu: [ + 'Január', + 'Február', + 'Március', + 'Április', + 'Május', + 'Június', + 'Július', + 'Augusztus', + 'Szeptember', + 'Október', + 'November', + 'December', + ], + id: ['Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember'], + ko: ['1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월'], + 'lt-LT': [ + 'Sausis', + 'Vasaris', + 'Kovas', + 'Balandis', + 'Gegužė', + 'Birželis', + 'Liepa', + 'Rugpjūtis', + 'Rugsėjis', + 'Spalis', + 'Lapkritis', + 'Gruodis', + ], + nb: ['Januar', 'Februar', 'Mars', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Desember'], + pl: ['Styczeń', 'Luty', 'Marzec', 'Kwiecień', 'Maj', 'Czerwiec', 'Lipiec', 'Sierpień', 'Wrzesień', 'Październik', 'Listopad', 'Grudzień'], + 'pt-BR': ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'], + 'pt-PT': ['Janeiro', 'Fevereiro', 'Março', 'Abril', 'Maio', 'Junho', 'Julho', 'Agosto', 'Setembro', 'Outubro', 'Novembro', 'Dezembro'], + 'ro-RO': [ + 'Ianuarie', + 'Februarie', + 'Martie', + 'Aprilie', + 'Mai', + 'Iunie', + 'Iulie', + 'August', + 'Septembrie', + 'Octombrie', + 'Noiembrie', + 'Decembrie', + ], + 'sk-SK': ['Január', 'Február', 'Marec', 'Apríl', 'Máj', 'Jún', 'Júl', 'August', 'September', 'Október', 'November', 'December'], + 'sl-SL': ['Januar', 'Februar', 'Marec', 'April', 'Maj', 'Junij', 'Julij', 'Avgust', 'September', 'Oktober', 'November', 'December'], + sv: ['Januari', 'Februari', 'Mars', 'April', 'Maj', 'Juni', 'Juli', 'Augusti', 'September', 'Oktober', 'November', 'December'], + th: [ + 'มกราคม', + 'กุมภาพันธ์', + 'มีนาคม', + 'เมษายน', + 'พฤษภาคม', + 'มิถุนายน', + 'กรกฎาคม', + 'สิงหาคม', + 'กันยายน', + 'ตุลาคม', + 'พฤศจิกายน', + 'ธันวาคม', + ], + tr: ['Ocak', 'Şubat', 'Mart', 'Nisan', 'Mayıs', 'Haziran', 'Temmuz', 'Ağustos', 'Eylül', 'Ekim', 'Kasım', 'Aralık'], + vi: [ + 'Tháng Một', + 'Tháng Hai', + 'Tháng Ba', + 'Tháng Tư', + 'Tháng Năm', + 'Tháng Sáu', + 'Tháng Bảy', + 'Tháng Tám', + 'Tháng Chín', + 'Tháng Mười', + 'Tháng Mười Một', + 'Tháng Mười Hai', + ], }; export const dayNameTranslations = { - en: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], // English - fr: ['Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam'], // French - es: ['Dom', 'Lun', 'Mar', 'Mié', 'Jue', 'Vie', 'Sáb'], // Spanish - de: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'], // German - it: ['Dom', 'Lun', 'Mar', 'Mer', 'Gio', 'Ven', 'Sab'], // Italian - nl: ['Zo', 'Ma', 'Di', 'Wo', 'Do', 'Vr', 'Za'], // Dutch - pt: ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'], // Portuguese - ja: ['日', '月', '火', '水', '木', '金', '土'], // Japanese - 'zh-CN': ['日', '一', '二', '三', '四', '五', '六'], // Simplified Chinese - 'zh-TW': ['日', '一', '二', '三', '四', '五', '六'], // Traditional Chinese - ru: ['Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'], // Russian + 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: ['Вс', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'], + 'bg-BG': ['Нд', 'Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб'], + cs: ['Ne', 'Po', 'Út', 'St', 'Čt', 'Pá', 'So'], + da: ['Søn', 'Man', 'Tir', 'Ons', 'Tor', 'Fre', 'Lør'], + el: ['Κυρ', 'Δευ', 'Τρί', 'Τετ', 'Πέμ', 'Παρ', 'Σάβ'], + fi: ['Su', 'Ma', 'Ti', 'Ke', 'To', 'Pe', 'La'], + 'hr-HR': ['Ned', 'Pon', 'Uto', 'Sri', 'Čet', 'Pet', 'Sub'], + hu: ['V', 'H', 'K', 'Sze', 'Cs', 'P', 'Szo'], + id: ['Min', 'Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab'], + ko: ['일', '월', '화', '수', '목', '금', '토'], + 'lt-LT': ['Sek', 'Pir', 'Ant', 'Tre', 'Ket', 'Pen', 'Šeš'], + nb: ['Søn', 'Man', 'Tir', 'Ons', 'Tor', 'Fre', 'Lør'], + pl: ['N', 'Pn', 'Wt', 'Śr', 'Cz', 'Pt', 'Sob'], + 'pt-BR': ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'], + 'pt-PT': ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sáb'], + 'ro-RO': ['Dum', 'Lun', 'Mar', 'Mie', 'Joi', 'Vin', 'Sâm'], + 'sk-SK': ['Ne', 'Po', 'Ut', 'St', 'Št', 'Pi', 'So'], + 'sl-SL': ['Ned', 'Pon', 'Tor', 'Sre', 'Čet', 'Pet', 'Sob'], + sv: ['Sön', 'Mån', 'Tis', 'Ons', 'Tor', 'Fre', 'Lör'], + th: ['อา.', 'จ.', 'อ.', 'พ.', 'พฤ.', 'ศ.', 'ส.'], + tr: ['Paz', 'Pzt', 'Sal', 'Çar', 'Per', 'Cum', 'Cts'], + vi: ['CN', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7'], }; export const japaneseDaysOfMonth = { @@ -90,7 +278,6 @@ export const japaneseDaysOfMonth = { export const chineseDaysOfMonth = { 'zh-CN': { - // Simplified Chinese 1: '一', 2: '二', 3: '三', @@ -124,7 +311,6 @@ export const chineseDaysOfMonth = { 31: '三十一', }, 'zh-TW': { - // Traditional Chinese 1: '一', 2: '二', 3: '三', @@ -158,3 +344,71 @@ export const chineseDaysOfMonth = { 31: '三十一', }, }; + +export const koreanDaysOfMonth = { + 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: '삼십일', +}; + +export const thaiDaysOfMonth = { + 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: '๓๑', +}; diff --git a/src/utils.js b/src/utils.js index ed03306..9cc162f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -9,7 +9,40 @@ export function isLeapYear(year) { } export function getPageLanguage(fallbackLang) { - const supportedLanguages = ['en', 'fr', 'es', 'de', 'it', 'nl', 'pt', 'ja', 'zh-CN', 'zh-TW', 'ru']; + const supportedLanguages = [ + 'en', + 'fr', + 'es', + 'de', + 'it', + 'nl', + 'pt', + 'ja', + 'zh-CN', + 'zh-TW', + 'ru', + 'bg-BG', + 'cs', + 'da', + 'el', + 'fi', + 'hr-HR', + 'hu', + 'id', + 'ko', + 'lt-LT', + 'nb', + 'pl', + 'pt-BR', + 'pt-PT', + 'ro-RO', + 'sk-SK', + 'sl-SL', + 'sv', + 'th', + 'tr', + 'vi', + ]; const documentPageLang = document.documentElement.lang; // Check if the page language is supported, if not, default to English return supportedLanguages.includes(documentPageLang) ? documentPageLang : fallbackLang;