Skip to content

Commit f463fcd

Browse files
committed
[FEAT]: Localization feature for English, Spanish and French added
1 parent c6bfa69 commit f463fcd

File tree

18 files changed

+317
-73
lines changed

18 files changed

+317
-73
lines changed

.npmignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ CHANGELOG.md
1616
rollup.config.js
1717
./.travis.yml
1818
tempackage.json
19-
Dropzone-ui.txt
19+
Dropzone-ui.txt
20+
CODE_OF_CONDICT.md
21+
CONTRIBUTING.md

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@dropzone-ui/react",
3-
"version": "2.1.1",
4-
"description": "Elegant React Library Component for drag’n’drop files. Simple to use with little code. Material design guidelines considered.",
3+
"version": "2.8.0",
4+
"description": "Elegant React Library Component for drag’n’drop files. Simple to use with little code. Material design guidelines considered. Multilanguage support.",
55
"main": "./build/index.js",
66
"module": "./build/index.es.js",
77
"types": "./build/index.d.ts",
@@ -30,6 +30,7 @@
3030
"unlimited-react-components",
3131
"front-end",
3232
"framework",
33+
"localization",
3334
"kamui"
3435
],
3536
"author": "JinSSJ3",

src/components/dropzone/components/Dropzone/Dropzone.tsx

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ import { FileItemContainer } from "../../../../components/file-item";
1616
import { FileItemContainerProps } from "../../../file-item/components/FileItemContainer/FileItemContainerProps";
1717
import DropzoneLabel from "../DropzoneLabel/DropzoneLabel";
1818
import { uploadPromiseAxios } from "../utils/dropzone-ui.upload.utils";
19+
import { DropzoneLocalizerSelector } from "../../../../localization";
20+
import {
21+
FunctionLabel,
22+
LocalLabels,
23+
} from "../../../../localization/localization";
1924

2025
const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
2126
const {
@@ -50,6 +55,9 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
5055
fakeUploading,
5156
localization,
5257
} = mergeProps(props, DropzonePropsDefault);
58+
59+
const DropzoneLocalizer: LocalLabels =
60+
DropzoneLocalizerSelector(localization);
5361
//console.log("color:", color);
5462
//ref to the hidden input tag
5563
const inputRef = useRef<HTMLInputElement>(null);
@@ -97,7 +105,8 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
97105
}, [uploadingMessage]);
98106

