Skip to content

Commit 9036fb6

Browse files
thegoomanjtpio
authored andcommitted
Localization for kernel-output example
1 parent dd2eb94 commit 9036fb6

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

advanced/kernel-output/package.json

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

advanced/kernel-output/src/index.ts

Lines changed: 16 additions & 11 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 { IRenderMimeRegistry } from '@jupyterlab/rendermime';
1315

1416
import { Menu } from '@lumino/widgets';
@@ -31,29 +33,32 @@ const extension: JupyterFrontEndPlugin<void> = {
3133
id: 'kernel-output',
3234
autoStart: true,
3335
optional: [ILauncher],
34-
requires: [ICommandPalette, IMainMenu, IRenderMimeRegistry],
36+
requires: [ICommandPalette, IMainMenu, IRenderMimeRegistry, ITranslator],
3537
activate: activate
3638
};
3739

3840
/**
3941
* Activate the JupyterLab extension.
4042
*
41-
* @param app Jupyter Font End
43+
* @param app Jupyter Front End
4244
* @param palette Jupyter Commands Palette
4345
* @param mainMenu Jupyter Menu
4446
* @param rendermime Jupyter Render Mime Registry
47+
* @param translator Jupyter Translator
4548
* @param launcher [optional] Jupyter Launcher
4649
*/
4750
function activate(
4851
app: JupyterFrontEnd,
4952
palette: ICommandPalette,
5053
mainMenu: IMainMenu,
5154
rendermime: IRenderMimeRegistry,
55+
translator: ITranslator,
5256
launcher: ILauncher | null
5357
): void {
5458
const manager = app.serviceManager;
5559
const { commands, shell } = app;
5660
const category = 'Extension Examples';
61+
const trans = translator.load('jupyterlab');
5762

5863
let panel: ExamplePanel;
5964

@@ -63,36 +68,36 @@ function activate(
6368
* @returns The panel
6469
*/
6570
async function createPanel(): Promise<ExamplePanel> {
66-
panel = new ExamplePanel(manager, rendermime);
71+
panel = new ExamplePanel(manager, rendermime, 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 Output';
78+
exampleMenu.title.label = trans.__('Kernel Output');
7479
mainMenu.addMenu(exampleMenu);
7580

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

8388
commands.addCommand(CommandIDs.execute, {
84-
label: 'Contact Kernel and Execute Code',
85-
caption: 'Contact Kernel and Execute Code',
89+
label: trans.__('Contact Kernel and Execute Code'),
90+
caption: trans.__('Contact Kernel and Execute Code'),
8691
execute: async () => {
8792
// Create the panel if it does not exist
8893
if (!panel) {
8994
await createPanel();
9095
}
9196
// Prompt the user about the statement to be executed
9297
const input = await InputDialog.getText({
93-
title: 'Code to execute',
94-
okLabel: 'Execute',
95-
placeholder: 'Statement to execute'
98+
title: trans.__('Code to execute'),
99+
okLabel: trans.__('Execute'),
100+
placeholder: trans.__('Statement to execute')
96101
});
97102
// Execute the statement
98103
if (input.button.accept) {

advanced/kernel-output/src/panel.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import { OutputAreaModel, SimplifiedOutputArea } from '@jupyterlab/outputarea';
99
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
1010

1111
import { KernelMessage, ServiceManager } from '@jupyterlab/services';
12+
import {
13+
ITranslator,
14+
nullTranslator,
15+
TranslationBundle
16+
} from '@jupyterlab/translation';
1217

1318
import { Message } from '@lumino/messaging';
1419

@@ -25,12 +30,15 @@ const PANEL_CLASS = 'jp-RovaPanel';
2530
export class ExamplePanel extends StackedPanel {
2631
constructor(
2732
manager: ServiceManager.IManager,
28-
rendermime: IRenderMimeRegistry
33+
rendermime: IRenderMimeRegistry,
34+
translator?: ITranslator
2935
) {
3036
super();
37+
this._translator = translator || nullTranslator;
38+
this._trans = this._translator.load('jupyterlab');
3139
this.addClass(PANEL_CLASS);
3240
this.id = 'kernel-output-panel';
33-
this.title.label = 'Kernel Output Example View';
41+
this.title.label = this._trans.__('Kernel Output Example View');
3442
this.title.closable = true;
3543

3644
this._sessionContext = new SessionContext({
@@ -86,4 +94,7 @@ export class ExamplePanel extends StackedPanel {
8694
private _sessionContext: SessionContext;
8795
private _outputarea: SimplifiedOutputArea;
8896
private _outputareamodel: OutputAreaModel;
97+
98+
private _translator: ITranslator;
99+
private _trans: TranslationBundle;
89100
}

0 commit comments

Comments
 (0)