mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-06 07:56:28 +08:00
Add locale support to Upload (#5094)
This commit is contained in:
parent
c552b315bc
commit
6eca8b4ad1
@ -36,4 +36,10 @@ export default {
|
|||||||
Select: {
|
Select: {
|
||||||
notFoundContent: 'Not Found',
|
notFoundContent: 'Not Found',
|
||||||
},
|
},
|
||||||
|
Upload: {
|
||||||
|
uploading: 'Uploading...',
|
||||||
|
removeFile: 'Remove file',
|
||||||
|
uploadError: 'Upload error',
|
||||||
|
previewFile: 'Preview file',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
@ -41,7 +41,7 @@ exports[`test renders ./components/upload/demo/defaultFileList.md correctly 1`]
|
|||||||
</a>
|
</a>
|
||||||
<i
|
<i
|
||||||
class="anticon anticon-cross"
|
class="anticon anticon-cross"
|
||||||
title="Remove file" />
|
title="删除文件" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
@ -59,7 +59,7 @@ exports[`test renders ./components/upload/demo/defaultFileList.md correctly 1`]
|
|||||||
</a>
|
</a>
|
||||||
<i
|
<i
|
||||||
class="anticon anticon-cross"
|
class="anticon anticon-cross"
|
||||||
title="Remove file" />
|
title="删除文件" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
@ -77,7 +77,7 @@ exports[`test renders ./components/upload/demo/defaultFileList.md correctly 1`]
|
|||||||
</a>
|
</a>
|
||||||
<i
|
<i
|
||||||
class="anticon anticon-cross"
|
class="anticon anticon-cross"
|
||||||
title="Remove file" />
|
title="删除文件" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -118,7 +118,7 @@ exports[`test renders ./components/upload/demo/fileList.md correctly 1`] = `
|
|||||||
</a>
|
</a>
|
||||||
<i
|
<i
|
||||||
class="anticon anticon-cross"
|
class="anticon anticon-cross"
|
||||||
title="Remove file" />
|
title="删除文件" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -158,13 +158,13 @@ exports[`test renders ./components/upload/demo/picture-card.md correctly 1`] = `
|
|||||||
href="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png"
|
href="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
title="Preview file">
|
title="预览文件">
|
||||||
<i
|
<i
|
||||||
class="anticon anticon-eye-o" />
|
class="anticon anticon-eye-o" />
|
||||||
</a>
|
</a>
|
||||||
<i
|
<i
|
||||||
class="anticon anticon-delete"
|
class="anticon anticon-delete"
|
||||||
title="Remove file" />
|
title="删除文件" />
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -207,7 +207,7 @@ exports[`test renders ./components/upload/demo/picture-style.md correctly 1`] =
|
|||||||
</a>
|
</a>
|
||||||
<i
|
<i
|
||||||
class="anticon anticon-cross"
|
class="anticon anticon-cross"
|
||||||
title="Remove file" />
|
title="删除文件" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
@ -232,7 +232,7 @@ exports[`test renders ./components/upload/demo/picture-style.md correctly 1`] =
|
|||||||
</a>
|
</a>
|
||||||
<i
|
<i
|
||||||
class="anticon anticon-cross"
|
class="anticon anticon-cross"
|
||||||
title="Remove file" />
|
title="删除文件" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -268,7 +268,7 @@ exports[`test renders ./components/upload/demo/picture-style.md correctly 1`] =
|
|||||||
</a>
|
</a>
|
||||||
<i
|
<i
|
||||||
class="anticon anticon-cross"
|
class="anticon anticon-cross"
|
||||||
title="Remove file" />
|
title="删除文件" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
@ -293,7 +293,7 @@ exports[`test renders ./components/upload/demo/picture-style.md correctly 1`] =
|
|||||||
</a>
|
</a>
|
||||||
<i
|
<i
|
||||||
class="anticon anticon-cross"
|
class="anticon anticon-cross"
|
||||||
title="Remove file" />
|
title="删除文件" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -4,7 +4,7 @@ import UploadList from './uploadList';
|
|||||||
import getFileItem from './getFileItem';
|
import getFileItem from './getFileItem';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import assign from 'object-assign';
|
import assign from 'object-assign';
|
||||||
import { UploadProps } from './interface';
|
import { UploadProps, UploadLocale } from './interface';
|
||||||
|
|
||||||
function T() {
|
function T() {
|
||||||
return true;
|
return true;
|
||||||
@ -51,6 +51,13 @@ function genPercentAdd() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defaultLocale: UploadLocale = {
|
||||||
|
uploading: '文件上传中',
|
||||||
|
removeFile: '删除文件',
|
||||||
|
uploadError: '上传错误',
|
||||||
|
previewFile: '预览文件',
|
||||||
|
};
|
||||||
|
|
||||||
export { UploadProps };
|
export { UploadProps };
|
||||||
|
|
||||||
export function Dragger(props) {
|
export function Dragger(props) {
|
||||||
@ -90,6 +97,14 @@ export default class Upload extends React.Component<UploadProps, any> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLocale() {
|
||||||
|
let locale = {};
|
||||||
|
if (this.context.antLocale && this.context.antLocale.Upload) {
|
||||||
|
locale = this.context.antLocale.Upload;
|
||||||
|
}
|
||||||
|
return assign({}, defaultLocale, locale, this.props.locale);
|
||||||
|
}
|
||||||
|
|
||||||
onStart = (file) => {
|
onStart = (file) => {
|
||||||
let targetItem;
|
let targetItem;
|
||||||
let nextFileList = this.state.fileList.concat();
|
let nextFileList = this.state.fileList.concat();
|
||||||
@ -264,6 +279,7 @@ export default class Upload extends React.Component<UploadProps, any> {
|
|||||||
onRemove={this.handleManualRemove}
|
onRemove={this.handleManualRemove}
|
||||||
showRemoveIcon={showRemoveIcon}
|
showRemoveIcon={showRemoveIcon}
|
||||||
showPreviewIcon={showPreviewIcon}
|
showPreviewIcon={showPreviewIcon}
|
||||||
|
locale={this.getLocale()}
|
||||||
/>
|
/>
|
||||||
) : null;
|
) : null;
|
||||||
|
|
||||||
|
@ -31,6 +31,13 @@ export interface ShowUploadListInterface {
|
|||||||
showPreviewIcon?: boolean;
|
showPreviewIcon?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface UploadLocale {
|
||||||
|
uploading?: string;
|
||||||
|
removeFile?: string;
|
||||||
|
uploadError?: string;
|
||||||
|
previewFile?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface UploadProps {
|
export interface UploadProps {
|
||||||
type?: 'drag' | 'select';
|
type?: 'drag' | 'select';
|
||||||
name?: string;
|
name?: string;
|
||||||
@ -54,6 +61,7 @@ export interface UploadProps {
|
|||||||
prefixCls?: string;
|
prefixCls?: string;
|
||||||
customRequest?: (option: any) => void;
|
customRequest?: (option: any) => void;
|
||||||
withCredentials?: boolean;
|
withCredentials?: boolean;
|
||||||
|
locale?: UploadLocale;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UploadListProps {
|
export interface UploadListProps {
|
||||||
@ -65,4 +73,5 @@ export interface UploadListProps {
|
|||||||
prefixCls?: string;
|
prefixCls?: string;
|
||||||
showRemoveIcon?: boolean;
|
showRemoveIcon?: boolean;
|
||||||
showPreviewIcon?: boolean;
|
showPreviewIcon?: boolean;
|
||||||
|
locale: UploadLocale;
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ export default class UploadList extends React.Component<UploadListProps, any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { prefixCls, items = [], listType, showPreviewIcon, showRemoveIcon } = this.props;
|
const { prefixCls, items = [], listType, showPreviewIcon, showRemoveIcon, locale } = this.props;
|
||||||
const list = items.map(file => {
|
const list = items.map(file => {
|
||||||
let progress;
|
let progress;
|
||||||
let icon = <Icon type="paper-clip" />;
|
let icon = <Icon type="paper-clip" />;
|
||||||
@ -74,7 +74,7 @@ export default class UploadList extends React.Component<UploadListProps, any> {
|
|||||||
if (listType === 'picture' || listType === 'picture-card') {
|
if (listType === 'picture' || listType === 'picture-card') {
|
||||||
if (file.status === 'uploading' || (!file.thumbUrl && !file.url)) {
|
if (file.status === 'uploading' || (!file.thumbUrl && !file.url)) {
|
||||||
if (listType === 'picture-card') {
|
if (listType === 'picture-card') {
|
||||||
icon = <div className={`${prefixCls}-list-item-uploading-text`}>Uploading...</div>;
|
icon = <div className={`${prefixCls}-list-item-uploading-text`}>{locale.uploading}</div>;
|
||||||
} else {
|
} else {
|
||||||
icon = <Icon className={`${prefixCls}-list-item-thumbnail`} type="picture" />;
|
icon = <Icon className={`${prefixCls}-list-item-thumbnail`} type="picture" />;
|
||||||
}
|
}
|
||||||
@ -133,16 +133,16 @@ export default class UploadList extends React.Component<UploadListProps, any> {
|
|||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
style={style}
|
style={style}
|
||||||
onClick={e => this.handlePreview(file, e)}
|
onClick={e => this.handlePreview(file, e)}
|
||||||
title="Preview file"
|
title={locale.previewFile}
|
||||||
>
|
>
|
||||||
<Icon type="eye-o" />
|
<Icon type="eye-o" />
|
||||||
</a>
|
</a>
|
||||||
) : null;
|
) : null;
|
||||||
const removeIcon = showRemoveIcon ? (
|
const removeIcon = showRemoveIcon ? (
|
||||||
<Icon type="delete" title="Remove file" onClick={() => this.handleClose(file)} />
|
<Icon type="delete" title={locale.removeFile} onClick={() => this.handleClose(file)} />
|
||||||
) : null;
|
) : null;
|
||||||
const removeIconCross = showRemoveIcon ? (
|
const removeIconCross = showRemoveIcon ? (
|
||||||
<Icon type="cross" title="Remove file" onClick={() => this.handleClose(file)} />
|
<Icon type="cross" title={locale.removeFile} onClick={() => this.handleClose(file)} />
|
||||||
) : null;
|
) : null;
|
||||||
const actions = (listType === 'picture-card' && file.status !== 'uploading')
|
const actions = (listType === 'picture-card' && file.status !== 'uploading')
|
||||||
? <span className={`${prefixCls}-list-item-actions`}>{previewIcon}{removeIcon}</span>
|
? <span className={`${prefixCls}-list-item-actions`}>{previewIcon}{removeIcon}</span>
|
||||||
@ -160,7 +160,7 @@ export default class UploadList extends React.Component<UploadListProps, any> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (file.status === 'error') {
|
if (file.status === 'error') {
|
||||||
const message = file.response || (file.error && file.error.statusText) || 'Upload Error';
|
const message = file.response || (file.error && file.error.statusText) || locale.uploadError;
|
||||||
return (
|
return (
|
||||||
<Tooltip title={message} key={file.uid}>
|
<Tooltip title={message} key={file.uid}>
|
||||||
{item}
|
{item}
|
||||||
|
Loading…
Reference in New Issue
Block a user