Browse Source

Fix lint and add translator to shell

Martha Cryan 4 years ago
parent
commit
7fd9334364

+ 29 - 6
packages/application/src/shell.ts

@@ -2,6 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 
 import { DocumentRegistry, DocumentWidget } from '@jupyterlab/docregistry';
+import { ITranslator, nullTranslator } from '@jupyterlab/translation';
 
 import { classes, DockPanelSvg, LabIcon } from '@jupyterlab/ui-components';
 
@@ -91,6 +92,16 @@ export namespace ILabShell {
    */
   export type AreaConfig = DockLayout.AreaConfig;
 
+  /**
+   * An options object for creating a lab shell object.
+   */
+  export type IOptions = {
+    /**
+     * The application language translator.
+     */
+    translator?: ITranslator;
+  };
+
   /**
    * An arguments object for the changed signals.
    */
@@ -185,15 +196,21 @@ export class LabShell extends Widget implements JupyterFrontEnd.IShell {
   /**
    * Construct a new application shell.
    */
-  constructor() {
+  constructor(options?: ILabShell.IOptions) {
     super();
     this.addClass(APPLICATION_SHELL_CLASS);
     this.id = 'main';
 
+    const trans = ((options && options.translator) || nullTranslator).load(
+      'jupyterlab'
+    );
     const headerPanel = (this._headerPanel = new BoxPanel());
     const menuHandler = (this._menuHandler = new Private.PanelHandler());
     menuHandler.panel.node.setAttribute('role', 'navigation');
-    menuHandler.panel.node.setAttribute('aria-label', 'main navigation');
+    menuHandler.panel.node.setAttribute(
+      'aria-label',
+      trans.__('main navigation')
+    );
     const topHandler = (this._topHandler = new Private.PanelHandler());
     topHandler.panel.node.setAttribute('role', 'banner');
     const bottomPanel = (this._bottomPanel = new BoxPanel());
@@ -218,22 +235,28 @@ export class LabShell extends Widget implements JupyterFrontEnd.IShell {
     leftHandler.sideBar.addClass(SIDEBAR_CLASS);
     leftHandler.sideBar.addClass('jp-mod-left');
     leftHandler.sideBar.node.setAttribute('role', 'complementary');
-    leftHandler.sideBar.node.setAttribute('aria-label', 'main sidebar');
+    leftHandler.sideBar.node.setAttribute(
+      'aria-label',
+      trans.__('main sidebar')
+    );
     leftHandler.sideBar.contentNode.setAttribute('role', 'navigation');
     leftHandler.sideBar.contentNode.setAttribute(
       'aria-label',
-      'main sidebar navigation'
+      trans.__('main sidebar navigation')
     );
     leftHandler.stackedPanel.id = 'jp-left-stack';
 
     rightHandler.sideBar.addClass(SIDEBAR_CLASS);
     rightHandler.sideBar.addClass('jp-mod-right');
     rightHandler.sideBar.node.setAttribute('role', 'complementary');
-    rightHandler.sideBar.node.setAttribute('aria-label', 'alternate sidebar');
+    rightHandler.sideBar.node.setAttribute(
+      'aria-label',
+      trans.__('alternate sidebar')
+    );
     rightHandler.sideBar.contentNode.setAttribute('role', 'navigation');
     rightHandler.sideBar.contentNode.setAttribute(
       'aria-label',
-      'alternate sidebar navigation'
+      trans.__('alternate sidebar navigation')
     );
     rightHandler.stackedPanel.id = 'jp-right-stack';
 

+ 4 - 1
packages/apputils-extension/src/palette.ts

@@ -104,7 +104,10 @@ export namespace Palette {
     let modal = false;
 
     palette.node.setAttribute('role', 'region');
-    palette.node.setAttribute('aria-label', trans.__('Command Palette Section'));
+    palette.node.setAttribute(
+      'aria-label',
+      trans.__('Command Palette Section')
+    );
     shell.add(palette, 'left', { rank: 300 });
 
     if (settingRegistry) {

+ 8 - 2
packages/extensionmanager-extension/src/index.ts

@@ -65,7 +65,10 @@ const plugin: JupyterFrontEndPlugin<void> = {
     if (enabled && labShell) {
       view = createView();
       view.node.setAttribute('role', 'region');
-      view.node.setAttribute('aria-label', trans.__('Extension Manager section'));
+      view.node.setAttribute(
+        'aria-label',
+        trans.__('Extension Manager section')
+      );
       labShell.add(view, 'left', { rank: 1000 });
     }
 
@@ -83,7 +86,10 @@ const plugin: JupyterFrontEndPlugin<void> = {
             }
             view = view || createView();
             view.node.setAttribute('role', 'region');
-            view.node.setAttribute('aria-label', trans.__('Extension Manager section'));
+            view.node.setAttribute(
+              'aria-label',
+              trans.__('Extension Manager section')
+            );
             if (labShell) {
               labShell.add(view, 'left', { rank: 1000 });
             }

+ 4 - 1
packages/filebrowser/src/browser.ts

@@ -88,7 +88,10 @@ export class FileBrowser extends Widget {
     this.toolbar = new Toolbar<Widget>();
     // a11y
     this.toolbar.node.setAttribute('role', 'navigation');
-    this.toolbar.node.setAttribute('aria-label', this._trans.__('file browser'));
+    this.toolbar.node.setAttribute(
+      'aria-label',
+      this._trans.__('file browser')
+    );
     this._directoryPending = false;
 
     const newFolder = new ToolbarButton({