MCPcopy Index your code
hub / github.com/plotly/dash / getUserLocale

Function getUserLocale

components/dash-core-components/src/utils/calendar/helpers.ts:48–72  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46 * externally on the page from the assets folder or via a script tag
47 */
48export function getUserLocale(): Locale | undefined {
49 // Check if page has loaded any external locales
50 const availableLocales = window.dateFns?.locale ?? {};
51
52 // Match available locales against user locale preferences
53 const localeKeys = Object.keys(availableLocales);
54 const userLanguages = navigator.languages || [navigator.language];
55 for (const lang of userLanguages) {
56 // First check full locale string for regional variants (e.g., 'fr-CA')
57 const normalizedLang = lang.replace('-', '');
58 if (availableLocales[normalizedLang]) {
59 return availableLocales[normalizedLang];
60 }
61
62 // Fallback to simple language code (e.g., 'fr')
63 const langCode = lang.split('-')[0];
64 if (availableLocales[langCode]) {
65 return availableLocales[langCode];
66 }
67 }
68
69 // No match found against user language preferences, we'll use first
70 // loaded locale (ultimately determined by script order in HTML)
71 return availableLocales[localeKeys[0]];
72}
73
74export function formatDate(date?: Date, formatStr = 'YYYY-MM-DD'): string {
75 if (!date) {

Callers 6

CalendarMonthFunction · 0.90
formatDateFunction · 0.85
strAsDateFunction · 0.85
formatMonthFunction · 0.85
getMonthOptionsFunction · 0.85
formatYearFunction · 0.85

Calls 1

keysMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…