|
1 |
| -import { Dropdown, Button, Divider, message } from 'antd'; |
2 |
| -import { ExportOutlined } from '@ant-design/icons'; |
| 1 | +import { Dropdown, Button, message } from 'antd'; |
| 2 | +import { ExportOutlined, FileOutlined } from '@ant-design/icons'; |
3 | 3 | import type { MenuProps } from 'antd';
|
4 | 4 | import { downloadFile, base64ToBlob } from '@/utils';
|
5 | 5 | import { useContext, useRef } from 'react';
|
6 | 6 | import { GloablStateContext } from '@/context';
|
7 | 7 | import LocalFileSelector from '@/fabritor/components/LocalFileSelector';
|
8 | 8 | import { CenterV } from '@/fabritor/components/Center';
|
9 | 9 | import { SETTER_WIDTH } from '@/config';
|
| 10 | +import { Trans, useTranslation } from '@/i18n/utils'; |
10 | 11 |
|
11 |
| -const items: MenuProps['items'] = [ |
12 |
| - { |
13 |
| - key: 'jpg', |
14 |
| - label: '导出为 JPG' |
15 |
| - }, |
16 |
| - { |
17 |
| - key: 'png', |
18 |
| - label: '导出为 PNG' |
19 |
| - }, |
20 |
| - { |
21 |
| - key: 'svg', |
22 |
| - label: '导出为 SVG' |
23 |
| - }, |
24 |
| - { |
25 |
| - key: 'json', |
26 |
| - label: '导出为 模板' |
27 |
| - }, |
28 |
| - { |
29 |
| - type: 'divider' |
30 |
| - }, |
31 |
| - { |
32 |
| - key: 'clipboard', |
33 |
| - label: '复制到剪贴板' |
34 |
| - } |
35 |
| -] |
| 12 | +const i18nKeySuffix = 'header.export'; |
| 13 | + |
| 14 | +const items: MenuProps['items'] = ['jpg', 'png', 'svg', 'json', 'divider', 'clipboard'].map( |
| 15 | + item => item === 'divider' ? ({ type: 'divider' }) : ({ key: item, label: <Trans i18nKey={`${i18nKeySuffix}.${item}`} /> }) |
| 16 | +) |
36 | 17 |
|
37 | 18 | export default function Export () {
|
38 | 19 | const { editor, setReady, setActiveObject } = useContext(GloablStateContext);
|
39 | 20 | const localFileSelectorRef = useRef<any>();
|
| 21 | + const { t } = useTranslation(); |
40 | 22 |
|
41 | 23 | const selectJsonFile = () => {
|
42 | 24 | localFileSelectorRef.current?.start?.();
|
@@ -67,9 +49,9 @@ export default function Export () {
|
67 | 49 | 'image/png': blob
|
68 | 50 | })
|
69 | 51 | ]);
|
70 |
| - message.success('复制成功'); |
| 52 | + message.success(translate(`${i18nKeySuffix}.copy_success`)); |
71 | 53 | } catch(e) {
|
72 |
| - message.error('复制失败,请选择导出到本地'); |
| 54 | + message.error(translate(`${i18nKeySuffix}.copy_fail`)); |
73 | 55 | }
|
74 | 56 | }
|
75 | 57 |
|
@@ -112,15 +94,15 @@ export default function Export () {
|
112 | 94 | paddingRight: 16
|
113 | 95 | }}
|
114 | 96 | >
|
115 |
| - <Button onClick={selectJsonFile}> |
116 |
| - 加载模板 |
| 97 | + <Button onClick={selectJsonFile} icon={<FileOutlined />}> |
| 98 | + {t(`${i18nKeySuffix}.load`)} |
117 | 99 | </Button>
|
118 | 100 | <Dropdown
|
119 | 101 | menu={{ items, onClick: handleClick }}
|
120 | 102 | arrow={{ pointAtCenter: true }}
|
121 | 103 | placement="bottom"
|
122 | 104 | >
|
123 |
| - <Button type="primary" icon={<ExportOutlined />}>导出</Button> |
| 105 | + <Button type="primary" icon={<ExportOutlined />}>{t(`${i18nKeySuffix}.export`)}</Button> |
124 | 106 | </Dropdown>
|
125 | 107 | <LocalFileSelector accept="application/json" ref={localFileSelectorRef} onChange={handleFileChange} />
|
126 | 108 | </CenterV>
|
|
0 commit comments