Skip to content

Commit

Permalink
Feat: Add languages
Browse files Browse the repository at this point in the history
  • Loading branch information
sandypockets committed Dec 9, 2023
1 parent 4f144df commit 011e3d0
Show file tree
Hide file tree
Showing 8 changed files with 1,059 additions and 61 deletions.
775 changes: 741 additions & 34 deletions __tests__/datePicker.localization.test.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/datepicker.bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/datepicker.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html lang="en">
<html lang="th">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -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": {
Expand Down
6 changes: 5 additions & 1 deletion src/calendarGenerator.js
Original file line number Diff line number Diff line change
@@ -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];
Expand Down Expand Up @@ -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';
Expand Down
Loading

0 comments on commit 011e3d0

Please sign in to comment.