Skip to content

Commit

Permalink
fix(#3309): use system default locale
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate Moore committed May 17, 2022
1 parent f54072b commit 510b14c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/thirty-drinks-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix [#3309](https://github.com/withastro/astro/issues/3309) default logger locale behavior.
22 changes: 10 additions & 12 deletions packages/astro/src/core/logger/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 510b14c

Please sign in to comment.