Skip to content

Commit

Permalink
Adds translator to the NotebookShell (#6725)
Browse files Browse the repository at this point in the history
* Adds translator to the NotebookShell

* move the translation plugin to application-extension

* Update packages/application-extension/src/index.ts

---------

Co-authored-by: Jeremy Tuloup <jeremy.tuloup@gmail.com>
  • Loading branch information
brichet and jtpio authored Feb 10, 2023
1 parent 6e6ac27 commit cc39a28
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
14 changes: 14 additions & 0 deletions packages/application-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,19 @@ const treePathUpdater: JupyterFrontEndPlugin<ITreePathUpdater> = {
autoStart: true
};

const translator: JupyterFrontEndPlugin<void> = {
id: '@jupyter-notebook/application-extension:translator',
requires: [INotebookShell, ITranslator],
autoStart: true,
activate: (
app: JupyterFrontEnd,
notebookShell: INotebookShell,
translator: ITranslator
) => {
notebookShell.translator = translator;
}
};

/**
* Zen mode plugin
*/
Expand Down Expand Up @@ -920,6 +933,7 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
topVisibility,
tree,
treePathUpdater,
translator,
zen
];

Expand Down
20 changes: 14 additions & 6 deletions packages/application/src/panelhandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,20 @@ export class SidePanelHandler extends PanelHandler {
this._widgetPanel = new StackedPanel();
this._widgetPanel.widgetRemoved.connect(this._onWidgetRemoved, this);

const closeButton = document.createElement('button');
this._closeButton = document.createElement('button');
closeIcon.element({
container: closeButton,
container: this._closeButton,
height: '16px',
width: 'auto'
});
closeButton.onclick = () => {
this._closeButton.onclick = () => {
this.collapse();
this.hide();
};
closeButton.className = 'jp-Button jp-SidePanel-collapse';
closeButton.title = 'Collapse side panel';
this._closeButton.className = 'jp-Button jp-SidePanel-collapse';
this._closeButton.title = 'Collapse side panel';

const icon = new Widget({ node: closeButton });
const icon = new Widget({ node: this._closeButton });
this._panel.addWidget(icon);
this._panel.addWidget(this._widgetPanel);
}
Expand Down Expand Up @@ -150,6 +150,13 @@ export class SidePanelHandler extends PanelHandler {
return this._widgetRemoved;
}

/**
* Get the close button element.
*/
get closeButton(): HTMLButtonElement {
return this._closeButton;
}

/**
* Expand the sidebar.
*
Expand Down Expand Up @@ -283,6 +290,7 @@ export class SidePanelHandler extends PanelHandler {
private _widgetPanel: StackedPanel;
private _currentWidget: Widget | null;
private _lastCurrentWidget: Widget | null;
private _closeButton: HTMLButtonElement;
private _widgetAdded: Signal<SidePanelHandler, Widget> = new Signal(this);
private _widgetRemoved: Signal<SidePanelHandler, Widget> = new Signal(this);
}
Expand Down
23 changes: 23 additions & 0 deletions packages/application/src/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { JupyterFrontEnd } from '@jupyterlab/application';
import { DocumentRegistry } from '@jupyterlab/docregistry';
import { ITranslator, nullTranslator } from '@jupyterlab/translation';

import { find } from '@lumino/algorithm';
import { PromiseDelegate, Token } from '@lumino/coreutils';
Expand Down Expand Up @@ -179,6 +180,27 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell {
return this._mainWidgetLoaded.promise;
}

/**
* Getter and setter for the translator.
*/
get translator(): ITranslator {
return this._translator ?? nullTranslator;
}
set translator(value: ITranslator) {
if (value !== this._translator) {
this._translator = value;
const trans = value.load('notebook');
this._leftHandler.closeButton.title = trans.__(
'Collapse %1 side panel',
this._leftHandler.area
);
this._rightHandler.closeButton.title = trans.__(
'Collapse %1 side panel',
this._rightHandler.area
);
}
}

/**
* Activate a widget in its area.
*/
Expand Down Expand Up @@ -324,6 +346,7 @@ export class NotebookShell extends Widget implements JupyterFrontEnd.IShell {
private _rightHandler: SidePanelHandler;
private _spacer: Widget;
private _main: Panel;
private _translator: ITranslator = nullTranslator;
private _currentChanged = new Signal<this, void>(this);
private _mainWidgetLoaded = new PromiseDelegate<void>();
}
Expand Down

0 comments on commit cc39a28

Please sign in to comment.