Skip to content

Commit 2b04f5c

Browse files
committed
Added localization to datagrid example
1 parent e7054af commit 2b04f5c

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

basics/datagrid/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@
3434
"watch": "tsc -w"
3535
},
3636
"dependencies": {
37-
"@jupyterlab/application": "^2.0.0",
38-
"@jupyterlab/mainmenu": "^2.0.0",
37+
"@jupyterlab/application": "^3.0.0-beta.1",
38+
"@jupyterlab/mainmenu": "^3.0.0-beta.1",
39+
"@jupyterlab/translation": "^3.0.0-beta.1",
3940
"@lumino/algorithm": "^1.2.3",
4041
"@lumino/coreutils": "^1.3.1",
4142
"@lumino/datagrid": "^0.5.2",

basics/datagrid/src/index.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import { ICommandPalette } from '@jupyterlab/apputils';
77

88
import { IMainMenu } from '@jupyterlab/mainmenu';
99

10+
import {
11+
ITranslator,
12+
nullTranslator,
13+
TranslationBundle
14+
} from '@jupyterlab/translation';
15+
1016
import { DataGrid, DataModel } from '@lumino/datagrid';
1117

1218
import { Menu, StackedPanel } from '@lumino/widgets';
@@ -17,18 +23,20 @@ import { Menu, StackedPanel } from '@lumino/widgets';
1723
const extension: JupyterFrontEndPlugin<void> = {
1824
id: 'datagrid',
1925
autoStart: true,
20-
requires: [ICommandPalette, IMainMenu],
26+
requires: [ICommandPalette, IMainMenu, ITranslator],
2127
activate: (
2228
app: JupyterFrontEnd,
2329
palette: ICommandPalette,
24-
mainMenu: IMainMenu
30+
mainMenu: IMainMenu,
31+
translator: ITranslator
2532
) => {
2633
const { commands, shell } = app;
34+
const trans = translator.load('jupyterlab');
2735

2836
const command = 'examples:datagrid';
2937
commands.addCommand(command, {
30-
label: 'Open a Datagrid',
31-
caption: 'Open a Datagrid Panel',
38+
label: trans.__('Open a Datagrid'),
39+
caption: trans.__('Open a Datagrid Panel'),
3240
execute: () => {
3341
const widget = new DataGridPanel();
3442
shell.add(widget, 'main');
@@ -38,7 +46,7 @@ const extension: JupyterFrontEndPlugin<void> = {
3846

3947
const exampleMenu = new Menu({ commands });
4048

41-
exampleMenu.title.label = 'DataGrid Example';
49+
exampleMenu.title.label = trans.__('DataGrid Example');
4250
mainMenu.addMenu(exampleMenu, { rank: 80 });
4351
exampleMenu.addItem({ command });
4452
}
@@ -47,11 +55,14 @@ const extension: JupyterFrontEndPlugin<void> = {
4755
export default extension;
4856

4957
class DataGridPanel extends StackedPanel {
50-
constructor() {
58+
constructor(translator?: ITranslator) {
5159
super();
60+
this._translator = translator || nullTranslator;
61+
this._trans = this._translator.load('jupyterlab');
62+
5263
this.addClass('jp-example-view');
5364
this.id = 'datagrid-example';
54-
this.title.label = 'Datagrid Example View';
65+
this.title.label = this._trans.__('Datagrid Example View');
5566
this.title.closable = true;
5667

5768
const model = new LargeDataModel();
@@ -60,6 +71,9 @@ class DataGridPanel extends StackedPanel {
6071

6172
this.addWidget(grid);
6273
}
74+
75+
private _translator: ITranslator;
76+
private _trans: TranslationBundle;
6377
}
6478

6579
class LargeDataModel extends DataModel {

0 commit comments

Comments
 (0)