Browse Source

Backport PR #10738: Add translations for kernel statuses (#10806)

Michał Krassowski 3 years ago
parent
commit
4cec12eba1

+ 1 - 1
packages/apputils/src/sessioncontext.tsx

@@ -1610,7 +1610,7 @@ namespace Private {
     const trans = translator.load('jupyterlab');
 
     const group = document.createElement('optgroup');
-    group.label = 'Use No Kernel';
+    group.label = trans.__('Use No Kernel');
     const option = document.createElement('option');
     option.text = trans.__('No Kernel');
     option.value = 'null';

+ 21 - 2
packages/apputils/src/toolbar.tsx

@@ -1,7 +1,6 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
-import { Text } from '@jupyterlab/coreutils';
 import {
   ITranslator,
   nullTranslator,
@@ -767,6 +766,22 @@ namespace Private {
       this.translator = translator || nullTranslator;
       this._trans = this.translator.load('jupyterlab');
       this.addClass(TOOLBAR_KERNEL_STATUS_CLASS);
+      // TODO-FIXME: this mapping is duplicated in statusbar/kernelStatus.tsx
+      this._statusNames = {
+        unknown: this._trans.__('Unknown'),
+        starting: this._trans.__('Starting'),
+        idle: this._trans.__('Idle'),
+        busy: this._trans.__('Busy'),
+        terminating: this._trans.__('Terminating'),
+        restarting: this._trans.__('Restarting'),
+        autorestarting: this._trans.__('Autorestarting'),
+        dead: this._trans.__('Dead'),
+        connected: this._trans.__('Connected'),
+        connecting: this._trans.__('Connecting'),
+        disconnected: this._trans.__('Disconnected'),
+        initializing: this._trans.__('Initializing'),
+        '': ''
+      };
       this._onStatusChanged(sessionContext);
       sessionContext.statusChanged.connect(this._onStatusChanged, this);
       sessionContext.connectionStatusChanged.connect(
@@ -787,7 +802,7 @@ namespace Private {
 
       const circleIconProps: LabIcon.IProps = {
         container: this.node,
-        title: this._trans.__('Kernel %1', Text.titleCase(status)),
+        title: this._trans.__('Kernel %1', this._statusNames[status] || status),
         stylesheet: 'toolbarButton',
         alignSelf: 'normal',
         height: '24px'
@@ -816,5 +831,9 @@ namespace Private {
 
     protected translator: ITranslator;
     private _trans: TranslationBundle;
+    private readonly _statusNames: Record<
+      ISessionContext.KernelDisplayStatus,
+      string
+    >;
   }
 }

+ 0 - 1
packages/statusbar/package.json

@@ -39,7 +39,6 @@
   "dependencies": {
     "@jupyterlab/apputils": "^3.1.4",
     "@jupyterlab/codeeditor": "^3.1.4",
-    "@jupyterlab/coreutils": "^5.1.4",
     "@jupyterlab/services": "^6.1.4",
     "@jupyterlab/translation": "^3.1.4",
     "@jupyterlab/ui-components": "^3.1.4",

+ 27 - 5
packages/statusbar/src/defaults/kernelStatus.tsx

@@ -2,7 +2,6 @@
 // Distributed under the terms of the Modified BSD License.
 
 import { ISessionContext, VDomModel, VDomRenderer } from '@jupyterlab/apputils';
-import { Text } from '@jupyterlab/coreutils';
 import { Session } from '@jupyterlab/services';
 import {
   ITranslator,
@@ -23,7 +22,7 @@ function KernelStatusComponent(
   const trans = translator.load('jupyterlab');
   let statusText = '';
   if (props.status) {
-    statusText = ` | ${Text.titleCase(trans.__(props.status))}`;
+    statusText = ` | ${props.status}`;
   }
   return (
     <TextItem
@@ -120,6 +119,22 @@ export namespace KernelStatus {
       translator = translator || nullTranslator;
       this._trans = translator.load('jupyterlab');
       this._kernelName = this._trans.__('No Kernel!');
+      // TODO-FIXME: this mapping is duplicated in apputils/toolbar.tsx
+      this._statusNames = {
+        unknown: this._trans.__('Unknown'),
+        starting: this._trans.__('Starting'),
+        idle: this._trans.__('Idle'),
+        busy: this._trans.__('Busy'),
+        terminating: this._trans.__('Terminating'),
+        restarting: this._trans.__('Restarting'),
+        autorestarting: this._trans.__('Autorestarting'),
+        dead: this._trans.__('Dead'),
+        connected: this._trans.__('Connected'),
+        connecting: this._trans.__('Connecting'),
+        disconnected: this._trans.__('Disconnected'),
+        initializing: this._trans.__('Initializing'),
+        '': ''
+      };
     }
 
     /**
@@ -133,7 +148,9 @@ export namespace KernelStatus {
      * The current status of the kernel.
      */
     get status() {
-      return this._kernelStatus;
+      return this._kernelStatus
+        ? this._statusNames[this._kernelStatus]
+        : undefined;
     }
 
     /**
@@ -166,7 +183,8 @@ export namespace KernelStatus {
       const oldState = this._getAllState();
       this._sessionContext = sessionContext;
       this._kernelStatus = sessionContext?.kernelDisplayStatus;
-      this._kernelName = sessionContext?.kernelDisplayName ?? 'No Kernel'; // FIXME-TRANS: ?
+      this._kernelName =
+        sessionContext?.kernelDisplayName ?? this._trans.__('No Kernel');
       sessionContext?.statusChanged.connect(this._onKernelStatusChanged, this);
       sessionContext?.connectionStatusChanged.connect(
         this._onKernelStatusChanged,
@@ -213,8 +231,12 @@ export namespace KernelStatus {
     private _trans: TranslationBundle;
     private _activityName: string = 'activity'; // FIXME-TRANS:?
     private _kernelName: string; // Initialized in constructor due to localization
-    private _kernelStatus: string | undefined = '';
+    private _kernelStatus: ISessionContext.KernelDisplayStatus | undefined = '';
     private _sessionContext: ISessionContext | null = null;
+    private readonly _statusNames: Record<
+      ISessionContext.KernelDisplayStatus,
+      string
+    >;
   }
 
   /**

+ 0 - 3
packages/statusbar/tsconfig.json

@@ -12,9 +12,6 @@
     {
       "path": "../codeeditor"
     },
-    {
-      "path": "../coreutils"
-    },
     {
       "path": "../services"
     },

+ 0 - 6
packages/statusbar/tsconfig.test.json

@@ -8,9 +8,6 @@
     {
       "path": "../codeeditor"
     },
-    {
-      "path": "../coreutils"
-    },
     {
       "path": "../services"
     },
@@ -32,9 +29,6 @@
     {
       "path": "../codeeditor"
     },
-    {
-      "path": "../coreutils"
-    },
     {
       "path": "../services"
     },