Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tray translation waits for i18n init #2604

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const pDefer = require('p-defer')
const logger = require('./common/logger')

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

/**
Expand Down
3 changes: 3 additions & 0 deletions src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ const Backend = require('i18next-fs-backend')
const store = require('./common/store')
const ipcMainEvents = require('./common/ipc-main-events')
const logger = require('./common/logger')
const getCtx = require('./context')

module.exports = async function () {
const ctx = getCtx()
logger.info('[i18n] init...')
await i18n
// @ts-expect-error
Expand All @@ -26,6 +28,7 @@ module.exports = async function () {
}
})
logger.info('[i18n] init done')
ctx.setProp('i18n.initDone', true)

ipcMain.on(ipcMainEvents.LANG_UPDATED, async (_, lang) => {
if (lang === store.get('language')) {
Expand Down
5 changes: 5 additions & 0 deletions src/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ async function buildMenu () {
const stopIpfs = ctx.getFn('stopIpfs')
const launchWebUI = ctx.getFn('launchWebUI')
const manualCheckForUpdates = ctx.getFn('manualCheckForUpdates')
/**
* we need to wait for i18n to be ready before we translate the tray menu
* @type {boolean}
*/
await ctx.getProp('i18n.initDone')

// @ts-expect-error
return Menu.buildFromTemplate([
Expand Down