From 510b14cd0d6f44e821621ce06042ff8a852db0b7 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Tue, 17 May 2022 15:25:15 -0500 Subject: [PATCH] fix(#3309): use system default locale --- .changeset/thirty-drinks-shout.md | 5 +++++ packages/astro/src/core/logger/core.ts | 22 ++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 .changeset/thirty-drinks-shout.md diff --git a/.changeset/thirty-drinks-shout.md b/.changeset/thirty-drinks-shout.md new file mode 100644 index 0000000000000..d749298a3212e --- /dev/null +++ b/.changeset/thirty-drinks-shout.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix [#3309](https://github.com/withastro/astro/issues/3309) default logger locale behavior. diff --git a/packages/astro/src/core/logger/core.ts b/packages/astro/src/core/logger/core.ts index bfe5287f365a1..46045fd811551 100644 --- a/packages/astro/src/core/logger/core.ts +++ b/packages/astro/src/core/logger/core.ts @@ -14,18 +14,16 @@ export interface LogOptions { level: LoggerLevel; } -function getLoggerLocale(): string { - const defaultLocale = 'en-US'; - if (process.env.LANG) { - const extractedLocale = process.env.LANG.split('.')[0].replace(/_/g, '-'); - // Check if language code is atleast two characters long (ie. en, es). - // NOTE: if "c" locale is encountered, the default locale will be returned. - if (extractedLocale.length < 2) return defaultLocale; - else return extractedLocale.substring(0, 5); - } else return defaultLocale; -} - -export const dateTimeFormat = new Intl.DateTimeFormat(getLoggerLocale(), { +// Hey, locales are pretty complicated! Be careful modifying this logic... +// If we throw at the top-level, international users can't use Astro. +// +// Using `[]` sets the default locale properly from the system! +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#parameters +// +// Here be the dragons we've slain: +// https://github.com/withastro/astro/issues/2625 +// https://github.com/withastro/astro/issues/3309 +export const dateTimeFormat = new Intl.DateTimeFormat([], { hour: '2-digit', minute: '2-digit', second: '2-digit',