Skip to content

Commit 996a718

Browse files
committed
chore: moved i18n calls in node to tr()
1 parent 1d6a74b commit 996a718

File tree

11 files changed

+96
-141
lines changed

11 files changed

+96
-141
lines changed

ts/localization/localeTools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export function propsToTuple<T extends MergedLocalizerTokens>(
144144
*
145145
* @returns The localized message string with substitutions applied.
146146
*/
147-
export function getMessageDefault<T extends MergedLocalizerTokens>(
147+
function getMessageDefault<T extends MergedLocalizerTokens>(
148148
...props: GetMessageArgs<T>
149149
): string {
150150
const token = props[0];

ts/mains/main_node.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ import { getAppRootPath } from '../node/getRootPath';
165165
import { setLatestRelease } from '../node/latest_desktop_release';
166166
import { isDevProd, isTestIntegration } from '../shared/env_vars';
167167
import { classicDark } from '../themes';
168-
import type { SetupI18nReturnType } from '../types/localizer';
169168

170169
import { isSessionLocaleSet, getCrowdinLocale } from '../util/i18n/shared';
171170
import { loadLocalizedDictionary } from '../node/locale';
@@ -177,9 +176,7 @@ import { initializeMainProcessLogger } from '../util/logger/main_process_logging
177176

178177
import * as log from '../util/logger/log';
179178
import { DURATION } from '../session/constants';
180-
181-
// Both of these will be set after app fires the 'ready' event
182-
let i18n: SetupI18nReturnType;
179+
import { tr } from '../localization/localeTools';
183180

184181
function prepareURL(pathSegments: Array<string>, moreKeys?: { theme: any }) {
185182
const urlObject: url.UrlObject = {
@@ -352,7 +349,7 @@ async function createWindow() {
352349
// Create the browser window.
353350
mainWindow = new BrowserWindow(windowOptions);
354351

355-
setupSpellChecker(mainWindow, i18n);
352+
setupSpellChecker(mainWindow);
356353

357354
const setWindowFocus = () => {
358355
if (!mainWindow) {
@@ -522,7 +519,7 @@ async function readyForUpdates() {
522519
// Second, start checking for app updates
523520
try {
524521
// if the user disabled auto updates, this will actually not start the updater
525-
await updater.start(getMainWindow, userConfig, i18n, log);
522+
await updater.start(getMainWindow, userConfig, log);
526523
} catch (error) {
527524
(log || console).error(
528525
'[updater] Error starting update checks:',
@@ -550,7 +547,7 @@ ipc.handle('force-update-check', async () => {
550547
throw new Error('Cannot use auto update! See canAutoUpdate() for more info.');
551548
}
552549

553-
const success = await checkForUpdates(getMainWindow, i18n, log, true);
550+
const success = await checkForUpdates(getMainWindow, log, true);
554551
if (!success) {
555552
throw new Error('Failed to check for updates');
556553
}
@@ -665,7 +662,7 @@ async function showAbout() {
665662
width: 550,
666663
height: 550,
667664
resizeable: true,
668-
title: i18n('about'),
665+
title: tr('about'),
669666
autoHideMenuBar: true,
670667
backgroundColor: classicDark['--background-primary-color'],
671668
show: false,
@@ -738,7 +735,6 @@ app.on('ready', async () => {
738735
if (!isSessionLocaleSet()) {
739736
const appLocale = process.env.LANGUAGE || app.getLocale() || 'en';
740737
const loadedLocale = loadLocalizedDictionary({ appLocale });
741-
i18n = loadedLocale.i18n;
742738
console.log(`appLocale is ${appLocale}`);
743739
console.log(`crowdin locale is ${loadedLocale.crowdinLocale}`);
744740
}
@@ -801,7 +797,6 @@ async function showMainWindow(sqlKey: string, passwordAttempt = false) {
801797
await sqlNode.initializeSql({
802798
configDir: userDataPath,
803799
key: sqlKey,
804-
i18n,
805800
passwordAttempt,
806801
});
807802
appStartInitialSpellcheckSetting = await getSpellCheckSetting();
@@ -816,7 +811,7 @@ async function showMainWindow(sqlKey: string, passwordAttempt = false) {
816811
await createWindow();
817812

818813
if (getStartInTray().usingTrayIcon) {
819-
tray = createTrayIcon(getMainWindow, i18n);
814+
tray = createTrayIcon(getMainWindow);
820815
}
821816

822817
setupMenu();
@@ -833,7 +828,7 @@ function setupMenu() {
833828
openSupportPage,
834829
platform,
835830
};
836-
const template = createTemplate(menuOptions, i18n);
831+
const template = createTemplate(menuOptions);
837832
const menu = Menu.buildFromTemplate(template);
838833
Menu.setApplicationMenu(menu);
839834
}
@@ -974,7 +969,7 @@ ipc.on('password-window-login', async (event, passPhrase) => {
974969
await showMainWindow(passPhrase, passwordAttempt);
975970
sendResponse(undefined);
976971
} catch (e) {
977-
sendResponse(i18n('passwordIncorrect'));
972+
sendResponse(tr('passwordIncorrect'));
978973
}
979974
});
980975

@@ -1005,7 +1000,7 @@ ipc.on('start-in-tray-on-start', (event, newValue) => {
10051000
userConfig.set('startInTray', newValue);
10061001
if (newValue) {
10071002
if (!tray) {
1008-
tray = createTrayIcon(getMainWindow, i18n);
1003+
tray = createTrayIcon(getMainWindow);
10091004
}
10101005
} else {
10111006
// destroy is not working for a lot of desktop env. So for simplicity, we don't destroy it here but just
@@ -1063,7 +1058,7 @@ ipc.on('set-password', async (event, passPhrase, oldPhrase) => {
10631058

10641059
const hashMatches = oldPhrase && PasswordUtil.matchesHash(oldPhrase, hash);
10651060
if (hash && !hashMatches) {
1066-
sendResponse(i18n('passwordCurrentIncorrect'));
1061+
sendResponse(tr('passwordCurrentIncorrect'));
10671062
return;
10681063
}
10691064

@@ -1082,7 +1077,7 @@ ipc.on('set-password', async (event, passPhrase, oldPhrase) => {
10821077
sendResponse(updatedHash);
10831078
}
10841079
} catch (e) {
1085-
sendResponse(i18n('passwordFailed'));
1080+
sendResponse(tr('passwordFailed'));
10861081
}
10871082
});
10881083

ts/node/menu.ts

Lines changed: 42 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isString } from 'lodash';
2-
import type { SetupI18nReturnType } from '../types/localizer';
32
import { LOCALE_DEFAULTS } from '../localization/constants';
3+
import { tr } from '../localization/localeTools';
44

55
/**
66
* Adds the accelerator prefix to the label for the menu item
@@ -13,17 +13,14 @@ const withAcceleratorPrefix = (label: string) => {
1313
return `&${label}`;
1414
};
1515

16-
export const createTemplate = (
17-
options: {
18-
openReleaseNotes: () => void;
19-
openSupportPage: () => void;
20-
platform: string;
21-
showAbout: () => void;
22-
saveDebugLog: (_event: any, additionalInfo?: string) => void;
23-
showWindow: () => void;
24-
},
25-
i18n: SetupI18nReturnType
26-
) => {
16+
export const createTemplate = (options: {
17+
openReleaseNotes: () => void;
18+
openSupportPage: () => void;
19+
platform: string;
20+
showAbout: () => void;
21+
saveDebugLog: (_event: any, additionalInfo?: string) => void;
22+
showWindow: () => void;
23+
}) => {
2724
if (!isString(options.platform)) {
2825
throw new TypeError('`options.platform` must be a string');
2926
}
@@ -33,122 +30,122 @@ export const createTemplate = (
3330

3431
const template = [
3532
{
36-
label: withAcceleratorPrefix(i18n('file')),
33+
label: withAcceleratorPrefix(tr('file')),
3734
submenu: [
3835
{
3936
type: 'separator',
4037
},
4138
{
4239
role: 'quit',
43-
label: i18n('quit'),
40+
label: tr('quit'),
4441
},
4542
],
4643
},
4744
{
48-
label: withAcceleratorPrefix(i18n('edit')),
45+
label: withAcceleratorPrefix(tr('edit')),
4946
submenu: [
5047
{
5148
role: 'undo',
52-
label: i18n('undo'),
49+
label: tr('undo'),
5350
},
5451
{
5552
role: 'redo',
56-
label: i18n('redo'),
53+
label: tr('redo'),
5754
},
5855
{
5956
type: 'separator',
6057
},
6158
{
6259
role: 'cut',
63-
label: i18n('cut'),
60+
label: tr('cut'),
6461
},
6562
{
6663
role: 'copy',
67-
label: i18n('copy'),
64+
label: tr('copy'),
6865
},
6966
{
7067
role: 'paste',
71-
label: i18n('paste'),
68+
label: tr('paste'),
7269
},
7370
{
7471
role: 'selectall',
75-
label: i18n('selectAll'),
72+
label: tr('selectAll'),
7673
},
7774
],
7875
},
7976
{
80-
label: withAcceleratorPrefix(i18n('view')),
77+
label: withAcceleratorPrefix(tr('view')),
8178
submenu: [
8279
{
8380
role: 'resetzoom',
84-
label: i18n('actualSize'),
81+
label: tr('actualSize'),
8582
},
8683
{
8784
accelerator: platform === 'darwin' ? 'Command+=' : 'Control+Plus',
8885
role: 'zoomin',
89-
label: i18n('appearanceZoomIn'),
86+
label: tr('appearanceZoomIn'),
9087
},
9188
{
9289
role: 'zoomout',
93-
label: i18n('appearanceZoomOut'),
90+
label: tr('appearanceZoomOut'),
9491
},
9592
{
9693
type: 'separator',
9794
},
9895
{
9996
role: 'togglefullscreen',
100-
label: i18n('fullScreenToggle'),
97+
label: tr('fullScreenToggle'),
10198
},
10299
{
103100
type: 'separator',
104101
},
105102
{
106-
label: i18n('helpReportABugExportLogs'),
103+
label: tr('helpReportABugExportLogs'),
107104
click: () => {
108105
saveDebugLog('export-logs');
109106
},
110107
},
111108
{
112109
role: 'toggledevtools',
113-
label: i18n('developerToolsToggle'),
110+
label: tr('developerToolsToggle'),
114111
},
115112
],
116113
},
117114
{
118-
label: withAcceleratorPrefix(i18n('window')),
115+
label: withAcceleratorPrefix(tr('window')),
119116
role: 'window',
120117
submenu: [
121118
{
122119
role: 'minimize',
123-
label: i18n('minimize'),
120+
label: tr('minimize'),
124121
},
125122
],
126123
},
127124
{
128-
label: withAcceleratorPrefix(i18n('sessionHelp')),
125+
label: withAcceleratorPrefix(tr('sessionHelp')),
129126
role: 'help',
130127
submenu: [
131128
{
132-
label: i18n('updateReleaseNotes'),
129+
label: tr('updateReleaseNotes'),
133130
click: openReleaseNotes,
134131
},
135132
{
136-
label: i18n('supportGoTo'),
133+
label: tr('supportGoTo'),
137134
click: openSupportPage,
138135
},
139136
{
140137
type: 'separator',
141138
},
142139
{
143-
label: i18n('about'),
140+
label: tr('about'),
144141
click: showAbout,
145142
},
146143
],
147144
},
148145
];
149146

150147
if (platform === 'darwin') {
151-
return updateForMac(template, i18n, {
148+
return updateForMac(template, {
152149
showAbout,
153150
showWindow,
154151
});
@@ -157,11 +154,7 @@ export const createTemplate = (
157154
return template;
158155
};
159156

160-
function updateForMac(
161-
template: any,
162-
i18n: SetupI18nReturnType,
163-
options: { showAbout: () => void; showWindow: () => void }
164-
) {
157+
function updateForMac(template: any, options: { showAbout: () => void; showWindow: () => void }) {
165158
const { showAbout, showWindow } = options;
166159

167160
// Remove About item and separator from Help menu, since it's on the first menu
@@ -176,7 +169,7 @@ function updateForMac(
176169
label: LOCALE_DEFAULTS.app_name,
177170
submenu: [
178171
{
179-
label: i18n('about'),
172+
label: tr('about'),
180173
click: showAbout,
181174
},
182175
{
@@ -186,22 +179,22 @@ function updateForMac(
186179
type: 'separator',
187180
},
188181
{
189-
label: i18n('hide'),
182+
label: tr('hide'),
190183
role: 'hide',
191184
},
192185
{
193-
label: i18n('hideOthers'),
186+
label: tr('hideOthers'),
194187
role: 'hideothers',
195188
},
196189
{
197-
label: i18n('showAll'),
190+
label: tr('showAll'),
198191
role: 'unhide',
199192
},
200193
{
201194
type: 'separator',
202195
},
203196
{
204-
label: i18n('quit'),
197+
label: tr('quit'),
205198
role: 'quit',
206199
},
207200
],
@@ -212,21 +205,21 @@ function updateForMac(
212205
// eslint-disable-next-line no-param-reassign
213206
template[windowMenuTemplateIndex].submenu = [
214207
{
215-
label: i18n('closeWindow'),
208+
label: tr('closeWindow'),
216209
accelerator: 'CmdOrCtrl+W',
217210
role: 'close',
218211
},
219212
{
220-
label: i18n('minimize'),
213+
label: tr('minimize'),
221214
accelerator: 'CmdOrCtrl+M',
222215
role: 'minimize',
223216
},
224217
{
225-
label: i18n('appearanceZoom'),
218+
label: tr('appearanceZoom'),
226219
role: 'zoom',
227220
},
228221
{
229-
label: i18n('show'),
222+
label: tr('show'),
230223
click: showWindow,
231224
},
232225
];

0 commit comments

Comments
 (0)