Adds translator to the NotebookShell (#6725)

* 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>
Nicolas Brichet 3 years ago committed by GitHub
parent 6e6ac276e7
commit cc39a28c07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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
*/
@ -920,6 +933,7 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
topVisibility,
tree,
treePathUpdater,
translator,
zen
];

@ -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<SidePanelHandler, Widget> = new Signal(this);
private _widgetRemoved: Signal<SidePanelHandler, Widget> = new Signal(this);
}

@ -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, void>(this);
private _mainWidgetLoaded = new PromiseDelegate<void>();
}

Loading…
Cancel
Save