Skip to content

Commit

Permalink
tray menu options now have translations when a user changes their lan…
Browse files Browse the repository at this point in the history
…guage (#1545)
  • Loading branch information
maxx-niu authored Jan 31, 2024
1 parent 4c84ecc commit 759c6b7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
13 changes: 11 additions & 2 deletions packages/app/app/components/Settings/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { remote } from 'electron';
import { ipcRenderer, remote } from 'electron';
import { Button, Input, Radio, Segment, Icon } from 'semantic-ui-react';
import cx from 'classnames';
import _ from 'lodash';
Expand Down Expand Up @@ -99,7 +99,16 @@ const Settings: React.FC<SettingsProps> = ({
placeholder={t(placeholder)}
value={i18n.language}
options={options}
onChange={(e, { value }) => i18n.changeLanguage(value as string)}
onChange={(e, { value }) => {
i18n.changeLanguage(value as string);
ipcRenderer.send('tray-menu-translations-update', {
'play': i18n.t('command-palette:actions.play'),
'pause': i18n.t('command-palette:actions.pause'),
'next': i18n.t('command-palette:actions.next'),
'previous': i18n.t('command-palette:actions.previous'),
'quit': i18n.t('command-palette:actions.quit')
});
}}
/>
);

Expand Down
27 changes: 20 additions & 7 deletions packages/main/src/services/trayMenu/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { injectable, inject } from 'inversify';
import { Menu, app, Tray, nativeImage } from 'electron';
import { Menu, app, Tray, nativeImage, ipcMain } from 'electron';
import { NuclearMeta, IpcEvents} from '@nuclear/core';
import HttpApi from '../http';
import Config from '../config';
import Platform from '../platform';
import Window from '../window';


type PlayerContext = {
isPlaying?: boolean;
track?: NuclearMeta
Expand All @@ -18,6 +17,14 @@ class TrayMenu {

private playerContext: PlayerContext;

private trayMenuTranslations = {
'pause': 'Pause',
'play': 'Play',
'next': 'Next',
'previous': 'Previous',
'quit': 'Quit'
};

constructor(
@inject(Config) private config: Config,
@inject(HttpApi) private httpApi: HttpApi,
Expand All @@ -39,6 +46,12 @@ class TrayMenu {
});
this.tray.setToolTip(this.getToolTipString());
this.tray.setContextMenu(this.getMenu());

// apply tray menu translations when user changes language from language settings
ipcMain.on('tray-menu-translations-update', (e, translations) => {
this.trayMenuTranslations = translations;
this.update();
});
}

getMenu() {
Expand Down Expand Up @@ -69,7 +82,7 @@ class TrayMenu {
if (this.playerContext.track) {
if (this.playerContext.isPlaying) {
template.push({
label: 'Pause',
label: this.trayMenuTranslations.pause,
type: 'normal',
click: async () => {
this.window.send(IpcEvents.PAUSE);
Expand All @@ -78,7 +91,7 @@ class TrayMenu {
});
} else {
template.push({
label: 'Play',
label: this.trayMenuTranslations.play,
type: 'normal',
click: async () => {
this.window.send(IpcEvents.PLAY);
Expand All @@ -88,15 +101,15 @@ class TrayMenu {
}

template.push({
label: 'Next',
label: this.trayMenuTranslations.next,
type: 'normal',
click: async () => {
this.window.send(IpcEvents.NEXT);
}
});

template.push({
label: 'Previous',
label: this.trayMenuTranslations.previous,
type: 'normal',
click: async () => {
this.window.send(IpcEvents.PREVIOUS);
Expand All @@ -110,7 +123,7 @@ class TrayMenu {

// Quit button
template.push({
label: 'Quit',
label: this.trayMenuTranslations.quit,
type: 'normal',
click: async () => {
await this.httpApi.close();
Expand Down

0 comments on commit 759c6b7

Please sign in to comment.