Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

localize strings for jupyterlab-lsp #557

Merged
merged 11 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

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

- features:

- added translation support ([#557], thanks @JessicaBarh)

- bug fixes:

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

[#557]: https://github.com/krassowski/jupyterlab-lsp/pull/557
[#570]: https://github.com/krassowski/jupyterlab-lsp/pull/570
[#576]: https://github.com/krassowski/jupyterlab-lsp/pull/576

Expand Down
4 changes: 3 additions & 1 deletion packages/code-jumpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"@jupyterlab/docregistry": "^3.0.0",
"@jupyterlab/fileeditor": "^3.0.0",
"@jupyterlab/notebook": "^3.0.0",
"@jupyterlab/observables": "^4.0.0"
"@jupyterlab/observables": "^4.0.0",
"@jupyterlab/translation": "^3.0.0"
},
"devDependencies": {
"@jupyterlab/apputils": "^3.0.0",
Expand All @@ -48,6 +49,7 @@
"@jupyterlab/notebook": "^3.0.0",
"@jupyterlab/observables": "^4.0.0",
"@jupyterlab/testutils": "^3.0.0",
"@jupyterlab/translation": "^3.0.0",
"rimraf": "^3.0.2",
"typescript": "~4.1.3",
"@babel/preset-env": "^7.4.3"
Expand Down
26 changes: 17 additions & 9 deletions packages/completion-theme/src/about.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TranslationBundle } from '@jupyterlab/translation';
import { LabIcon } from '@jupyterlab/ui-components';
import React, { ReactElement } from 'react';

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

function render_theme(
trans: TranslationBundle,
theme: ICompletionTheme,
get_set: IconSetGetter,
is_current: boolean
Expand All @@ -42,31 +44,37 @@ function render_theme(
>
<h4>
{theme.name}
{is_current ? ' (current)' : ''}
{is_current ? trans.__(' (current)') : ''}
</h4>
<ul>
<li key={'id'}>
ID: <code>{theme.id}</code>
</li>
<li key={'licence'}>Licence: {render_licence(theme.icons.licence)}</li>
<li key={'licence'}>
{trans.__('Licence: ')}
{render_licence(theme.icons.licence)}
</li>
<li key={'dark'}>
{typeof theme.icons.dark === 'undefined'
? ''
: 'Includes dedicated dark mode icons set'}
: trans.__('Includes dedicated dark mode icons set')}
</li>
</ul>
<div className={'lsp-completer-theme-icons'}>{icons}</div>
</div>
);
}

export function render_themes_list(props: {
themes: ICompletionTheme[];
current: ICompletionTheme;
get_set: IconSetGetter;
}): React.ReactElement {
export function render_themes_list(
trans: TranslationBundle,
props: {
themes: ICompletionTheme[];
current: ICompletionTheme;
get_set: IconSetGetter;
}
): React.ReactElement {
let themes = props.themes.map(theme =>
render_theme(theme, props.get_set, theme == props.current)
render_theme(trans, theme, props.get_set, theme == props.current)
);
return <div>{themes}</div>;
}
21 changes: 13 additions & 8 deletions packages/completion-theme/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IThemeManager,
showDialog
} from '@jupyterlab/apputils';
import { ITranslator, TranslationBundle } from '@jupyterlab/translation';
import { LabIcon, kernelIcon } from '@jupyterlab/ui-components';

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

constructor(protected themeManager: IThemeManager) {
constructor(protected themeManager: IThemeManager, trans: TranslationBundle) {
this.themes = new Map();
this.icons_cache = new Map();
this.icon_overrides = new Map();
themeManager.themeChanged.connect(this.update_icons_set, this);
this.trans = trans;
}

protected is_theme_light() {
Expand Down Expand Up @@ -143,13 +146,13 @@ export class CompletionThemeManager implements ILSPCompletionThemeManager {
*/
display_themes() {
showDialog({
title: 'LSP Completer Themes',
body: render_themes_list({
title: this.trans.__('LSP Completer Themes'),
body: render_themes_list(this.trans, {
themes: [...this.themes.values()],
current: this.current_theme,
get_set: this.get_iconset.bind(this)
}),
buttons: [Dialog.okButton()]
buttons: [Dialog.okButton({ label: this.trans.__('OK') })]
}).catch(console.warn);
}

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

export const COMPLETION_THEME_MANAGER: JupyterFrontEndPlugin<ILSPCompletionThemeManager> = {
id: PLUGIN_ID,
requires: [IThemeManager, ICommandPalette],
requires: [IThemeManager, ICommandPalette, ITranslator],
activate: (
app,
themeManager: IThemeManager,
commandPalette: ICommandPalette
commandPalette: ICommandPalette,
translator: ITranslator
) => {
let manager = new CompletionThemeManager(themeManager);
const trans = translator.load('jupyterlab-lsp');
let manager = new CompletionThemeManager(themeManager, trans);
const command_id = 'lsp:completer-about-themes';
app.commands.addCommand(command_id, {
label: 'Display the completer themes',
label: trans.__('Display the completer themes'),
execute: () => {
manager.display_themes();
}
Expand Down
8 changes: 7 additions & 1 deletion packages/jupyterlab-lsp/src/adapters/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { JupyterFrontEnd } from '@jupyterlab/application';
import { CodeEditor } from '@jupyterlab/codeeditor';
import { DocumentRegistry, IDocumentWidget } from '@jupyterlab/docregistry';
import { nullTranslator, TranslationBundle } from '@jupyterlab/translation';
import { JSONObject } from '@lumino/coreutils';
import { Signal } from '@lumino/signaling';

Expand Down Expand Up @@ -93,6 +94,7 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
public isConnected: boolean;
public connection_manager: DocumentConnectionManager;
public status_message: StatusMessage;
public trans: TranslationBundle;
protected isDisposed = false;
console: ILSPLogConsole;

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

// set up signal connections
this.widget.context.saveState.connect(this.on_save_state, this);
Expand Down Expand Up @@ -580,7 +585,8 @@ export abstract class WidgetAdapter<T extends IDocumentWidget> {
connection: connection,
status_message: this.status_message,
settings: feature.settings,
adapter: this
adapter: this,
trans: this.trans
});
adapter_features.push(integration);
}
Expand Down
Loading