diff --git a/packages/application-extension/src/index.ts b/packages/application-extension/src/index.ts index 470d1fa1a6..5b937ea9ab 100644 --- a/packages/application-extension/src/index.ts +++ b/packages/application-extension/src/index.ts @@ -844,6 +844,19 @@ const treePathUpdater: JupyterFrontEndPlugin = { autoStart: true }; +const translator: JupyterFrontEndPlugin = { + id: '@jupyter-notebook/application-extension:translator', + requires: [INotebookShell, ITranslator], + autoStart: true, + activate: ( + app: JupyterFrontEnd, + notebookShell: INotebookShell, + translator: ITranslator + ) => { + notebookShell.translator = translator; + } +}; + /** * Zen mode plugin */ @@ -920,6 +933,7 @@ const plugins: JupyterFrontEndPlugin[] = [ topVisibility, tree, treePathUpdater, + translator, zen ]; diff --git a/packages/application/src/panelhandler.ts b/packages/application/src/panelhandler.ts index 356a74cacb..212baa9abb 100644 --- a/packages/application/src/panelhandler.ts +++ b/packages/application/src/panelhandler.ts @@ -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); } @@ -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. * @@ -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 = new Signal(this); private _widgetRemoved: Signal = new Signal(this); } diff --git a/packages/application/src/shell.ts b/packages/application/src/shell.ts index 36b754c0fd..96b7c4b66a 100644 --- a/packages/application/src/shell.ts +++ b/packages/application/src/shell.ts @@ -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'; @@ -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. */ @@ -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); private _mainWidgetLoaded = new PromiseDelegate(); }