Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 3229b06

Browse files
authored
Add internationalisation to progress strings in room export dialog (#7385)
1 parent 7857bf2 commit 3229b06

File tree

6 files changed

+59
-19
lines changed

6 files changed

+59
-19
lines changed

src/components/views/dialogs/ExportDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const ExportDialog: React.FC<IProps> = ({ room, onFinished }) => {
5353
const [sizeLimit, setSizeLimit] = useState<number | null>(8);
5454
const sizeLimitRef = useRef<Field>();
5555
const messageCountRef = useRef<Field>();
56-
const [exportProgressText, setExportProgressText] = useState("Processing...");
56+
const [exportProgressText, setExportProgressText] = useState(_t("Processing..."));
5757
const [displayCancel, setCancelWarning] = useState(false);
5858
const [exportCancelled, setExportCancelled] = useState(false);
5959
const [exportSuccessful, setExportSuccessful] = useState(false);

src/i18n/strings/en_EN.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,11 @@
740740
"Share your public space": "Share your public space",
741741
"Unknown App": "Unknown App",
742742
"Are you sure you want to exit during this export?": "Are you sure you want to exit during this export?",
743+
"Generating a ZIP": "Generating a ZIP",
744+
"Fetched %(count)s events out of %(total)s|other": "Fetched %(count)s events out of %(total)s",
745+
"Fetched %(count)s events out of %(total)s|one": "Fetched %(count)s event out of %(total)s",
746+
"Fetched %(count)s events so far|other": "Fetched %(count)s events so far",
747+
"Fetched %(count)s events so far|one": "Fetched %(count)s event so far",
743748
"HTML": "HTML",
744749
"JSON": "JSON",
745750
"Plain Text": "Plain Text",
@@ -752,7 +757,18 @@
752757
"This is the start of export of <roomName/>. Exported by <exporterDetails/> at %(exportDate)s.": "This is the start of export of <roomName/>. Exported by <exporterDetails/> at %(exportDate)s.",
753758
"Topic: %(topic)s": "Topic: %(topic)s",
754759
"Error fetching file": "Error fetching file",
760+
"Processing event %(number)s out of %(total)s": "Processing event %(number)s out of %(total)s",
761+
"Starting export...": "Starting export...",
762+
"Fetched %(count)s events in %(seconds)ss|other": "Fetched %(count)s events in %(seconds)ss",
763+
"Fetched %(count)s events in %(seconds)ss|one": "Fetched %(count)s event in %(seconds)ss",
764+
"Creating HTML...": "Creating HTML...",
765+
"Export successful!": "Export successful!",
766+
"Exported %(count)s events in %(seconds)s seconds|other": "Exported %(count)s events in %(seconds)s seconds",
767+
"Exported %(count)s events in %(seconds)s seconds|one": "Exported %(count)s event in %(seconds)s seconds",
755768
"File Attached": "File Attached",
769+
"Starting export process...": "Starting export process...",
770+
"Fetching events...": "Fetching events...",
771+
"Creating output...": "Creating output...",
756772
"Enable": "Enable",
757773
"That's fine": "That's fine",
758774
"Stop": "Stop",
@@ -2477,6 +2493,7 @@
24772493
"End Poll": "End Poll",
24782494
"Are you sure you want to end this poll? This will show the final results of the poll and stop people from being able to vote.": "Are you sure you want to end this poll? This will show the final results of the poll and stop people from being able to vote.",
24792495
"An error has occurred.": "An error has occurred.",
2496+
"Processing...": "Processing...",
24802497
"Enter a number between %(min)s and %(max)s": "Enter a number between %(min)s and %(max)s",
24812498
"Size can only be a number between %(min)s MB and %(max)s MB": "Size can only be a number between %(min)s MB and %(max)s MB",
24822499
"Number of messages can only be a number between %(min)s and %(max)s": "Number of messages can only be a number between %(min)s and %(max)s",

src/utils/exportUtils/Exporter.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { saveAs } from "file-saver";
2222
import { logger } from "matrix-js-sdk/src/logger";
2323

2424
import { MatrixClientPeg } from "../../MatrixClientPeg";
25-
import { IExportOptions, ExportType } from "./exportUtils";
25+
import { ExportType, IExportOptions } from "./exportUtils";
2626
import { decryptFile } from "../DecryptFile";
2727
import { mediaFromContent } from "../../customisations/Media";
2828
import { formatFullDateNoDay } from "../../DateUtils";
@@ -83,7 +83,7 @@ export default abstract class Exporter {
8383

8484
const zip = new JSZip();
8585
// Create a writable stream to the directory
86-
if (!this.cancelled) this.updateProgress("Generating a ZIP");
86+
if (!this.cancelled) this.updateProgress(_t("Generating a ZIP"));
8787
else return this.cleanUp();
8888

8989
for (const file of this.files) zip.file(filenameWithoutExt + "/" + file.name, file.blob);
@@ -172,11 +172,18 @@ export default abstract class Exporter {
172172
// }
173173
events.push(mxEv);
174174
}
175-
this.updateProgress(
176-
("Fetched " + events.length + " events ") + (this.exportType === ExportType.LastNMessages
177-
? `out of ${this.exportOptions.numberOfMessages}`
178-
: "so far"),
179-
);
175+
176+
if (this.exportType === ExportType.LastNMessages) {
177+
this.updateProgress(_t("Fetched %(count)s events out of %(total)s", {
178+
count: events.length,
179+
total: this.exportOptions.numberOfMessages,
180+
}));
181+
} else {
182+
this.updateProgress(_t("Fetched %(count)s events so far", {
183+
count: events.length,
184+
}));
185+
}
186+
180187
prevToken = res.end;
181188
}
182189
// Reverse the events so that we preserve the order

src/utils/exportUtils/HtmlExport.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,10 @@ export default class HTMLExporter extends Exporter {
395395
let prevEvent = null;
396396
for (let i = start; i < Math.min(start + 1000, events.length); i++) {
397397
const event = events[i];
398-
this.updateProgress(`Processing event ${i + 1} out of ${events.length}`, false, true);
398+
this.updateProgress(_t("Processing event %(number)s out of %(total)s", {
399+
number: i + 1,
400+
total: events.length,
401+
}), false, true);
399402
if (this.cancelled) return this.cleanUp();
400403
if (!haveTileForEvent(event)) continue;
401404

@@ -411,15 +414,18 @@ export default class HTMLExporter extends Exporter {
411414
}
412415

413416
public async export() {
414-
this.updateProgress("Starting export...");
417+
this.updateProgress(_t("Starting export..."));
415418

416419
const fetchStart = performance.now();
417420
const res = await this.getRequiredEvents();
418421
const fetchEnd = performance.now();
419422

420-
this.updateProgress(`Fetched ${res.length} events in ${(fetchEnd - fetchStart)/1000}s`, true, false);
423+
this.updateProgress(_t("Fetched %(count)s events in %(seconds)ss", {
424+
count: res.length,
425+
seconds: (fetchEnd - fetchStart) / 1000,
426+
}), true, false);
421427

422-
this.updateProgress("Creating HTML...");
428+
this.updateProgress(_t("Creating HTML..."));
423429

424430
const usedClasses = new Set<string>();
425431
for (let page = 0; page < res.length / 1000; page++) {
@@ -442,8 +448,11 @@ export default class HTMLExporter extends Exporter {
442448
if (this.cancelled) {
443449
logger.info("Export cancelled successfully");
444450
} else {
445-
this.updateProgress("Export successful!");
446-
this.updateProgress(`Exported ${res.length} events in ${(exportEnd - fetchStart)/1000} seconds`);
451+
this.updateProgress(_t("Export successful!"));
452+
this.updateProgress(_t("Exported %(count)s events in %(seconds)s seconds", {
453+
count: res.length,
454+
seconds: (exportEnd - fetchStart) / 1000,
455+
}));
447456
}
448457

449458
this.cleanUp();

src/utils/exportUtils/JSONExport.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import Exporter from "./Exporter";
2323
import { formatFullDateNoDay, formatFullDateNoDayNoTime } from "../../DateUtils";
2424
import { haveTileForEvent } from "../../components/views/rooms/EventTile";
2525
import { ExportType, IExportOptions } from "./exportUtils";
26+
import { _t } from "../../languageHandler";
2627

2728
export default class JSONExporter extends Exporter {
2829
protected totalSize = 0;
@@ -79,7 +80,10 @@ export default class JSONExporter extends Exporter {
7980
protected async createOutput(events: MatrixEvent[]) {
8081
for (let i = 0; i < events.length; i++) {
8182
const event = events[i];
82-
this.updateProgress(`Processing event ${i + 1} out of ${events.length}`, false, true);
83+
this.updateProgress(_t("Processing event %(number)s out of %(total)s", {
84+
number: i + 1,
85+
total: events.length,
86+
}), false, true);
8387
if (this.cancelled) return this.cleanUp();
8488
if (!haveTileForEvent(event)) continue;
8589
this.messages.push(await this.getJSONString(event));

src/utils/exportUtils/PlainTextExport.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ export default class PlainTextExporter extends Exporter {
107107
let content = "";
108108
for (let i = 0; i < events.length; i++) {
109109
const event = events[i];
110-
this.updateProgress(`Processing event ${i + 1} out of ${events.length}`, false, true);
110+
this.updateProgress(_t("Processing event %(number)s out of %(total)s", {
111+
number: i + 1,
112+
total: events.length,
113+
}), false, true);
111114
if (this.cancelled) return this.cleanUp();
112115
if (!haveTileForEvent(event)) continue;
113116
const textForEvent = await this.plainTextForEvent(event);
@@ -117,16 +120,16 @@ export default class PlainTextExporter extends Exporter {
117120
}
118121

119122
public async export() {
120-
this.updateProgress("Starting export process...");
121-
this.updateProgress("Fetching events...");
123+
this.updateProgress(_t("Starting export process..."));
124+
this.updateProgress(_t("Fetching events..."));
122125

123126
const fetchStart = performance.now();
124127
const res = await this.getRequiredEvents();
125128
const fetchEnd = performance.now();
126129

127130
logger.log(`Fetched ${res.length} events in ${(fetchEnd - fetchStart)/1000}s`);
128131

129-
this.updateProgress("Creating output...");
132+
this.updateProgress(_t("Creating output..."));
130133
const text = await this.createOutput(res);
131134

132135
if (this.files.length) {

0 commit comments

Comments
 (0)