Skip to content

Commit fd4857f

Browse files
authored
fix: tray translation waits for i18n init (#2604)
* fix: tray translation waits for i18n init * chore: update i18n context name
1 parent 28174ce commit fd4857f

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/context.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const pDefer = require('p-defer')
33
const logger = require('./common/logger')
44

55
/**
6-
* @typedef { 'tray' | 'tray-menu-state' | 'tray.update-menu' | 'countlyDeviceId' | 'manualCheckForUpdates' | 'startIpfs' | 'stopIpfs' | 'restartIpfs' | 'getIpfsd' | 'launchWebUI' | 'webui' | 'splashScreen'} ContextProperties
6+
* @typedef { 'tray' | 'tray-menu-state' | 'tray.update-menu' | 'countlyDeviceId' | 'manualCheckForUpdates' | 'startIpfs' | 'stopIpfs' | 'restartIpfs' | 'getIpfsd' | 'launchWebUI' | 'webui' | 'splashScreen' | 'i18n.initDone' } ContextProperties
77
*/
88

99
/**

src/i18n.js

+3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ const Backend = require('i18next-fs-backend')
66
const store = require('./common/store')
77
const ipcMainEvents = require('./common/ipc-main-events')
88
const logger = require('./common/logger')
9+
const getCtx = require('./context')
910

1011
module.exports = async function () {
12+
const ctx = getCtx()
1113
logger.info('[i18n] init...')
1214
await i18n
1315
// @ts-expect-error
@@ -26,6 +28,7 @@ module.exports = async function () {
2628
}
2729
})
2830
logger.info('[i18n] init done')
31+
ctx.setProp('i18n.initDone', true)
2932

3033
ipcMain.on(ipcMainEvents.LANG_UPDATED, async (_, lang) => {
3134
if (lang === store.get('language')) {

src/tray.js

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ async function buildMenu () {
4343
const stopIpfs = ctx.getFn('stopIpfs')
4444
const launchWebUI = ctx.getFn('launchWebUI')
4545
const manualCheckForUpdates = ctx.getFn('manualCheckForUpdates')
46+
/**
47+
* we need to wait for i18n to be ready before we translate the tray menu
48+
* @type {boolean}
49+
*/
50+
await ctx.getProp('i18n.initDone')
4651

4752
// @ts-expect-error
4853
return Menu.buildFromTemplate([

0 commit comments

Comments
 (0)