Skip to content

Commit 5b5be89

Browse files
ZabilsyaZabilsya
andauthored
[DOP-21437] add i18next (#78)
* [DOP-21437] add i18next * fix after review --------- Co-authored-by: Zabilsya <[email protected]>
1 parent bccaf65 commit 5b5be89

File tree

236 files changed

+1843
-842
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

236 files changed

+1843
-842
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
"clsx": "2.1.1",
2727
"dayjs": "1.11.13",
2828
"dotenv-webpack": "8.1.0",
29+
"i18next": "24.2.2",
2930
"rc-picker": "4.9.2",
3031
"react": "18.2.0",
3132
"react-dom": "18.2.0",
3233
"react-error-boundary": "4.0.13",
34+
"react-i18next": "15.4.1",
3335
"react-router-dom": "6.22.3"
3436
},
3537
"devDependencies": {

src/app/config/antd/constants.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/app/config/antd/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { ConfigProvider } from 'antd';
22
import React, { PropsWithChildren } from 'react';
3+
import { useTranslation } from 'react-i18next';
34

4-
import { VALIDATE_MESSAGES } from './constants';
5+
import { getValidateMessages } from './utils';
56

67
export const AntdConfigProvider = ({ children }: PropsWithChildren) => {
7-
return <ConfigProvider form={{ validateMessages: VALIDATE_MESSAGES }}>{children}</ConfigProvider>;
8+
const { t } = useTranslation('error');
9+
10+
return <ConfigProvider form={{ validateMessages: getValidateMessages(t) }}>{children}</ConfigProvider>;
811
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { TFunction } from 'i18next';
2+
3+
export const getValidateMessages = (t: TFunction<'error'>) => {
4+
return {
5+
required: `${t('fieldIsRequired')}!`,
6+
pattern: { mismatch: `${t('fieldPatternInvalid')} \${pattern}` },
7+
};
8+
};

src/app/config/antd/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './getValidateMessages';
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import React from 'react';
22
import { Result } from 'antd';
3+
import { useTranslation } from 'react-i18next';
34

45
import { BackHome } from './BackHome';
56

67
export const AccessError = () => {
7-
return <Result status="403" title="403" subTitle="Sorry, you don't have access to this page." extra={<BackHome />} />;
8+
const { t } = useTranslation('error');
9+
10+
return <Result status="403" title="403" subTitle={t('access')} extra={<BackHome />} />;
811
};

src/app/config/errorBoundary/errors/BackHome.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import React from 'react';
22
import { Button } from 'antd';
33
import { useNavigate } from 'react-router-dom';
4+
import { useTranslation } from 'react-i18next';
45

56
import { isAuthenticated } from '../../router';
67
import { useErrorBoundaryContext } from '../hooks';
78

89
export const BackHome = () => {
10+
const { t } = useTranslation('error');
911
const navigate = useNavigate();
1012
const { resetErrorBoundary } = useErrorBoundaryContext();
1113

@@ -19,7 +21,7 @@ export const BackHome = () => {
1921

2022
return (
2123
<Button type="primary" onClick={handleClick}>
22-
Back Home
24+
{t('backHome')}
2325
</Button>
2426
);
2527
};
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React from 'react';
22
import { Result } from 'antd';
3+
import { useTranslation } from 'react-i18next';
34

45
import { BackHome } from './BackHome';
56

67
export const NotFoundError = () => {
7-
return (
8-
<Result status="404" title="404" subTitle="Sorry, the page you visited does not exist." extra={<BackHome />} />
9-
);
8+
const { t } = useTranslation('error');
9+
10+
return <Result status="404" title="404" subTitle={t('notFound')} extra={<BackHome />} />;
1011
};
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import React from 'react';
22
import { Result } from 'antd';
3+
import { useTranslation } from 'react-i18next';
34

45
import { BackHome } from './BackHome';
56

67
export const ServerError = () => {
7-
return <Result status="500" title="500" subTitle="Sorry, something went wrong." extra={<BackHome />} />;
8+
const { t } = useTranslation('error');
9+
10+
return <Result status="500" title="500" subTitle={t('internalServer')} extra={<BackHome />} />;
811
};

src/entities/connection/api/hooks/useDeleteConnection/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { useMutation, UseMutationResult, useQueryClient } from '@tanstack/react-query';
22
import { notification } from 'antd';
33
import { getErrorMessage } from '@shared/config';
4+
import { useTranslation } from 'react-i18next';
45

56
import { connectionService } from '../../connectionService';
67
import { DeleteConnectionRequest } from '../../types';
78
import { ConnectionQueryKey } from '../../keys';
89

910
/** Hook for deleting connection */
1011
export const useDeleteConnection = (data: DeleteConnectionRequest): UseMutationResult => {
12+
const { t } = useTranslation('error');
1113
const queryClient = useQueryClient();
1214

1315
return useMutation({
@@ -16,12 +18,12 @@ export const useDeleteConnection = (data: DeleteConnectionRequest): UseMutationR
1618
queryClient.invalidateQueries({ queryKey: [ConnectionQueryKey.GET_CONNECTIONS] });
1719
queryClient.removeQueries({ queryKey: [ConnectionQueryKey.GET_CONNECTION, data.id] });
1820
notification.success({
19-
message: 'Connection was deleted successfully',
21+
message: t('deleteConnectionSuccess', { ns: 'connection' }),
2022
});
2123
},
2224
onError: (error) => {
2325
notification.error({
24-
message: getErrorMessage(error),
26+
message: getErrorMessage(error, t),
2527
});
2628
},
2729
});

0 commit comments

Comments
 (0)