Skip to content

Commit 8baba79

Browse files
authored
Merge pull request #557 from JessicaBarh/add-i18n
localize strings for jupyterlab-lsp
2 parents 06f1e32 + c6df790 commit 8baba79

File tree

17 files changed

+252
-120
lines changed

17 files changed

+252
-120
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
### `@krassowski/jupyterlab-lsp 3.5.1` (unreleased)
44

5+
- features:
6+
7+
- added translation support ([#557], thanks @JessicaBarh)
8+
59
- bug fixes:
610

7-
- fixes name of jupyterlab-lsp package displayed in JupyterLab UI ([#570])
8-
- remove vendored CodeMirror from distribution ([#576])
11+
- fixed name of jupyterlab-lsp package displayed in JupyterLab UI ([#570], thanks @marimeireles)
12+
- removed vendored CodeMirror from distribution ([#576])
913

14+
[#557]: https://github.com/krassowski/jupyterlab-lsp/pull/557
1015
[#570]: https://github.com/krassowski/jupyterlab-lsp/pull/570
1116
[#576]: https://github.com/krassowski/jupyterlab-lsp/pull/576
1217

packages/code-jumpers/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"@jupyterlab/docregistry": "^3.0.0",
3737
"@jupyterlab/fileeditor": "^3.0.0",
3838
"@jupyterlab/notebook": "^3.0.0",
39-
"@jupyterlab/observables": "^4.0.0"
39+
"@jupyterlab/observables": "^4.0.0",
40+
"@jupyterlab/translation": "^3.0.0"
4041
},
4142
"devDependencies": {
4243
"@jupyterlab/apputils": "^3.0.0",
@@ -48,6 +49,7 @@
4849
"@jupyterlab/notebook": "^3.0.0",
4950
"@jupyterlab/observables": "^4.0.0",
5051
"@jupyterlab/testutils": "^3.0.0",
52+
"@jupyterlab/translation": "^3.0.0",
5153
"rimraf": "^3.0.2",
5254
"typescript": "~4.1.3",
5355
"@babel/preset-env": "^7.4.3"

packages/completion-theme/src/about.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { TranslationBundle } from '@jupyterlab/translation';
12
import { LabIcon } from '@jupyterlab/ui-components';
23
import React, { ReactElement } from 'react';
34

@@ -21,6 +22,7 @@ function render_licence(licence: ILicenseInfo): ReactElement {
2122
type IconSetGetter = (theme: ICompletionTheme) => Map<string, LabIcon>;
2223

2324
function render_theme(
25+
trans: TranslationBundle,
2426
theme: ICompletionTheme,
2527
get_set: IconSetGetter,
2628
is_current: boolean
@@ -42,31 +44,37 @@ function render_theme(
4244
>
4345
<h4>
4446
{theme.name}
45-
{is_current ? ' (current)' : ''}
47+
{is_current ? trans.__(' (current)') : ''}
4648
</h4>
4749
<ul>
4850
<li key={'id'}>
4951
ID: <code>{theme.id}</code>
5052
</li>
51-
<li key={'licence'}>Licence: {render_licence(theme.icons.licence)}</li>
53+
<li key={'licence'}>
54+
{trans.__('Licence: ')}
55+
{render_licence(theme.icons.licence)}
56+
</li>
5257
<li key={'dark'}>
5358
{typeof theme.icons.dark === 'undefined'
5459
? ''
55-
: 'Includes dedicated dark mode icons set'}
60+
: trans.__('Includes dedicated dark mode icons set')}
5661
</li>
5762
</ul>
5863
<div className={'lsp-completer-theme-icons'}>{icons}</div>
5964
</div>
6065
);
6166
}
6267

63-
export function render_themes_list(props: {
64-
themes: ICompletionTheme[];
65-
current: ICompletionTheme;
66-
get_set: IconSetGetter;
67-
}): React.ReactElement {
68+
export function render_themes_list(
69+
trans: TranslationBundle,
70+
props: {
71+
themes: ICompletionTheme[];
72+
current: ICompletionTheme;
73+
get_set: IconSetGetter;
74+
}
75+
): React.ReactElement {
6876
let themes = props.themes.map(theme =>
69-
render_theme(theme, props.get_set, theme == props.current)
77+
render_theme(trans, theme, props.get_set, theme == props.current)
7078
);
7179
return <div>{themes}</div>;
7280
}

packages/completion-theme/src/index.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
IThemeManager,
77
showDialog
88
} from '@jupyterlab/apputils';
9+
import { ITranslator, TranslationBundle } from '@jupyterlab/translation';
910
import { LabIcon, kernelIcon } from '@jupyterlab/ui-components';
1011

1112
import { render_themes_list } from './about';
@@ -25,12 +26,14 @@ export class CompletionThemeManager implements ILSPCompletionThemeManager {
2526
private current_theme_id: string;
2627
private icons_cache: Map<string, LabIcon>;
2728
private icon_overrides: Map<string, CompletionItemKindStrings>;
29+
private trans: TranslationBundle;
2830

29-
constructor(protected themeManager: IThemeManager) {
31+
constructor(protected themeManager: IThemeManager, trans: TranslationBundle) {
3032
this.themes = new Map();
3133
this.icons_cache = new Map();
3234
this.icon_overrides = new Map();
3335
themeManager.themeChanged.connect(this.update_icons_set, this);
36+
this.trans = trans;
3437
}
3538

3639
protected is_theme_light() {
@@ -143,13 +146,13 @@ export class CompletionThemeManager implements ILSPCompletionThemeManager {
143146
*/
144147
display_themes() {
145148
showDialog({
146-
title: 'LSP Completer Themes',
147-
body: render_themes_list({
149+
title: this.trans.__('LSP Completer Themes'),
150+
body: render_themes_list(this.trans, {
148151
themes: [...this.themes.values()],
149152
current: this.current_theme,
150153
get_set: this.get_iconset.bind(this)
151154
}),
152-
buttons: [Dialog.okButton()]
155+
buttons: [Dialog.okButton({ label: this.trans.__('OK') })]
153156
}).catch(console.warn);
154157
}
155158

@@ -169,16 +172,18 @@ const LSP_CATEGORY = 'Language server protocol';
169172

170173
export const COMPLETION_THEME_MANAGER: JupyterFrontEndPlugin<ILSPCompletionThemeManager> = {
171174
id: PLUGIN_ID,
172-
requires: [IThemeManager, ICommandPalette],
175+
requires: [IThemeManager, ICommandPalette, ITranslator],
173176
activate: (
174177
app,
175178
themeManager: IThemeManager,
176-
commandPalette: ICommandPalette
179+
commandPalette: ICommandPalette,
180+
translator: ITranslator
177181
) => {
178-
let manager = new CompletionThemeManager(themeManager);
182+
const trans = translator.load('jupyterlab-lsp');
183+
let manager = new CompletionThemeManager(themeManager, trans);
179184
const command_id = 'lsp:completer-about-themes';
180185
app.commands.addCommand(command_id, {
181-
label: 'Display the completer themes',
186+
label: trans.__('Display the completer themes'),
182187
execute: () => {
183188
manager.display_themes();
184189
}

packages/jupyterlab-lsp/src/adapters/adapter.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { JupyterFrontEnd } from '@jupyterlab/application';
22
import { CodeEditor } from '@jupyterlab/codeeditor';
33
import { DocumentRegistry, IDocumentWidget } from '@jupyterlab/docregistry';
4+
import { nullTranslator, TranslationBundle } from '@jupyterlab/translation';
45
import { JSONObject } from '@lumino/coreutils';
56
import { Signal } from '@lumino/signaling';
67

@@ -93,6 +94,7 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
9394
public isConnected: boolean;
9495
public connection_manager: DocumentConnectionManager;
9596
public status_message: StatusMessage;
97+
public trans: TranslationBundle;
9698
protected isDisposed = false;
9799
console: ILSPLogConsole;
98100

@@ -128,6 +130,9 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
128130
this.status_message = new StatusMessage();
129131
this.isConnected = false;
130132
this.console = extension.console.scope('WidgetAdapter');
133+
this.trans = (extension.translator || nullTranslator).load(
134+
'jupyterlab-lsp'
135+
);
131136

132137
// set up signal connections
133138
this.widget.context.saveState.connect(this.on_save_state, this);
@@ -580,7 +585,8 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
580585
connection: connection,
581586
status_message: this.status_message,
582587
settings: feature.settings,
583-
adapter: this
588+
adapter: this,
589+
trans: this.trans
584590
});
585591
adapter_features.push(integration);
586592
}

0 commit comments

Comments
 (0)