Skip to content

Commit

Permalink
Add completed translations
Browse files Browse the repository at this point in the history
  • Loading branch information
corovcam committed Nov 16, 2023
1 parent 9f0c8cd commit 2a00dfb
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 123 deletions.
43 changes: 28 additions & 15 deletions src/components/file-management-dialog/UppyDashboardDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import "@uppy/image-editor/dist/style.min.css";

import { useEffect, useRef, useCallback } from "preact/hooks";
import { useUppyContext, useAppContext, useWorker } from "../../hooks";
import czechLocale from "../../utils/czechLocale";
import czechLocale from "../../utils/locales/czechLocale";
import englishLocale from "../../utils/locales/englishLocale";

import { debugLogger } from "@uppy/core";
import { DashboardModal } from "@uppy/react";
Expand Down Expand Up @@ -56,7 +57,7 @@ const UppyDashboardDialog = ({
async (file) => {
if (window.Worker) {
if (isProcessing.current) {
this.uppy.info("Still processing previous file.", "info", 3000);
uppy.info(uppy.i18n("Still processing previous file."), "info", 3000);
return;
}
// TODO: Alert error only in Debug
Expand All @@ -73,19 +74,25 @@ const UppyDashboardDialog = ({
} catch (error) {
isProcessing.current = false;
uppy.info(
"There was an error when uploading file:\n" + error,
`${uppy.i18n("There was an error when uploading file")}:\n ${error}`,
"error",
5000
);
}
} else {
uppy.info("Web Worker is not supported", "info", 5000);
uppy.info(uppy.i18n("Web Worker is not supported"), "info", 5000);
}
},
[uppy, extractImageWorker, isProcessing]
);

useEffect(() => {
const customLocale = locale?.startsWith("cs") ?
{
strings: Object.assign(cs_CZ.strings, czechLocale.strings)
} : {
strings: Object.assign(en_US.strings, englishLocale.strings)
}
uppy.setOptions({
debug: debug,
logger: debug
Expand All @@ -97,7 +104,7 @@ const UppyDashboardDialog = ({
console.error(...args);
},
},
locale: locale?.startsWith("cs") ? cs_CZ : en_US,
locale: customLocale,
restrictions: {
allowedFileTypes: allowedFileTypes,
},
Expand All @@ -123,9 +130,10 @@ const UppyDashboardDialog = ({
!modifyExistingFiles && autoExtractImagesFromPDFs
? // eslint-disable-next-line no-unused-vars
(currentFile, _files) => {
console.log(currentFile, _files);
if (currentFile.type === "application/pdf") {
uppy.info(
"PDF image extraction processing, please wait...",
uppy.i18n("PDF image extraction processing, please wait..."),
"info",
3000
);
Expand Down Expand Up @@ -200,7 +208,7 @@ const UppyDashboardDialog = ({
})
.catch((error) => {
uppy.info({
message: "Error loading files.",
message: uppy.i18n("Error loading files."),
details: error.message,
}, "error", 7000);
})
Expand Down Expand Up @@ -253,13 +261,13 @@ const UppyDashboardDialog = ({
extractImageWorker.onmessage = (event) => {
if (event.data?.type === "done") {
isProcessing.current = false;
uppy.info("Image extraction completed.", "success", 3000);
uppy.info(`[${event.data.sourcePdf}] ${uppy.i18n("Image extraction completed")}. ${uppy.i18n("Image count")}: ${event.data.imageCount}`, "success", 5000);
return;
} else if (event.data?.type === "error") {
isProcessing.current = false;
uppy.info(
{
message: `Error extracting images from ${event.data.sourcePdf}`,
message: `${uppy.i18n("Error extracting images from")}: ${event.data.sourcePdf}`,
details: `${event.data.message}`,
},
"error",
Expand Down Expand Up @@ -287,10 +295,15 @@ const UppyDashboardDialog = ({
alert("Error: " + event.message);
};
} else {
uppy.info("Web Worker is not supported.", "error", 5000);
uppy.info(uppy.i18n("Web Worker is not supported"), "error", 5000);
}
}, [extractImageWorker, uppy, debug]);

const manualI18n = (key) => {
const localeStrings = locale?.startsWith("cs") ? czechLocale.strings : englishLocale.strings;
return localeStrings[key];
}

return (
<>
<DashboardModal
Expand All @@ -306,21 +319,21 @@ const UppyDashboardDialog = ({
showProgressDetails
note={
modifyExistingFiles
? "Select existing files to modify metadata."
: "Select files to upload."
? manualI18n("Select existing files to modify metadata.")
: manualI18n("Select files to upload.")
}
disableLocalFiles={modifyExistingFiles}
metaFields={(file) => {
const fields = [];
if (file.type.startsWith("image/")) {
fields.push({
id: "caption",
name: "Caption",
placeholder: "Set the Caption here",
name: manualI18n("Caption"),
placeholder: manualI18n("Set the Caption here"),
});
fields.push({
id: "featureImage",
name: "Feature Image",
name: manualI18n("Feature Image"),
render: ({ value, onChange, required, form }, h) => {
return h("input", {
type: "checkbox",
Expand Down
8 changes: 0 additions & 8 deletions src/utils/czechLocale.js

This file was deleted.

20 changes: 20 additions & 0 deletions src/utils/locales/czechLocale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export default {
strings: {
noSearchResults: "Pro vaše hledání nejsou k dispozici žádné výsledky.",
selectPdfs: "Vyberte soubory PDF, ze kterých chcete extrahovat obrázky.",
uploadStalled: "Nahrávání neproběhlo po dobu %{seconds} sekund. Možná jej budete chtít zopakovat.",
"Still processing previous file.": "Stále zpracováváme předchozí soubor.",
"PDF image extraction processing, please wait...": "Zpracování extrakce obrázků z PDF, počkejte prosím...",
"There was an error when uploading file": "Při nahrávání souboru došlo k chybě",
"Web Worker is not supported": "Web Worker není podporován",
"Error loading files.": "Chyba při načítání souborů.",
"Image extraction completed": "Extrakce obrázků dokončena",
"Image count": "Počet obrázků",
"Error extracting images from": "Chyba při extrakci obrázků z",
"Select existing files to modify metadata.": "Vyberte existující soubory pro úpravu metadat.",
"Select files to upload.": "Vyberte soubory, které chcete nahrát.",
"Set the Caption here": "Zde nastavte Titulek",
"Caption": "Titulek",
"Feature Image": "Hlavní obrázek"
},
};
17 changes: 17 additions & 0 deletions src/utils/locales/englishLocale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default {
strings: {
"Still processing previous file.": "Still processing previous file.",
"PDF image extraction processing, please wait...": "PDF image extraction processing, please wait...",
"There was an error when uploading file": "There was an error when uploading file",
"Web Worker is not supported": "Web Worker is not supported",
"Error loading files.": "Error loading files.",
"Image extraction completed": "Image extraction completed",
"Image count": "Image count",
"Error extracting images from": "Error extracting images from",
"Select existing files to modify metadata.": "Select existing files to modify metadata.",
"Select files to upload.": "Select files to upload.",
"Set the Caption here": "Set the Caption here",
"Caption": "Caption",
"Feature Image": "Feature Image",
},
};
2 changes: 2 additions & 0 deletions src/utils/pdf-extract-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,6 @@ export default async function extractPdfImages(pdfFileName, pdfBytes) {
postMessage(imageObj, [imageObj.imageData.buffer]);
}
}

return imagesInDoc.length;
}
4 changes: 2 additions & 2 deletions src/workers/extract-images-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import extractPdfImages from "../utils/pdf-extract-images.js";
addEventListener("message", async (event) => {
const { pdfFileName, data } = event.data;
try {
await extractPdfImages(pdfFileName, data);
postMessage({ type: "done" });
const imageCount = await extractPdfImages(pdfFileName, data);
postMessage({ type: "done", imageCount: imageCount, sourcePdf: pdfFileName });
} catch (error) {
postMessage({ type: "error", message: error.message, sourcePdf: pdfFileName });
console.error(error);
Expand Down
98 changes: 0 additions & 98 deletions todo.md

This file was deleted.

0 comments on commit 2a00dfb

Please sign in to comment.