Skip to content

Commit 9dd5fd2

Browse files
committed
Mark more strings for translation.
Fixes #1128 among many other things. Signed-off-by: Anders Kaseorg <[email protected]>
1 parent 11e2635 commit 9dd5fd2

File tree

14 files changed

+98
-47
lines changed

14 files changed

+98
-47
lines changed

app/common/link-util.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import fs from "node:fs";
33
import os from "node:os";
44
import path from "node:path";
55

6-
import {html} from "./html.ts";
6+
import {Html, html} from "./html.ts";
7+
import * as t from "./translation-util.ts";
78

89
export async function openBrowser(url: URL): Promise<void> {
910
if (["http:", "https:", "mailto:"].includes(url.protocol)) {
@@ -21,15 +22,21 @@ export async function openBrowser(url: URL): Promise<void> {
2122
<head>
2223
<meta charset="UTF-8" />
2324
<meta http-equiv="Refresh" content="0; url=${url.href}" />
24-
<title>Redirecting</title>
25+
<title>${t.__("Redirecting")}</title>
2526
<style>
2627
html {
2728
font-family: menu, "Helvetica Neue", sans-serif;
2829
}
2930
</style>
3031
</head>
3132
<body>
32-
<p>Opening <a href="${url.href}">${url.href}</a></p>
33+
<p>
34+
${new Html({
35+
html: t.__("Opening {{{link}}}…", {
36+
link: html`<a href="${url.href}">${url.href}</a>`.html,
37+
}),
38+
})}
39+
</p>
3340
</body>
3441
</html>
3542
`.html,

app/common/messages.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as t from "./translation-util.ts";
2+
13
type DialogBoxError = {
24
title: string;
35
content: string;
@@ -13,26 +15,24 @@ export function invalidZulipServerError(domain: string): string {
1315
https://zulip.readthedocs.io/en/stable/production/ssl-certificates.html`;
1416
}
1517

16-
export function enterpriseOrgError(
17-
length: number,
18-
domains: string[],
19-
): DialogBoxError {
18+
export function enterpriseOrgError(domains: string[]): DialogBoxError {
2019
let domainList = "";
2120
for (const domain of domains) {
2221
domainList += `• ${domain}\n`;
2322
}
2423

2524
return {
26-
title: `Could not add the following ${
27-
length === 1 ? "organization" : "organizations"
28-
}`,
29-
content: `${domainList}\nPlease contact your system administrator.`,
25+
title: t.__mf(
26+
"{number, plural, one {Could not add # organization} other {Could not add # organizations}}",
27+
{number: domains.length},
28+
),
29+
content: `${domainList}\n${t.__("Please contact your system administrator.")}`,
3030
};
3131
}
3232

3333
export function orgRemovalError(url: string): DialogBoxError {
3434
return {
35-
title: `Removing ${url} is a restricted operation.`,
36-
content: "Please contact your system administrator.",
35+
title: t.__("Removing {{{url}}} is a restricted operation.", {url}),
36+
content: t.__("Please contact your system administrator."),
3737
};
3838
}

app/common/translation-util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ i18n.configure({
1313
/* Fetches the current appLocale from settings.json */
1414
i18n.setLocale(ConfigUtil.getConfigItem("appLanguage", "en") ?? "en");
1515

16-
export {__} from "i18n";
16+
export {__, __mf} from "i18n";

app/main/handle-external-link.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import path from "node:path";
1111

1212
import * as ConfigUtil from "../common/config-util.ts";
1313
import * as LinkUtil from "../common/link-util.ts";
14+
import * as t from "../common/translation-util.ts";
1415

1516
import {send} from "./typed-ipc-main.ts";
1617

@@ -125,8 +126,8 @@ export default function handleExternalLink(
125126
downloadPath,
126127
async completed(filePath: string, fileName: string) {
127128
const downloadNotification = new Notification({
128-
title: "Download Complete",
129-
body: `Click to show ${fileName} in folder`,
129+
title: t.__("Download Complete"),
130+
body: t.__("Click to show {{{fileName}}} in folder", {fileName}),
130131
silent: true, // We'll play our own sound - ding.ogg
131132
});
132133
downloadNotification.on("click", () => {
@@ -149,8 +150,8 @@ export default function handleExternalLink(
149150
if (state !== "cancelled") {
150151
if (ConfigUtil.getConfigItem("promptDownload", false)) {
151152
new Notification({
152-
title: "Download Complete",
153-
body: "Download failed",
153+
title: t.__("Download Complete"),
154+
body: t.__("Download failed"),
154155
}).show();
155156
} else {
156157
contents.downloadURL(url.href);

app/main/linuxupdater.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {z} from "zod";
55

66
import * as ConfigUtil from "../common/config-util.ts";
77
import Logger from "../common/logger-util.ts";
8+
import * as t from "../common/translation-util.ts";
89

910
import * as LinuxUpdateUtil from "./linux-update-util.ts";
1011

@@ -34,8 +35,11 @@ export async function linuxUpdateNotification(session: Session): Promise<void> {
3435
const notified = LinuxUpdateUtil.getUpdateItem(latestVersion);
3536
if (notified === null) {
3637
new Notification({
37-
title: "Zulip Update",
38-
body: `A new version ${latestVersion} is available. Please update using your package manager.`,
38+
title: t.__("Zulip Update"),
39+
body: t.__(
40+
"A new version {{{version}}} is available. Please update using your package manager.",
41+
{version: latestVersion},
42+
),
3943
}).show();
4044
LinuxUpdateUtil.setUpdateItem(latestVersion, true);
4145
}

app/renderer/js/main.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ export class ServerManagerView {
8080
$dndTooltip: HTMLElement;
8181
$sidebar: Element;
8282
$fullscreenPopup: Element;
83-
$fullscreenEscapeKey: string;
8483
loading: Set<string>;
8584
activeTabIndex: number;
8685
tabs: ServerOrFunctionalTab[];
@@ -121,8 +120,10 @@ export class ServerManagerView {
121120
this.$sidebar = document.querySelector("#sidebar")!;
122121

123122
this.$fullscreenPopup = document.querySelector("#fullscreen-popup")!;
124-
this.$fullscreenEscapeKey = process.platform === "darwin" ? "^⌘F" : "F11";
125-
this.$fullscreenPopup.textContent = `Press ${this.$fullscreenEscapeKey} to exit full screen`;
123+
this.$fullscreenPopup.textContent = t.__(
124+
"Press {{{exitKey}}} to exit full screen",
125+
{exitKey: process.platform === "darwin" ? "^⌘F" : "F11"},
126+
);
126127

127128
this.loading = new Set();
128129
this.activeTabIndex = -1;
@@ -261,7 +262,10 @@ export class ServerManagerView {
261262
} catch (error: unknown) {
262263
logger.error(error);
263264
logger.error(
264-
`Could not add ${domain}. Please contact your system administrator.`,
265+
t.__(
266+
"Could not add {{{domain}}}. Please contact your system administrator.",
267+
{domain},
268+
),
265269
);
266270
return false;
267271
}
@@ -311,10 +315,7 @@ export class ServerManagerView {
311315
failedDomains.push(org);
312316
}
313317

314-
const {title, content} = Messages.enterpriseOrgError(
315-
domainsAdded.length,
316-
failedDomains,
317-
);
318+
const {title, content} = Messages.enterpriseOrgError(failedDomains);
318319
dialog.showErrorBox(title, content);
319320
if (DomainUtil.getDomains().length === 0) {
320321
// No orgs present, stop showing loading gif
@@ -795,8 +796,9 @@ export class ServerManagerView {
795796

796797
// Toggles the dnd button icon.
797798
toggleDndButton(alert: boolean): void {
798-
this.$dndTooltip.textContent =
799-
(alert ? "Disable" : "Enable") + " Do Not Disturb";
799+
this.$dndTooltip.textContent = alert
800+
? t.__("Disable Do Not Disturb")
801+
: t.__("Enable Do Not Disturb");
800802
const $dndIcon = this.$dndButton.querySelector("i")!;
801803
$dndIcon.textContent = alert ? "notifications_off" : "notifications";
802804

app/renderer/js/pages/preference/base-section.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {type Html, html} from "../../../../common/html.ts";
2+
import * as t from "../../../../common/translation-util.ts";
23
import {generateNodeFromHtml} from "../../components/base.ts";
34
import {ipcRenderer} from "../../typed-ipc-renderer.ts";
45

@@ -31,7 +32,7 @@ export function generateOptionHtml(
3132
const labelHtml = disabled
3233
? html`<label
3334
class="disallowed"
34-
title="Setting locked by system administrator."
35+
title="${t.__("Setting locked by system administrator.")}"
3536
></label>`
3637
: html`<label></label>`;
3738
if (settingOption) {

app/renderer/js/pages/preference/general-section.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,9 @@ export function initGeneralSection({$root}: GeneralSectionProperties): void {
561561
}
562562

563563
async function factoryResetSettings(): Promise<void> {
564-
const clearAppDataMessage =
565-
"When the application restarts, it will be as if you have just downloaded Zulip app.";
564+
const clearAppDataMessage = t.__(
565+
"When the application restarts, it will be as if you have just downloaded the Zulip app.",
566+
);
566567
const getAppPath = path.join(app.getPath("appData"), app.name);
567568

568569
const {response} = await dialog.showMessageBox({
@@ -609,7 +610,7 @@ export function initGeneralSection({$root}: GeneralSectionProperties): void {
609610
spellDiv.innerHTML += html`
610611
<div class="setting-description">${t.__("Spellchecker Languages")}</div>
611612
<div id="spellcheck-langs-value">
612-
<input name="spellcheck" placeholder="Enter Languages" />
613+
<input name="spellcheck" placeholder="${t.__("Enter Languages")}" />
613614
</div>
614615
`.html;
615616

app/renderer/js/pages/preference/network-section.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function initNetworkSection({$root}: NetworkSectionProperties): void {
2828
</div>
2929
<div class="manual-proxy-block">
3030
<div class="setting-row" id="proxy-pac-option">
31-
<span class="setting-input-key">PAC ${t.__("script")}</span>
31+
<span class="setting-input-key">${t.__("PAC script")}</span>
3232
<input
3333
class="setting-input-value"
3434
placeholder="e.g. foobar.com/pacfile.js"

app/renderer/js/pages/preference/new-server-form.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ export function initNewServerForm({
2323
<input
2424
class="setting-input-value"
2525
autofocus
26-
placeholder="your-organization.zulipchat.com or zulip.your-organization.com"
26+
placeholder="${t.__(
27+
"your-organization.zulipchat.com or zulip.your-organization.com",
28+
)}"
2729
/>
2830
</div>
2931
<div class="server-center">
@@ -60,12 +62,12 @@ export function initNewServerForm({
6062
)!;
6163

6264
async function submitFormHandler(): Promise<void> {
63-
$saveServerButton.textContent = "Connecting...";
65+
$saveServerButton.textContent = t.__("Connecting…");
6466
let serverConfig;
6567
try {
6668
serverConfig = await DomainUtil.checkDomain($newServerUrl.value.trim());
6769
} catch (error: unknown) {
68-
$saveServerButton.textContent = "Connect";
70+
$saveServerButton.textContent = t.__("Connect");
6971
await dialog.showMessageBox({
7072
type: "error",
7173
message:

0 commit comments

Comments
 (0)