diff --git a/README.md b/README.md index 65ff7d8b..5a6e44be 100644 --- a/README.md +++ b/README.md @@ -43,27 +43,28 @@ The `user` field is the only required option. All other fields are optional. If the `theme` parameter is specified, any color customizations specified will be applied on top of the theme, overriding the theme's values. -| Parameter | Details | Example | -| :------------------: | :---------------------------------------------: | :------------------------------------------------------------------------------------------------: | -| `user` | GitHub username to show stats for | `DenverCoder1` | -| `theme` | The theme to apply (Default: `default`) | `dark`, `radical`, etc. [๐ŸŽจโžœ](./docs/themes.md) | -| `hide_border` | Make the border transparent (Default: `false`) | `true` or `false` | -| `border_radius` | Set the roundness of the edges (Default: `4.5`) | Number `0` (sharp corners) to `248` (ellipse) | -| `background` | Background color (eg. `f2f2f2`, `35,d22,00f`) | **hex code** without `#`, **css color**, or gradient in the form `angle,start_color,...,end_color` | -| `border` | Border color | **hex code** without `#` or **css color** | -| `stroke` | Stroke line color between sections | **hex code** without `#` or **css color** | -| `ring` | Color of the ring around the current streak | **hex code** without `#` or **css color** | -| `fire` | Color of the fire in the ring | **hex code** without `#` or **css color** | -| `currStreakNum` | Current streak number | **hex code** without `#` or **css color** | -| `sideNums` | Total and longest streak numbers | **hex code** without `#` or **css color** | -| `currStreakLabel` | Current streak label | **hex code** without `#` or **css color** | -| `sideLabels` | Total and longest streak labels | **hex code** without `#` or **css color** | -| `dates` | Date range text color | **hex code** without `#` or **css color** | -| `date_format` | Date format pattern or empty for locale format | See note below on [๐Ÿ“… Date Formats](#-date-formats) | -| `locale` | Locale for labels and numbers (Default: `en`) | ISO 639-1 code - See [๐Ÿ—ช Locales](#-locales) | -| `type` | Output format (Default: `svg`) | Current options: `svg`, `png` or `json` | -| `mode` | Streak mode (Default: `daily`) | `daily` (contribute daily) or `weekly` (contribute once per Sun-Sat week) | -| `disable_animations` | Disable SVG animations (Default: `false`) | `true` or `false` | +| Parameter | Details | Example | +| :------------------: | :----------------------------------------------: | :------------------------------------------------------------------------------------------------: | +| `user` | GitHub username to show stats for | `DenverCoder1` | +| `theme` | The theme to apply (Default: `default`) | `dark`, `radical`, etc. [๐ŸŽจโžœ](./docs/themes.md) | +| `hide_border` | Make the border transparent (Default: `false`) | `true` or `false` | +| `border_radius` | Set the roundness of the edges (Default: `4.5`) | Number `0` (sharp corners) to `248` (ellipse) | +| `background` | Background color (eg. `f2f2f2`, `35,d22,00f`) | **hex code** without `#`, **css color**, or gradient in the form `angle,start_color,...,end_color` | +| `border` | Border color | **hex code** without `#` or **css color** | +| `stroke` | Stroke line color between sections | **hex code** without `#` or **css color** | +| `ring` | Color of the ring around the current streak | **hex code** without `#` or **css color** | +| `fire` | Color of the fire in the ring | **hex code** without `#` or **css color** | +| `currStreakNum` | Current streak number | **hex code** without `#` or **css color** | +| `sideNums` | Total and longest streak numbers | **hex code** without `#` or **css color** | +| `currStreakLabel` | Current streak label | **hex code** without `#` or **css color** | +| `sideLabels` | Total and longest streak labels | **hex code** without `#` or **css color** | +| `dates` | Date range text color | **hex code** without `#` or **css color** | +| `date_format` | Date format pattern or empty for locale format | See note below on [๐Ÿ“… Date Formats](#-date-formats) | +| `locale` | Locale for labels and numbers (Default: `en`) | ISO 639-1 code - See [๐Ÿ—ช Locales](#-locales) | +| `type` | Output format (Default: `svg`) | Current options: `svg`, `png` or `json` | +| `mode` | Streak mode (Default: `daily`) | `daily` (contribute daily) or `weekly` (contribute once per Sun-Sat week) | +| `exclude_days` | List of days of the week to exclude from streaks | Comma-separated list of day abbreviations (Sun,Mon,Tue,Wed,Thu,Fri,Sat) e.g. `Sun,Sat` | +| `disable_animations` | Disable SVG animations (Default: `false`) | `true` or `false` | ### ๐Ÿ–Œ Themes diff --git a/scripts/translation-progress.php b/scripts/translation-progress.php index 1849f686..030fff9c 100644 --- a/scripts/translation-progress.php +++ b/scripts/translation-progress.php @@ -17,6 +17,7 @@ function getProgress(array $translations): array "Week Streak", "Longest Week Streak", "Present", + "Excluding", ]; $translations_file = file(__DIR__ . "/../src/translations.php"); diff --git a/src/card.php b/src/card.php index 66b5b2a5..df469cb2 100644 --- a/src/card.php +++ b/src/card.php @@ -53,6 +53,37 @@ function formatDate(string $dateString, string|null $format, string $locale): st return htmlspecialchars($formatted); } +/** + * Translate days of the week + * + * Takes a list of days (eg. ["Sun", "Mon", "Sat"]) and returns the short abbreviation of the days of the week in another locale + * e.g. ["Sun", "Mon", "Sat"] -> ["dim", "lun", "sam"] + * + * @param array $days List of days to translate + * @param string $locale Locale code + * + * @return array Translated days + */ +function translateDays(array $days, string $locale): array +{ + if ($locale === "en") { + return $days; + } + $patternGenerator = new IntlDatePatternGenerator($locale); + $pattern = $patternGenerator->getBestPattern("EEE"); + $dateFormatter = new IntlDateFormatter( + $locale, + IntlDateFormatter::NONE, + IntlDateFormatter::NONE, + pattern: $pattern + ); + $translatedDays = []; + foreach ($days as $day) { + $translatedDays[] = $dateFormatter->format(new DateTime($day)); + } + return $translatedDays; +} + /** * Normalize a theme name * @@ -335,6 +366,21 @@ function generateCard(array $stats, array $params = null): string $currentStreakRange = splitLines($currentStreakRange, 28, 0); $longestStreakRange = splitLines($longestStreakRange, 28, 0); + // if days are excluded, add a note to the corner + $excludedDays = ""; + if (!empty($stats["excludedDays"])) { + $daysCommaSeparated = implode(", ", translateDays($stats["excludedDays"], $localeCode)); + $offset = $direction === "rtl" ? 495 - 5 : 5; + $excludedDays = " + + + + * {$localeTranslations["Excluding"]} {$daysCommaSeparated} + + + "; + } + return " "; diff --git a/src/demo/css/style.css b/src/demo/css/style.css index 3b3a5446..c7215da5 100644 --- a/src/demo/css/style.css +++ b/src/demo/css/style.css @@ -185,6 +185,35 @@ h2 { text-transform: capitalize; } +.weekdays input { + display: none !important; +} + +.weekdays input[type="checkbox"] + label { + font-size: 90%; + display: inline-block; + border-radius: 6px; + height: 30px; + width: 30px; + margin-right: 3px; + line-height: 28px; + text-align: center; + cursor: pointer; + background: var(--card-background); + color: var(--text); + border: 1px solid var(--border); +} + +.weekdays input[type="checkbox"]:checked + label { + background: var(--text); + color: var(--background); +} + +.weekdays input[type="checkbox"]:disabled + label { + background: var(--card-background); + color: var(--stroke); +} + span[title="required"] { color: var(--red); } diff --git a/src/demo/index.php b/src/demo/index.php index bd3580ce..573de37e 100644 --- a/src/demo/index.php +++ b/src/demo/index.php @@ -137,6 +137,25 @@ function gtag() { + +
+ + + + + + + + + + + + + + + +
+