Skip to content

Commit

Permalink
Merge branch 'main' into fix/missing-id
Browse files Browse the repository at this point in the history
  • Loading branch information
Udit-takkar authored Apr 25, 2024
2 parents 9cf1a26 + 8fbb1ed commit a85be4c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 32 deletions.
77 changes: 47 additions & 30 deletions packages/platform/atoms/cal-provider/BaseCalProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,35 @@ export function BaseCalProvider({
clientId,
});

const translations = {
t: (key: string, values: Record<string, string | number | null | undefined>) => {
let translation = String(enTranslations[key as translationKeys] ?? "");
if (!translation) {
return "";
}
if (values) {
const valueKeys = Object.keys(values) as (keyof typeof values)[];
if (valueKeys.length) {
valueKeys.forEach((valueKey) => {
if (translation)
translation = translation.replace(
`{{${String(valueKey)}}}`,
values[valueKey]?.toString() ?? `{{${String(valueKey)}}}`
);
});
}
}

return replaceOccurrences(translation, enTranslations) ?? "";
},
i18n: {
language: "en",
defaultLocale: "en",
locales: ["en"],
exists: (key: translationKeys | string) => Boolean(enTranslations[key as translationKeys]),
},
};

return isInit ? (
<AtomsContext.Provider
value={{
Expand All @@ -74,41 +103,29 @@ export function BaseCalProvider({
isInit: isInit,
isValidClient: Boolean(!error && clientId && isInit),
isAuth: Boolean(isInit && !error && clientId && currentAccessToken && http.getAuthorizationHeader()),
t: (key, values) => {
let translation = String(enTranslations[key as translationKeys] ?? "");
if (!translation) {
return "";
}
if (values) {
const valueKeys = Object.keys(values) as (keyof typeof values)[];
if (valueKeys.length) {
valueKeys.forEach((valueKey) => {
if (translation)
translation = translation.replace(
`{{${String(valueKey)}}}`,
values[valueKey]?.toString() ?? `{{${String(valueKey)}}}`
);
});
}
}

return replaceOccurrences(translation, enTranslations) ?? "";
},
i18n: {
language: "en",
defaultLocale: "en",
locales: ["en"],
exists: (key: translationKeys | string) => Boolean(enTranslations[key as translationKeys]),
},
...translations,
}}>
<TooltipProvider>{children}</TooltipProvider>
<Toaster />
</AtomsContext.Provider>
) : (
<>
{children}
<Toaster />
</>
<AtomsContext.Provider
value={{
clientId,
options,
error,
getClient: () => http,
isAuth: false,
isValidClient: Boolean(!error && clientId),
isInit: false,
isRefreshing: false,
...translations,
}}>
<>
<TooltipProvider>{children}</TooltipProvider>
<Toaster />
</>
</AtomsContext.Provider>
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/platform/atoms/hooks/useAtomsContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface IAtomsContext {
i18n: {
language: string;
defaultLocale: string;
locales: [string];
locales: string[];
exists: (key: translationKeys | string) => boolean;
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/platform/atoms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "module",
"description": "Customizable UI components to integrate scheduling into your product.",
"authors": "Cal.com, Inc.",
"version": "1.0.30",
"version": "1.0.35",
"scripts": {
"dev": "yarn vite build --watch & npx tailwindcss -i ./globals.css -o ./globals.min.css --postcss --minify --watch",
"build": "yarn vite build && npx tailwindcss -i ./globals.css -o ./globals.min.css --postcss --minify",
Expand Down

0 comments on commit a85be4c

Please sign in to comment.