summaryrefslogtreecommitdiff
path: root/packages/create-astro/src
diff options
context:
space:
mode:
authorGravatar Nate Moore <natemoo-re@users.noreply.github.com> 2022-05-18 10:45:09 -0500
committerGravatar GitHub <noreply@github.com> 2022-05-18 10:45:09 -0500
commitcf8015eaa2b756f4ec399e8fd7071dee7dfa9ab6 (patch)
treeb7f7ec25cb31b46cc528c79080ea29cc05d2b1c2 /packages/create-astro/src
parent6cec1b8ef27f2548f949b2fcef85d94a3c599dc2 (diff)
downloadastro-cf8015eaa2b756f4ec399e8fd7071dee7dfa9ab6.tar.gz
astro-cf8015eaa2b756f4ec399e8fd7071dee7dfa9ab6.tar.zst
astro-cf8015eaa2b756f4ec399e8fd7071dee7dfa9ab6.zip
fix: locale handling for logger (#3391)
* fix(#3309): use system default locale * fix(#3309): use system default locale in create-astro * test: add locale regression tests * test: add i18n regression test
Diffstat (limited to 'packages/create-astro/src')
-rw-r--r--packages/create-astro/src/logger.ts23
1 files changed, 11 insertions, 12 deletions
diff --git a/packages/create-astro/src/logger.ts b/packages/create-astro/src/logger.ts
index 65f354632..96965e7ea 100644
--- a/packages/create-astro/src/logger.ts
+++ b/packages/create-astro/src/logger.ts
@@ -6,20 +6,19 @@ type ConsoleStream = Writable & {
fd: 1 | 2;
};
-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;
- } else return defaultLocale;
-}
-
-const dt = 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
+const dt = new Intl.DateTimeFormat([], {
hour: '2-digit',
minute: '2-digit',
+ second: '2-digit',
});
export const defaultLogDestination = new Writable({