Skip to content

Commit 8696ce5

Browse files
committed
Localization for kernel-messaging example
1 parent b0b3189 commit 8696ce5

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

advanced/kernel-messaging/src/index.ts

Lines changed: 12 additions & 7 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
4042
* @param launcher [optional] Jupyter Launcher
43+
* @param translator Jupyter Translator
4144
*/
4245
function activate(
4346
app: JupyterFrontEnd,
4447
palette: ICommandPalette,
4548
mainMenu: IMainMenu,
46-
launcher: ILauncher | null
49+
launcher: ILauncher | null,
50+
translator: ITranslator
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)