MCPcopy Create free account
hub / github.com/adobe/react-spectrum / getDefaultLocale

Function getDefaultLocale

packages/react-aria/src/i18n/useDefaultLocale.ts:24–40  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22 * Gets the locale setting of the browser.
23 */
24export function getDefaultLocale(): Locale {
25 let locale =
26 (typeof window !== 'undefined' && window[localeSymbol]) ||
27 // @ts-ignore
28 (typeof navigator !== 'undefined' && (navigator.language || navigator.userLanguage)) ||
29 'en-US';
30
31 try {
32 Intl.DateTimeFormat.supportedLocalesOf([locale]);
33 } catch {
34 locale = 'en-US';
35 }
36 return {
37 locale,
38 direction: isRTL(locale) ? 'rtl' : 'ltr'
39 };
40}
41
42let currentLocale = getDefaultLocale();
43let listeners = new Set<(locale: Locale) => void>();

Callers 2

updateLocaleFunction · 0.85

Calls 1

isRTLFunction · 0.90

Tested by

no test coverage detected