|
1 |
| -## Premise |
2 |
| - |
3 |
| -Since FastGPT is managed in the same way as monorepo, it is recommended to install ‘make’ first during development. |
4 |
| - |
5 |
| -monorepo Project Name: |
6 |
| - |
7 |
| -- app: main project |
8 |
| --...... |
9 |
| - |
10 |
| -## Dev |
11 |
| - |
12 |
| -```sh |
13 |
| -# Give automatic script code execution permission (on non-Linux systems, you can manually execute the postinstall.sh file content) |
14 |
| -chmod -R +x ./scripts/ |
15 |
| -# Executing under the code root directory installs all dependencies within the root package, projects, and packages |
16 |
| -pnpm i |
17 |
| - |
18 |
| -# Not make cmd |
19 |
| -cd projects/app |
20 |
| -pnpm dev |
21 |
| - |
22 |
| -# Make cmd |
23 |
| -make dev name=app |
24 |
| -``` |
25 |
| - |
26 |
| -Note: If the Node version is >= 20, you need to pass the `--no-node-snapshot` parameter to Node when running `pnpm i` |
27 |
| - |
28 |
| -```sh |
29 |
| -NODE_OPTIONS=--no-node-snapshot pnpm i |
30 |
| -``` |
31 |
| - |
32 |
| -### Jest |
33 |
| - |
34 |
| -https://fael3z0zfze.feishu.cn/docx/ZOI1dABpxoGhS7xzhkXcKPxZnDL |
35 |
| - |
36 |
| -## I18N |
37 |
| - |
38 |
| -### Install i18n-ally Plugin |
39 |
| - |
40 |
| -1. Open the Extensions Marketplace in VSCode, search for and install the `i18n Ally` plugin. |
41 |
| - |
42 |
| -### Code Optimization Examples |
43 |
| - |
44 |
| -#### Fetch Specific Namespace Translations in `getServerSideProps` |
45 |
| - |
46 |
| -```typescript |
47 |
| -// pages/yourPage.tsx |
48 |
| -export async function getServerSideProps(context: any) { |
49 |
| - return { |
50 |
| - props: { |
51 |
| - currentTab: context?.query?.currentTab || TabEnum.info, |
52 |
| - ...(await serverSideTranslations(context.locale, ['publish', 'user'])) |
53 |
| - } |
54 |
| - }; |
55 |
| -} |
56 |
| -``` |
57 |
| - |
58 |
| -#### Use useTranslation Hook in Page |
59 |
| - |
60 |
| -```typescript |
61 |
| -// pages/yourPage.tsx |
62 |
| -import { useTranslation } from 'next-i18next'; |
63 |
| - |
64 |
| -const YourComponent = () => { |
65 |
| - const { t } = useTranslation(); |
66 |
| - |
67 |
| - return ( |
68 |
| - <Button |
69 |
| - variant="outline" |
70 |
| - size="sm" |
71 |
| - mr={2} |
72 |
| - onClick={() => setShowSelected(false)} |
73 |
| - > |
74 |
| - {t('common:close')} |
75 |
| - </Button> |
76 |
| - ); |
77 |
| -}; |
78 |
| - |
79 |
| -export default YourComponent; |
80 |
| -``` |
81 |
| -
|
82 |
| -#### Handle Static File Translations |
83 |
| -
|
84 |
| -```typescript |
85 |
| -// utils/i18n.ts |
86 |
| -import { i18nT } from '@fastgpt/web/i18n/utils'; |
87 |
| - |
88 |
| -const staticContent = { |
89 |
| - id: 'simpleChat', |
90 |
| - avatar: 'core/workflow/template/aiChat', |
91 |
| - name: i18nT('app:template.simple_robot'), |
92 |
| -}; |
93 |
| - |
94 |
| -export default staticContent; |
95 |
| -``` |
96 |
| -
|
97 |
| -### Standardize Translation Format |
98 |
| -
|
99 |
| -- Use the t(namespace:key) format to ensure consistent naming. |
100 |
| -- Translation keys should use lowercase letters and underscores, e.g., common.close. |
101 |
| -
|
102 |
| -## Build |
103 |
| -
|
104 |
| -```sh |
105 |
| -# Docker cmd: Build image, not proxy |
106 |
| -docker build -f ./projects/app/Dockerfile -t registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.8.1 . --build-arg name=app |
107 |
| -# Make cmd: Build image, not proxy |
108 |
| -make build name=app image=registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.8.1 |
109 |
| - |
110 |
| -# Docker cmd: Build image with proxy |
111 |
| -docker build -f ./projects/app/Dockerfile -t registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.8.1 . --build-arg name=app --build-arg proxy=taobao |
112 |
| -# Make cmd: Build image with proxy |
113 |
| -make build name=app image=registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.8.1 proxy=taobao |
114 |
| -``` |
| 1 | +## Premise |
| 2 | + |
| 3 | +Since FastGPT is managed in the same way as monorepo, it is recommended to install ‘make’ first during development. |
| 4 | + |
| 5 | +monorepo Project Name: |
| 6 | + |
| 7 | +- app: main project |
| 8 | +-...... |
| 9 | + |
| 10 | +## Dev |
| 11 | + |
| 12 | +```sh |
| 13 | +# Give automatic script code execution permission (on non-Linux systems, you can manually execute the postinstall.sh file content) |
| 14 | +chmod -R +x ./scripts/ |
| 15 | +# Executing under the code root directory installs all dependencies within the root package, projects, and packages |
| 16 | +pnpm i |
| 17 | + |
| 18 | +# Not make cmd |
| 19 | +cd projects/app |
| 20 | +pnpm dev |
| 21 | + |
| 22 | +# Make cmd |
| 23 | +make dev name=app |
| 24 | +``` |
| 25 | + |
| 26 | +Note: If the Node version is >= 20, you need to pass the `--no-node-snapshot` parameter to Node when running `pnpm i` |
| 27 | + |
| 28 | +```sh |
| 29 | +NODE_OPTIONS=--no-node-snapshot pnpm i |
| 30 | +``` |
| 31 | + |
| 32 | +### Jest |
| 33 | + |
| 34 | +https://fael3z0zfze.feishu.cn/docx/ZOI1dABpxoGhS7xzhkXcKPxZnDL |
| 35 | + |
| 36 | +## I18N |
| 37 | + |
| 38 | +### Install i18n-ally Plugin |
| 39 | + |
| 40 | +1. Open the Extensions Marketplace in VSCode, search for and install the `i18n Ally` plugin. |
| 41 | + |
| 42 | +### Code Optimization Examples |
| 43 | + |
| 44 | +#### Fetch Specific Namespace Translations in `getServerSideProps` |
| 45 | + |
| 46 | +```typescript |
| 47 | +// pages/yourPage.tsx |
| 48 | +export async function getServerSideProps(context: any) { |
| 49 | + return { |
| 50 | + props: { |
| 51 | + currentTab: context?.query?.currentTab || TabEnum.info, |
| 52 | + ...(await serverSideTranslations(context.locale, ['publish', 'user'])) |
| 53 | + } |
| 54 | + }; |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +#### Use useTranslation Hook in Page |
| 59 | + |
| 60 | +```typescript |
| 61 | +// pages/yourPage.tsx |
| 62 | +import { useTranslation } from 'next-i18next'; |
| 63 | + |
| 64 | +const YourComponent = () => { |
| 65 | + const { t } = useTranslation(); |
| 66 | + |
| 67 | + return ( |
| 68 | + <Button |
| 69 | + variant="outline" |
| 70 | + size="sm" |
| 71 | + mr={2} |
| 72 | + onClick={() => setShowSelected(false)} |
| 73 | + > |
| 74 | + {t('common:close')} |
| 75 | + </Button> |
| 76 | + ); |
| 77 | +}; |
| 78 | + |
| 79 | +export default YourComponent; |
| 80 | +``` |
| 81 | +
|
| 82 | +#### Handle Static File Translations |
| 83 | +
|
| 84 | +```typescript |
| 85 | +// utils/i18n.ts |
| 86 | +import { i18nT } from '@fastgpt/web/i18n/utils'; |
| 87 | + |
| 88 | +const staticContent = { |
| 89 | + id: 'simpleChat', |
| 90 | + avatar: 'core/workflow/template/aiChat', |
| 91 | + name: i18nT('app:template.simple_robot'), |
| 92 | +}; |
| 93 | + |
| 94 | +export default staticContent; |
| 95 | +``` |
| 96 | +
|
| 97 | +### Standardize Translation Format |
| 98 | +
|
| 99 | +- Use the t(namespace:key) format to ensure consistent naming. |
| 100 | +- Translation keys should use lowercase letters and underscores, e.g., common.close. |
| 101 | +
|
| 102 | +## audit |
| 103 | +
|
| 104 | +Please fill the OperationLogEventEnum and operationLog/audit function is added to the ts, and on the corresponding position to fill i18n, at the same time to add the location of the log using addOpearationLog function add function |
| 105 | +
|
| 106 | +## Build |
| 107 | +
|
| 108 | +```sh |
| 109 | +# Docker cmd: Build image, not proxy |
| 110 | +docker build -f ./projects/app/Dockerfile -t registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.8.1 . --build-arg name=app |
| 111 | +# Make cmd: Build image, not proxy |
| 112 | +make build name=app image=registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.8.1 |
| 113 | + |
| 114 | +# Docker cmd: Build image with proxy |
| 115 | +docker build -f ./projects/app/Dockerfile -t registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.8.1 . --build-arg name=app --build-arg proxy=taobao |
| 116 | +# Make cmd: Build image with proxy |
| 117 | +make build name=app image=registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:v4.8.1 proxy=taobao |
| 118 | +``` |
0 commit comments