Skip to content

Commit 746c7f1

Browse files
committed
feat: added support for builder locale
v1.1.17
1 parent 6d38e4f commit 746c7f1

File tree

5 files changed

+34
-30
lines changed

5 files changed

+34
-30
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"author": "Suraj Air",
66
"license": "BSD-3-Clause",
77
"homepage": "https://chaibuilder.com",
8-
"version": "1.1.16",
8+
"version": "1.1.17",
99
"type": "module",
1010
"repository": {
1111
"type": "git",

src/Editor.tsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,27 @@ import { useAtom } from "jotai";
33
import { useTranslation } from "react-i18next";
44
import { lsBlocksAtom, lsBrandingOptionsAtom, lsProvidersAtom } from "./atoms-dev.ts";
55

6-
function ChaiEditor() {
6+
let PreviewMessage = () => {
77
const { t } = useTranslation();
8+
return (
9+
<div className={"font-normal text-sm"}>
10+
{t("dev_mode_message")}{" "}
11+
<a target={"_blank"} className="text-orange-500 underline" href={"/preview"}>
12+
/preview
13+
</a>{" "}
14+
{t("to_see_page_preview")}
15+
</div>
16+
);
17+
};
18+
19+
function ChaiEditor() {
820
const [blocks, setBlocks] = useAtom(lsBlocksAtom);
921
const [brandingOptions, setBrandingOptions] = useAtom(lsBrandingOptionsAtom);
1022
const [providers, setProviders] = useAtom(lsProvidersAtom);
23+
1124
return (
1225
<ChaiBuilderEditor
13-
topBarComponents={{
14-
left: [
15-
() => (
16-
<div className={"font-normal text-sm"}>
17-
{t("dev_mode_message")}{" "}
18-
<a target={"_blank"} className="text-orange-500 underline" href={"/preview"}>
19-
/preview
20-
</a>{" "}
21-
{t("to_see_page_preview")}
22-
</div>
23-
),
24-
],
25-
}}
26+
topBarComponents={{ left: [PreviewMessage] }}
2627
blocks={blocks}
2728
dataProviders={providers}
2829
brandingOptions={brandingOptions}

src/core/locales/load.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ i18n
2929
},
3030
});
3131

32-
export default "";
32+
export default i18n;

src/core/main/ChaiBuilderEditor.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ const ChaiBuilderComponent = (props: ChaiBuilderEditorProps) => {
4949
reset();
5050
}, [props.blocks]);
5151

52+
useEffect(() => {
53+
i18n.changeLanguage(props.locale || "en");
54+
}, [props.locale]);
55+
5256
useEffect(() => {
5357
setBrandingOptions(props.brandingOptions);
5458
}, [props.brandingOptions, setBrandingOptions]);

src/core/types/chaiBuilderEditorProps.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { ChaiBlock } from "./ChaiBlock";
2-
import React, { LazyExoticComponent } from "react";
2+
import React from "react";
33
import { ChaiPage, PredefinedBlock } from "./index";
44

5-
interface UiLibrary {
5+
interface UILibrary {
66
name: string;
77
uuid: string;
88
}
@@ -12,18 +12,17 @@ interface Block {
1212
[key: string]: any;
1313
}
1414

15-
type ReactComponents = React.LazyExoticComponent<any> | React.FC<any>;
15+
type ReactComponentType = React.ComponentType<any>;
1616

1717
export interface ChaiBuilderEditorProps {
1818
blocks?: ChaiBlock[];
1919
editable?: boolean;
20-
nonEditableComponent?: ReactComponents;
20+
locale?: string;
21+
nonEditableComponent?: ReactComponentType;
2122
brandingOptions?: Record<string, string>;
2223
canvas?: React.FC<any>;
2324
previewLink?: string;
24-
canvasTopBarComponents?: {
25-
right?: React.LazyExoticComponent<any>[];
26-
};
25+
canvasTopBarComponents?: { right?: ReactComponentType[] };
2726
dataBindingSupport?: boolean;
2827
dataProviders?: { providerKey: string; args: Record<string, any> }[];
2928
darkMode?: boolean;
@@ -41,17 +40,17 @@ export interface ChaiBuilderEditorProps {
4140
onSavePage: ({ blocks, providers }: any) => Promise<boolean>;
4241
onSaveBrandingOptions: (brandingOptions: any) => Promise<boolean>;
4342
onSyncStatusChange?: (syncStatus: "UNSAVED" | "SAVED") => void;
44-
previewComponent?: LazyExoticComponent<any>;
43+
previewComponent?: ReactComponentType;
4544
sideBarComponents?: {
46-
bottom?: ReactComponents[];
47-
top?: { icon: React.FC<any> | string; name: string; panel: ReactComponents }[];
45+
bottom?: ReactComponentType[];
46+
top?: { icon: ReactComponentType | string; name: string; panel: ReactComponentType }[];
4847
};
4948
topBarComponents?: {
50-
center?: ReactComponents[];
51-
left?: ReactComponents[];
52-
right?: ReactComponents[];
49+
center?: ReactComponentType[];
50+
left?: ReactComponentType[];
51+
right?: ReactComponentType[];
5352
};
54-
uiLibraries?: UiLibrary[];
53+
uiLibraries?: UILibrary[];
5554
uploadMediaCallback?: (file: File) => Promise<{ url: string }>;
5655
getPages?: () => Promise<ChaiPage[]>;
5756
unsplashAccessKey?: string;

0 commit comments

Comments
 (0)