Skip to content

Commit 23c1565

Browse files
authored
Merge pull request #118 from kgoo124/localization-kernel-output
Localization for kernel-output example
2 parents dd2eb94 + 4136d50 commit 23c1565

File tree

4 files changed

+54
-37
lines changed

4 files changed

+54
-37
lines changed

advanced/kernel-output/README.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ object ([see the documentation](https://jupyterlab.github.io/jupyterlab/apputils
4141
Here it is stored in the private `_sessionContext` variable:
4242

4343
```ts
44-
// src/panel.ts#L86-L86
44+
// src/panel.ts#L94-L94
4545

4646
private _sessionContext: SessionContext;
4747
```
@@ -50,7 +50,7 @@ A `SessionContext` handles a single kernel session. The session itself (not yet
5050
the kernel) is started with these lines:
5151

5252
```ts
53-
// src/panel.ts#L36-L40
53+
// src/panel.ts#L44-L48
5454

5555
this._sessionContext = new SessionContext({
5656
sessionManager: manager.sessions,
@@ -63,7 +63,7 @@ The private session variable is exposed as read-only for other users
6363
through a getter method:
6464

6565
```ts
66-
// src/panel.ts#L64-L66
66+
// src/panel.ts#L72-L74
6767

6868
get session(): ISessionContext {
6969
return this._sessionContext;
@@ -75,7 +75,7 @@ with this line:
7575

7676
<!-- prettier-ignore-start -->
7777
```ts
78-
// src/panel.ts#L50-L61
78+
// src/panel.ts#L58-L69
7979

8080
void this._sessionContext
8181
.initialize()
@@ -99,7 +99,7 @@ The following two methods ensure the clean disposal of the session
9999
when you close the panel.
100100

101101
```ts
102-
// src/panel.ts#L68-L71
102+
// src/panel.ts#L76-L79
103103

104104
dispose(): void {
105105
this._sessionContext.dispose();
@@ -108,7 +108,7 @@ dispose(): void {
108108
```
109109

110110
```ts
111-
// src/panel.ts#L81-L84
111+
// src/panel.ts#L89-L92
112112

113113
protected onCloseRequest(msg: Message): void {
114114
super.onCloseRequest(msg);
@@ -124,7 +124,7 @@ You can instantiate it with a new `OutputAreaModel`; this is class containing
124124
the data to show:
125125

126126
```ts
127-
// src/panel.ts#L42-L46
127+
// src/panel.ts#L50-L54
128128

129129
this._outputareamodel = new OutputAreaModel();
130130
this._outputarea = new SimplifiedOutputArea({
@@ -138,7 +138,7 @@ some code to a kernel through a `ISessionContext` ([see documentation](https://j
138138
in the specific `SimplifiedOutputArea` object you created:
139139

140140
```ts
141-
// src/panel.ts#L73-L79
141+
// src/panel.ts#L81-L87
142142

143143
execute(code: string): void {
144144
SimplifiedOutputArea.execute(code, this._outputarea, this._sessionContext)
@@ -158,7 +158,7 @@ To display the `SimplifiedOutputArea` Widget you need to add it to your
158158
panel with:
159159

160160
```ts
161-
// src/panel.ts#L48-L48
161+
// src/panel.ts#L56-L56
162162

163163
this.addWidget(this._outputarea);
164164
```
@@ -172,7 +172,7 @@ The last step is to add the panel to the JupyterLab main area.
172172
First, it is a good practice to unify the extension commands into one namespace at the top of the file:
173173

174174
```ts
175-
// src/index.ts#L21-L25
175+
// src/index.ts#L23-L27
176176

177177
namespace CommandIDs {
178178
export const create = 'kernel-output:create';
@@ -185,7 +185,7 @@ You can then add the commands to the palette and the menu by iterating
185185
on a list:
186186

187187
```ts
188-
// src/index.ts#L105-L109
188+
// src/index.ts#L110-L114
189189

190190
// add items in command palette and menu
191191
[CommandIDs.create, CommandIDs.execute].forEach(command => {
@@ -198,7 +198,7 @@ To create a new client session, the service manager must be obtained from
198198
the JupyterLab application:
199199

200200
```ts
201-
// src/index.ts#L54-L54
201+
// src/index.ts#L58-L58
202202

203203
const manager = app.serviceManager;
204204
```
@@ -208,7 +208,7 @@ ready. Then once the panel is created and its session is ready, it
208208
can be added to the JupyterLab main area:
209209

210210
```ts
211-
// src/index.ts#L58-L69
211+
// src/index.ts#L63-L74
212212

213213
let panel: ExamplePanel;
214214

@@ -218,7 +218,7 @@ let panel: ExamplePanel;
218218
* @returns The panel
219219
*/
220220
async function createPanel(): Promise<ExamplePanel> {
221-
panel = new ExamplePanel(manager, rendermime);
221+
panel = new ExamplePanel(manager, rendermime, translator);
222222
shell.add(panel, 'main');
223223
return panel;
224224
}
@@ -231,21 +231,21 @@ to be executed by the kernel. Then you will send it to your panel for execution
231231
and display:
232232

233233
```ts
234-
// src/index.ts#L83-L103
234+
// src/index.ts#L88-L108
235235

236236
commands.addCommand(CommandIDs.execute, {
237-
label: 'Contact Kernel and Execute Code',
238-
caption: 'Contact Kernel and Execute Code',
237+
label: trans.__('Contact Kernel and Execute Code'),
238+
caption: trans.__('Contact Kernel and Execute Code'),
239239
execute: async () => {
240240
// Create the panel if it does not exist
241241
if (!panel) {
242242
await createPanel();
243243
}
244244
// Prompt the user about the statement to be executed
245245
const input = await InputDialog.getText({
246-
title: 'Code to execute',
247-
okLabel: 'Execute',
248-
placeholder: 'Statement to execute'
246+
title: trans.__('Code to execute'),
247+
okLabel: trans.__('Execute'),
248+
placeholder: trans.__('Statement to execute')
249249
});
250250
// Execute the statement
251251
if (input.button.accept) {

advanced/kernel-output/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/outputarea": "~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/outputarea": "~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.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)