MCPcopy
hub / github.com/calcom/cal.diy / useLocale

Function useLocale

packages/lib/hooks/useLocale.ts:34–73  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32const serverI18nInstances = new Map();
33
34export const useLocale = (): useLocaleReturnType => {
35 const appRouterContext = useContext(AppRouterI18nContext);
36 const customI18nContext = useContext(CustomI18nContext);
37 const clientI18n = useClientLocale();
38
39 if (appRouterContext) {
40 const { translations, locale, ns } = customI18nContext ?? appRouterContext;
41 const instanceKey = `${locale}-${ns}`;
42
43 // Check if we already have an instance for this locale and namespace
44 if (!serverI18nInstances.has(instanceKey)) {
45 const i18n = createInstance();
46 i18n.init({
47 lng: locale,
48 resources: {
49 [locale]: {
50 [ns]: translations,
51 },
52 },
53 });
54
55 serverI18nInstances.set(instanceKey, {
56 t: i18n.getFixedT(locale, ns),
57 isLocaleReady: true,
58 i18n,
59 });
60 }
61
62 return serverI18nInstances.get(instanceKey);
63 }
64
65 console.warn(
66 "useLocale hook is being used outside of App Router - hence this hook will use a global, client-side i18n which can cause a small flicker"
67 );
68 return {
69 t: clientI18n.t,
70 isLocaleReady: clientI18n.isLocaleReady,
71 i18n: clientI18n.i18n,
72 };
73};

Callers 15

useDescriptionFunction · 0.90
NoAvailabilityDialogFunction · 0.90
DayFunction · 0.90
DatePickerFunction · 0.90
DefaultOutOfOfficeSlotFunction · 0.90
DateValuesFunction · 0.90
HeaderFunction · 0.90
EmbedTabs.tsxFile · 0.90
useEmbedTypesFunction · 0.90
DateOverrideListFunction · 0.90

Calls 6

useClientLocaleFunction · 0.85
hasMethod · 0.80
getMethod · 0.65
warnMethod · 0.65
initMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected