Skip to content

Commit b98ab7b

Browse files
committed
Fixed missing translations in archiving popup, when triggered from navigation and the single rows in grid
1 parent e9abe6c commit b98ab7b

3 files changed

Lines changed: 59 additions & 43 deletions

File tree

src/main/i18n.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
import i18n from "i18next";
2+
import { app } from "electron";
23
import { SettingsStore } from "./Stores";
34
import { i18nextOptions } from "../i18n.config";
45
import { File } from "../@types";
56

6-
function setupI18n() {
7+
async function setupI18n() {
78
i18n.init(i18nextOptions);
89

9-
const language = SettingsStore.get("language") || "en";
10-
i18n.changeLanguage(language);
10+
const language = SettingsStore.get("language");
11+
if (!language) {
12+
const systemLocale = app.getLocale();
13+
const normalizedLocale = systemLocale.split("-")[0];
14+
const supportedLanguages = i18nextOptions.resources
15+
? Object.keys(i18nextOptions.resources)
16+
: [];
17+
const detectedLanguage = supportedLanguages.includes(normalizedLocale)
18+
? normalizedLocale
19+
: "en";
20+
SettingsStore.set("language", detectedLanguage);
21+
await i18n.changeLanguage(detectedLanguage);
22+
} else {
23+
await i18n.changeLanguage(language);
24+
}
1125

1226
SettingsStore.onDidChange("language", async (newLanguage) => {
13-
i18n.changeLanguage(newLanguage);
27+
await i18n.changeLanguage(newLanguage);
1428
// Lazy import to avoid circular dependency
1529
const { UpdateTrayMenu } = await import("./Tray");
1630
const { CreateMenu } = await import("./Menu");

src/main/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ if (!gotTheLock) {
235235

236236
app
237237
.whenReady()
238-
.then(() => {
239-
setupI18n();
238+
.then(async () => {
239+
await setupI18n();
240240
registerAllHandlers();
241241
const tray = SettingsStore.get("tray");
242242
const startMinimized = SettingsStore.get("startMinimized");

src/renderer/Archive.tsx

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,6 @@ const ArchiveComponent: React.FC<ArchiveComponentProps> = ({
1818
number | undefined
1919
>(undefined);
2020

21-
const handleTriggerArchiving = (
22-
doneFileAvailable: boolean,
23-
lineNumber?: number,
24-
): void => {
25-
setArchiveLineNumber(lineNumber);
26-
setPromptItem(
27-
doneFileAvailable
28-
? lineNumber
29-
? promptItemArchivingSingle
30-
: promptItemArchivingAll
31-
: promptItemChooseChangeFile,
32-
);
33-
};
34-
3521
const handleArchiveAllConfirm = (): void => {
3622
ipcRenderer.send("archiveTodos");
3723
};
@@ -48,30 +34,46 @@ const ArchiveComponent: React.FC<ArchiveComponentProps> = ({
4834
ipcRenderer.send("createFile", true, archiveLineNumber);
4935
};
5036

51-
const promptItemArchivingAll = {
52-
id: "archive",
53-
headline: t("prompt.archive.headline"),
54-
text: t("prompt.archive.text"),
55-
button1: t("archive"),
56-
onButton1: handleArchiveAllConfirm,
57-
};
37+
const handleTriggerArchiving = (
38+
doneFileAvailable: boolean,
39+
lineNumber?: number,
40+
): void => {
41+
setArchiveLineNumber(lineNumber);
5842

59-
const promptItemArchivingSingle = {
60-
id: "archive",
61-
headline: t("prompt.archive.headline.single"),
62-
text: t("prompt.archive.text.single"),
63-
button1: t("archive"),
64-
onButton1: handleArchiveSingleConfirm,
65-
};
43+
// Define prompt items here to get fresh translations every time
44+
const promptItemArchivingAll = {
45+
id: "archive",
46+
headline: t("prompt.archive.headline"),
47+
text: t("prompt.archive.text"),
48+
button1: t("archive"),
49+
onButton1: handleArchiveAllConfirm,
50+
};
51+
52+
const promptItemArchivingSingle = {
53+
id: "archive",
54+
headline: t("prompt.archive.headline.single"),
55+
text: t("prompt.archive.text.single"),
56+
button1: t("archive"),
57+
onButton1: handleArchiveSingleConfirm,
58+
};
59+
60+
const promptItemChooseChangeFile = {
61+
id: "changeFile",
62+
headline: t("prompt.archive.changeFile.headline"),
63+
text: t("prompt.archive.changeFile.text"),
64+
button1: t("openFile"),
65+
onButton1: handleOpenDoneFile,
66+
button2: t("createFile"),
67+
onButton2: handleCreateDoneFile,
68+
};
6669

67-
const promptItemChooseChangeFile = {
68-
id: "changeFile",
69-
headline: t("prompt.archive.changeFile.headline"),
70-
text: t("prompt.archive.changeFile.text"),
71-
button1: t("openFile"),
72-
onButton1: handleOpenDoneFile,
73-
button2: t("createFile"),
74-
onButton2: handleCreateDoneFile,
70+
setPromptItem(
71+
doneFileAvailable
72+
? lineNumber
73+
? promptItemArchivingSingle
74+
: promptItemArchivingAll
75+
: promptItemChooseChangeFile,
76+
);
7577
};
7678

7779
useEffect((): void => {
@@ -85,7 +87,7 @@ const ArchiveComponent: React.FC<ArchiveComponentProps> = ({
8587
return (): void => {
8688
ipcRenderer.off("triggerArchiving", handleTriggerArchiving);
8789
};
88-
}, []);
90+
}, [handleTriggerArchiving]);
8991

9092
return <></>;
9193
};

0 commit comments

Comments
 (0)