Last active
October 5, 2025 13:00
-
-
Save Sheraff/c74fd217a4f6f6e27e6feae04a4bf12c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getSupportedLocales(): string[] { | |
| const candidates: string[] = [] | |
| const letters = Array.from({ length: 26 }, (_, i) => String.fromCharCode(65 + i)) | |
| for (const a of letters) { | |
| for (const b of letters) { | |
| candidates.push(a + b) | |
| for (const c of letters) { | |
| candidates.push(a + b + c) | |
| } | |
| } | |
| } | |
| return Intl.getCanonicalLocales(Intl.DateTimeFormat.supportedLocalesOf(candidates)) | |
| } | |
| let locales: string[] | |
| /** | |
| * Get the translation of a day in every Intl-supported locale | |
| * | |
| * @param day 1=Monday ... 7=Sunday | |
| * @returns A set translations of the given day | |
| */ | |
| export function getDayTranslations(day: 1 | 2 | 3 | 4 | 5 | 6 | 7) { | |
| locales ||= getSupportedLocales() | |
| const result = new Set<string>() | |
| const date = new Date() | |
| date.setDate(date.getDate() + (day + 7 - date.getDay()) % 7) | |
| const format = { weekday: 'long' } as const | |
| for (const locale of locales) { | |
| const dayName = new Intl.DateTimeFormat(locale, format).format(date) | |
| result.add(dayName) | |
| } | |
| return result | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment