Skip to content

Commit dd2eb94

Browse files
authored
Merge pull request #117 from kgoo124/localization-kernel-messaging
Localization for kernel-messaging example
2 parents 5cf924b + 03cf9ed commit dd2eb94

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed

advanced/kernel-messaging/README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Jupyterlab provides a class `SessionContext`
3636
that manages a single kernel session. Here is the code to initialize such session:
3737

3838
```ts
39-
// src/panel.ts#L33-L37
39+
// src/panel.ts#L41-L45
4040

4141
this._sessionContext = new SessionContext({
4242
sessionManager: manager.sessions,
@@ -46,7 +46,7 @@ this._sessionContext = new SessionContext({
4646
```
4747

4848
<!-- prettier-ignore-start -->
49-
<!-- embedme src/panel.ts#L43-L54 -->
49+
<!-- embedme src/panel.ts#L51-L62 -->
5050

5151
```ts
5252
void this._sessionContext
@@ -68,7 +68,7 @@ The session manager object is
6868
provided directly by the JupyterLab application:
6969

7070
```ts
71-
// src/index.ts#L48-L48
71+
// src/index.ts#L52-L52
7272

7373
const manager = app.serviceManager;
7474
```
@@ -81,14 +81,16 @@ to free the kernel session resources if the panel is closed. The whole adapted
8181
panel class looks like this:
8282

8383
```ts
84-
// src/panel.ts#L25-L74
84+
// src/panel.ts#L31-L85
8585

8686
export class ExamplePanel extends StackedPanel {
87-
constructor(manager: ServiceManager.IManager) {
87+
constructor(manager: ServiceManager.IManager, translator?: ITranslator) {
8888
super();
89+
this._translator = translator || nullTranslator;
90+
this._trans = this._translator.load('jupyterlab');
8991
this.addClass(PANEL_CLASS);
9092
this.id = 'kernel-messaging-panel';
91-
this.title.label = 'Kernel Messaging Example View';
93+
this.title.label = this._trans.__('Kernel Messaging Example View');
9294
this.title.closable = true;
9395

9496
this._sessionContext = new SessionContext({
@@ -132,6 +134,9 @@ export class ExamplePanel extends StackedPanel {
132134
private _model: KernelModel;
133135
private _sessionContext: SessionContext;
134136
private _example: KernelView;
137+
138+
private _translator: ITranslator;
139+
private _trans: TranslationBundle;
135140
}
136141
```
137142

advanced/kernel-messaging/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@
4242
"watch:src": "tsc -w"
4343
},
4444
"dependencies": {
45-
"@jupyterlab/application": "~3.0.0-beta.4",
46-
"@jupyterlab/launcher": "~3.0.0-beta.4",
47-
"@jupyterlab/mainmenu": "~3.0.0-beta.4",
48-
"@jupyterlab/nbformat": "~3.0.0-beta.4",
45+
"@jupyterlab/application": "^3.0.0-beta.8",
46+
"@jupyterlab/launcher": "^3.0.0-beta.8",
47+
"@jupyterlab/mainmenu": "^3.0.0-beta.8",
48+
"@jupyterlab/nbformat": "^3.0.0-beta.8",
49+
"@jupyterlab/translation": "^3.0.0-beta.8",
4950
"@lumino/algorithm": "^1.3.3",
5051
"@lumino/coreutils": "^1.5.3",
5152
"@lumino/datagrid": "^0.5.2",

advanced/kernel-messaging/src/index.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { ILauncher } from '@jupyterlab/launcher';
99

1010
import { IMainMenu } from '@jupyterlab/mainmenu';
1111

12+
import { ITranslator } from '@jupyterlab/translation';
13+
1214
import { Menu } from '@lumino/widgets';
1315

1416
import { ExamplePanel } from './panel';
@@ -27,27 +29,30 @@ const extension: JupyterFrontEndPlugin<void> = {
2729
id: 'kernel-messaging',
2830
autoStart: true,
2931
optional: [ILauncher],
30-
requires: [ICommandPalette, IMainMenu],
32+
requires: [ICommandPalette, IMainMenu, ITranslator],
3133
activate: activate
3234
};
3335

3436
/**
3537
* Activate the JupyterLab extension.
3638
*
37-
* @param app Jupyter Font End
39+
* @param app Jupyter Front End
3840
* @param palette Jupyter Commands Palette
3941
* @param mainMenu Jupyter Menu
42+
* @param translator Jupyter Translator
4043
* @param launcher [optional] Jupyter Launcher
4144
*/
4245
function activate(
4346
app: JupyterFrontEnd,
4447
palette: ICommandPalette,
4548
mainMenu: IMainMenu,
49+
translator: ITranslator,
4650
launcher: ILauncher | null
4751
): void {
4852
const manager = app.serviceManager;
4953
const { commands, shell } = app;
5054
const category = 'Extension Examples';
55+
const trans = translator.load('jupyterlab');
5156

5257
// Add launcher
5358
if (launcher) {
@@ -63,20 +68,20 @@ function activate(
6368
* @returns The panel
6469
*/
6570
async function createPanel(): Promise<ExamplePanel> {
66-
const panel = new ExamplePanel(manager);
71+
const panel = new ExamplePanel(manager, translator);
6772
shell.add(panel, 'main');
6873
return panel;
6974
}
7075

7176
// add menu tab
7277
const exampleMenu = new Menu({ commands });
73-
exampleMenu.title.label = 'Kernel Messaging';
78+
exampleMenu.title.label = trans.__('Kernel Messaging');
7479
mainMenu.addMenu(exampleMenu);
7580

7681
// add commands to registry
7782
commands.addCommand(CommandIDs.create, {
78-
label: 'Open the Kernel Messaging Panel',
79-
caption: 'Open the Kernel Messaging Panel',
83+
label: trans.__('Open the Kernel Messaging Panel'),
84+
caption: trans.__('Open the Kernel Messaging Panel'),
8085
execute: createPanel
8186
});
8287

advanced/kernel-messaging/src/panel.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import {
44
sessionContextDialogs
55
} from '@jupyterlab/apputils';
66

7+
import {
8+
ITranslator,
9+
nullTranslator,
10+
TranslationBundle
11+
} from '@jupyterlab/translation';
12+
713
import { ServiceManager } from '@jupyterlab/services';
814

915
import { Message } from '@lumino/messaging';
@@ -23,11 +29,13 @@ const PANEL_CLASS = 'jp-RovaPanel';
2329
* A panel which has the ability to add other children.
2430
*/
2531
export class ExamplePanel extends StackedPanel {
26-
constructor(manager: ServiceManager.IManager) {
32+
constructor(manager: ServiceManager.IManager, translator?: ITranslator) {
2733
super();
34+
this._translator = translator || nullTranslator;
35+
this._trans = this._translator.load('jupyterlab');
2836
this.addClass(PANEL_CLASS);
2937
this.id = 'kernel-messaging-panel';
30-
this.title.label = 'Kernel Messaging Example View';
38+
this.title.label = this._trans.__('Kernel Messaging Example View');
3139
this.title.closable = true;
3240

3341
this._sessionContext = new SessionContext({
@@ -71,4 +79,7 @@ export class ExamplePanel extends StackedPanel {
7179
private _model: KernelModel;
7280
private _sessionContext: SessionContext;
7381
private _example: KernelView;
82+
83+
private _translator: ITranslator;
84+
private _trans: TranslationBundle;
7485
}

0 commit comments

Comments
 (0)