Skip to content

Commit 3731607

Browse files
thegoomanjtpio
authored andcommitted
Localization for signals example
1 parent 4cb5863 commit 3731607

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

basics/signals/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"@jupyterlab/application": "~3.0.0-beta.4",
4646
"@jupyterlab/launcher": "~3.0.0-beta.4",
4747
"@jupyterlab/mainmenu": "~3.0.0-beta.4",
48+
"@jupyterlab/translation": "^3.0.0-beta.4",
4849
"@lumino/algorithm": "^1.3.3",
4950
"@lumino/coreutils": "^1.5.3",
5051
"@lumino/datagrid": "^0.3.1",

basics/signals/src/index.ts

Lines changed: 10 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 { SignalExamplePanel } from './panel';
@@ -27,7 +29,7 @@ const extension: JupyterFrontEndPlugin<void> = {
2729
id: 'signals',
2830
autoStart: true,
2931
optional: [ILauncher],
30-
requires: [ICommandPalette, IMainMenu],
32+
requires: [ICommandPalette, IMainMenu, ITranslator],
3133
activate: activate
3234
};
3335

@@ -43,11 +45,13 @@ function activate(
4345
app: JupyterFrontEnd,
4446
palette: ICommandPalette,
4547
mainMenu: IMainMenu,
46-
launcher: ILauncher | null
48+
launcher: ILauncher | null,
49+
translator: ITranslator
4750
): void {
4851
const manager = app.serviceManager;
4952
const { commands, shell } = app;
5053
const category = 'Extension Examples';
54+
const trans = translator.load('jupyterlab');
5155

5256
// Add launcher
5357
if (launcher) {
@@ -65,21 +69,21 @@ function activate(
6569
function createPanel(): Promise<SignalExamplePanel> {
6670
let panel: SignalExamplePanel;
6771
return manager.ready.then(() => {
68-
panel = new SignalExamplePanel();
72+
panel = new SignalExamplePanel(translator);
6973
shell.add(panel, 'main');
7074
return panel;
7175
});
7276
}
7377

7478
// Add menu tab
7579
const signalMenu = new Menu({ commands });
76-
signalMenu.title.label = 'Signal Example';
80+
signalMenu.title.label = trans.__('Signal Example');
7781
mainMenu.addMenu(signalMenu);
7882

7983
// Add commands to registry
8084
commands.addCommand(CommandIDs.create, {
81-
label: 'Open the Signal Example Panel',
82-
caption: 'Open the Signal Example Panel',
85+
label: trans.__('Open the Signal Example Panel'),
86+
caption: trans.__('Open the Signal Example Panel'),
8387
execute: createPanel
8488
});
8589

basics/signals/src/panel.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import {
2+
ITranslator,
3+
nullTranslator,
4+
TranslationBundle
5+
} from '@jupyterlab/translation';
16
import { StackedPanel } from '@lumino/widgets';
27

38
import { ButtonWidget, ICount } from './button';
@@ -10,11 +15,13 @@ const PANEL_CLASS = 'jp-tutorial-view';
1015
* A panel which contains a console and the ability to add other children.
1116
*/
1217
export class SignalExamplePanel extends StackedPanel {
13-
constructor() {
18+
constructor(translator?: ITranslator) {
1419
super();
20+
this._translator = translator || nullTranslator;
21+
this._trans = this._translator.load('jupyterlab');
1522
this.addClass(PANEL_CLASS);
1623
this.id = 'SignalExamplePanel';
17-
this.title.label = 'Signal Example View';
24+
this.title.label = this._trans.__('Signal Example View');
1825
this.title.closable = true;
1926

2027
this._widget = new ButtonWidget();
@@ -33,4 +40,7 @@ export class SignalExamplePanel extends StackedPanel {
3340
}
3441

3542
private _widget: ButtonWidget;
43+
44+
private _translator: ITranslator;
45+
private _trans: TranslationBundle;
3646
}

0 commit comments

Comments
 (0)