99107
/**
100-
* Method for uploading FIles
108+
* Method for uploading Files
109+
* It will set all odd file id's as valid
101110
* @param files
102111
*/
103112
const fakeUpload = (file: FileValidated): Promise<FileValidated> => {
@@ -107,19 +116,19 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
107116
resolve({
108117
...file,
109118
uploadStatus: "success",
110-
uploadMessage:
111-
localization === "ES-es"
119+
uploadMessage: DropzoneLocalizer.fakeuploadsuccess as string,
120+
/* localization === "ES-es"
112121
? "EL archivo se subió correctamente"
113-
: "File was succesfully uploaded",
122+
: "File was succesfully uploaded", */
114123
});
115124
} else {
116125
resolve({
117126
...file,
118127
uploadStatus: "error",
119-
uploadMessage:
120-
localization === "ES-es"
128+
uploadMessage: DropzoneLocalizer.fakeUploadError as string,
129+
/* localization === "ES-es"
121130
? "Erro al subir el archivo"
122-
: "Error on Uploading",
131+
: "Error on Uploading", */
123132
});
124133
}
125134
}, 1500);
@@ -136,12 +145,16 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
136145
).length;
137146
let totalRejected: number = 0;
138147
let currentCountUpload: number = 0;
148+
const uploadingMessenger: FunctionLabel =
149+
DropzoneLocalizer.uploadingMessage as FunctionLabel;
150+
139151
setOnUploadStart(true);
140152
if (missingUpload > 0 && url) {
141153
setLocalMessage(
142-
localization === "ES-es"
154+
uploadingMessenger(`${missingUpload}/${totalNumber}`),
155+
/* localization === "ES-es"
143156
? `Subiendo ${missingUpload}/${totalNumber} archivos`
144-
: `uploading ${missingUpload}/${totalNumber} files`,
157+
: `uploading ${missingUpload}/${totalNumber} files`, */
145158
);
146159

147160
let uploadStartFiles: FileValidated[] = files.map((f: FileValidated) => {
@@ -158,9 +171,11 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
158171
let currentFile: FileValidated = uploadStartFiles[i];
159172
if (currentFile.uploadStatus === "uploading") {
160173
setLocalMessage(
161-
localization === "ES-es"
174+
uploadingMessenger(`${++currentCountUpload}/${missingUpload}`),
175+
176+
/* localization === "ES-es"
162177
? `Subiendo ${++currentCountUpload}/${missingUpload} archivos`
163-
: `Uploading ${++currentCountUpload}/${missingUpload} files...`,
178+
: `Uploading ${++currentCountUpload}/${missingUpload} files...`, */
164179
);
165180
// const uploadedFile = await fakeUpload(currentFile);
166181

@@ -181,24 +196,25 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
181196
}
182197
}
183198
// upload group finished :D
199+
const finishUploadMessenger: FunctionLabel =
200+
DropzoneLocalizer.uploadFinished as FunctionLabel;
184201
setLocalMessage(
185-
localization === "ES-es"
186-
? `Archivos subidos: ${
187-
missingUpload - totalRejected
188-
}, Rechazados: ${totalRejected}`
189-
: `Uloaded files: ${
190-
missingUpload - totalRejected
191-
}, Rejected: ${totalRejected}`,
202+
finishUploadMessenger(missingUpload - totalRejected, totalRejected),
203+
/* localization === "ES-es"
204+
? `Archivos subidos: ${missingUpload - totalRejected}, Rechazados: ${totalRejected}`
205+
: `Uloaded files: ${missingUpload - totalRejected}, Rejected: ${totalRejected}`,
206+
*/
192207
);
193208
setTimeout(() => {
194209
setOnUploadStart(false);
195210
}, 2300);
196211
//console.log("queueFiles files:", queueFiles);
197212
} else {
198213
setLocalMessage(
199-
localization === "ES-es"
214+
DropzoneLocalizer.noFilesMessage as string,
215+
/* localization === "ES-es"
200216
? `No hay archivos válidos pendientes por subir`
201-
: `There is not any missing valid file for uploading`,
217+
: `There is not any missing valid file for uploading`, */
202218
);
203219
setTimeout(() => {
204220
setOnUploadStart(false);
@@ -317,7 +333,7 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
317333
//onDrop?.([]);
318334
};
319335
const handleChangeView = (newView: "grid" | "list") => {
320-
// console.log("new View", newView);
336+
// console.log("new View", newView);
321337
setLocalView(newView);
322338
onChangeView?.(newView);
323339
};
@@ -341,7 +357,7 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
341357
onChangeView={handleChangeView}
342358
onUploadStart={!uploadOnDrop ? handleUploadStart : undefined}
343359
urlPresent={url !== undefined}
344-
localization={localization!=="ES-es"?"EN-en":"ES-es"}
360+
localization={localization}
345361
/>
346362
)}
347363
{value && files && files.length > 0 ? (
@@ -354,7 +370,7 @@ const Dropzone: React.FC<DropzoneProps> = (props: DropzoneProps) => {
354370
<DropzoneFooter
355371
accept={accept}
356372
message={onUploadStart ? localMessage : undefined}
357-
localization={localization!=="ES-es"?"EN-en":"ES-es"}
373+
localization={localization}
358374
/>
359375
)}
360376
<div

src/components/dropzone/components/Dropzone/DropzoneProps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export interface DropzoneProps extends OverridableProps {
145145
/**
146146
* language to be used
147147
* for now
148-
* only English and Spanish is supported
148+
* only English, French and Spanish are supported
149149
*/
150150
localization?: Localization;
151151
}

src/components/dropzone/components/DropzoneFooter.tsx/DropzoneFooter.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
import React, { FC } from "react";
2+
import { DropzoneLocalizerSelector } from "../../../../localization";
3+
import {
4+
FunctionLabel,
5+
LocalLabels,
6+
} from "../../../../localization/localization";
27
import { DropzoneFooterProps } from "./DropzoneFooterProps";
38

49
const DropzoneFooter: FC<DropzoneFooterProps> = (
510
props: DropzoneFooterProps,
611
) => {
712
const { accept, message, localization } = props;
13+
14+
const DropzoneFooterLocalizer: LocalLabels = DropzoneLocalizerSelector(
15+
localization,
16+
).footer as LocalLabels;
17+
const accepCustomMessenger: FunctionLabel =
18+
DropzoneFooterLocalizer.acceptCustom as FunctionLabel;
819
return (
920
<div className="dz-ui-footer" onClick={undefined}>
1021
{message
@@ -16,6 +27,11 @@ const DropzoneFooter: FC<DropzoneFooterProps> = (
1627
: localization === "ES-es"
1728
? `Archivos aceptados: ${accept}`
1829
: `File types: ${accept}`}
30+
{message
31+
? message
32+
: !accept
33+
? DropzoneFooterLocalizer.acceptAll
34+
: accepCustomMessenger(accept)}
1935
</div>
2036
);
2137
};

src/components/dropzone/components/DropzoneHeader/DropzoneHeader.tsx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import React, { FC } from "react";
2-
import { Localization } from "../../../../localization/localization";
2+
import { DropzoneLocalizerSelector } from "../../../../localization";
3+
import {
4+
FunctionLabel,
5+
Localization,
6+
LocalLabels,
7+
} from "../../../../localization/localization";
38
import { FileItemContainerProps } from "../../../file-item/components/FileItemContainer/FileItemContainerProps";
49
import { fileSizeFormater } from "../../../file-item/utils";
510
import { Cancel, ViewGrid, ViewList } from "../../../icons";
@@ -38,6 +43,10 @@ const DropzoneHeader: FC<DropzoneHeaderProps> = (
3843
localization,
3944
} = props;
4045

46+
const DropzoneHeaderLocalizer: LocalLabels = DropzoneLocalizerSelector(
47+
localization,
48+
).header as LocalLabels;
49+
4150
const handleStartUploading = () => {
4251
onUploadStart?.();
4352
};
@@ -46,25 +55,34 @@ const DropzoneHeader: FC<DropzoneHeaderProps> = (
4655
if (onUploadStart && urlPresent && numberOfValidFiles) {
4756
result.push(
4857
<>
49-
{localization === "ES-es" ? `Subir archivos` : "Upload files"}
58+
{DropzoneHeaderLocalizer.uploadFilesMessage}
59+
{/* localization === "ES-es" ? `Subir archivos` : "Upload files" */}
5060
<Upload color="#646c7f" onClick={handleStartUploading} />
5161
{" | "}
5262
</>,
5363
);
5464
}
65+
66+
const maxFileSizeMessenger: FunctionLabel =
67+
DropzoneHeaderLocalizer.maxSizeMessage as FunctionLabel;
5568
if (maxFileSize) {
5669
result.push(
57-
localization === "ES-es"
70+
maxFileSizeMessenger(fileSizeFormater(maxFileSize)),
71+
72+
/* localization === "ES-es"
5873
? `Tam. máximo de archivo ${fileSizeFormater(maxFileSize)} | `
59-
: `Max File size: ${fileSizeFormater(maxFileSize)} | `,
74+
: `Max File size: ${fileSizeFormater(maxFileSize)} | `, */
6075
);
6176
}
77+
const validFileSizeMessenger: FunctionLabel =
78+
DropzoneHeaderLocalizer.validFilesMessage as FunctionLabel;
6279

6380
if (maxFiles) {
6481
result.push(
65-
localization === "ES-es"
82+
validFileSizeMessenger(numberOfValidFiles, maxFiles),
83+
/* localization === "ES-es"
6684
? `Archivos ${numberOfValidFiles}/${maxFiles} | Válidos: ${numberOfValidFiles} | `
67-
: `Files ${numberOfValidFiles}/${maxFiles} | Valid: ${numberOfValidFiles} | `,
85+
: `Files ${numberOfValidFiles}/${maxFiles} | Valid: ${numberOfValidFiles} | `, */
6886
);
6987
}
7088

src/components/dropzone/components/DropzoneUI/DropzoneUI.tsx

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

src/components/dropzone/components/DropzoneUI/DropzoneUIProps.ts

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

src/components/dropzone/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { default as DropzoneUI } from "./components/Dropzone/Dropzone";
1+
export { default as Dropzone } from "./components/Dropzone/Dropzone";
22
export * from "./components/Dropzone/Dropzone";

src/components/file-item/components/FileItem/FileItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ const FileItem: FC<FileItemProps> = (props: FileItemProps) => {
124124
sizeFormatted={sizeFormatted}
125125
//fileNamePosition={undefined}
126126
uploadStatus={uploadStatus}
127-
localization={localization!=="ES-es"?"EN-en":"ES-es"}
127+
localization={localization}
128128
/>
129129

130130
<FileItemFullInfoLayer
@@ -136,7 +136,7 @@ const FileItem: FC<FileItemProps> = (props: FileItemProps) => {
136136
onClose={handleCloseInfo}
137137
uploadStatus={uploadStatus}
138138
uploadMessage={uploadMessage}
139-
localization={localization!=="ES-es"?"EN-en":"ES-es"}
139+
localization={localization}
140140
/>
141141
</Paper>
142142

0 commit comments

Comments
 (0)