Intl.Locale Exposes Week And Text Direction

Query runtime ICU regional defaults from Intl.Locale using getWeekInfo, getTextInfo, and getCalendars for week starts, weekends, and text direction.

JavascriptConfig Management

Code

snippet
const tags = ['en-US', 'de-DE', 'ar-EG', 'ja-JP-u-ca-japanese'];

for (const tag of tags) {
  const locale = new Intl.Locale(tag);
  const week = locale.getWeekInfo();
  const text = locale.getTextInfo();
  const calendars = locale.getCalendars();
  console.log(
    tag.padEnd(18),
    'dir:', text.direction,
    '| firstDay:', week.firstDay,
    '| weekend:', week.weekend.join(','),
    '| cal:', calendars[0],
  );
}

Output

Captured from a sandboxed run of this snippet in the build pipeline.

en-US              dir: ltr | firstDay: 7 | weekend: 6,7 | cal: gregory
de-DE              dir: ltr | firstDay: 1 | weekend: 6,7 | cal: gregory
ar-EG              dir: rtl | firstDay: 6 | weekend: 5,6 | cal: gregory
ja-JP-u-ca-japanese dir: ltr | firstDay: 7 | weekend: 6,7 | cal: japanese

Code mechanics — Intl.Locale Exposes Week And Text Direction

One loop does the cycling here: for (const tag of tags).

All sample computations reference top-level declarations: tags.

What to watch for

  • The environment needs no preparation beyond having the interpreter or compiler.

Core lines

const locale = new Intl.Locale(tag);

Interactive Tools for This Topic

FAQ

Does the code pull in any external packages?
No external packages are involved; every call resolves to a built-in API. Its state lives in module-level bindings: `tags`.