[release-12.0.1] i18n: Move locale code behind the feature toggle in internationalization/dates.ts (#104090)

pull/104134/head
Laura Fernández 2 months ago committed by GitHub
parent 44cfb7c6b4
commit 173db4aac7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 15
      public/app/core/internationalization/dates.ts
  2. 4
      public/test/jest-setup.ts

@ -4,8 +4,12 @@ import memoize from 'micro-memoize';
import { config } from 'app/core/config';
import { getI18next } from './index';
const deepMemoize: typeof memoize = (fn) => memoize(fn, { isEqual: deepEqual });
const isLocaleEnabled = config.featureToggles.localeFormatPreference;
const createDateTimeFormatter = deepMemoize((locale: string, options: Intl.DateTimeFormatOptions) => {
return new Intl.DateTimeFormat(locale, options);
});
@ -20,17 +24,20 @@ export const formatDate = deepMemoize(
return formatDate(new Date(value), format);
}
const locale = config.locale;
const dateFormatter = createDateTimeFormatter(locale, format);
const i18n = getI18next();
const currentLocale = isLocaleEnabled ? config.locale : i18n.language;
const dateFormatter = createDateTimeFormatter(currentLocale, format);
return dateFormatter.format(value);
}
);
export const formatDuration = deepMemoize(
(duration: Intl.DurationInput, options: Intl.DurationFormatOptions = {}): string => {
const locale = config.locale;
const i18n = getI18next();
const currentLocale = isLocaleEnabled ? config.locale : i18n.language;
const dateFormatter = createDurationFormatter(locale, options);
const dateFormatter = createDurationFormatter(currentLocale, options);
return dateFormatter.format(duration);
}
);

@ -23,7 +23,9 @@ const settings: Partial<GrafanaBootConfig> = {
};
global.grafanaBootData = {
settings,
user: {},
user: {
locale: 'en-US',
},
navTree: [],
};

Loading…
Cancel
Save