Skip to content

Commit

Permalink
Improve translations in diagnostics, update translation domain
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Sep 4, 2021
1 parent 9c41716 commit dc5d899
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 115 deletions.
2 changes: 1 addition & 1 deletion packages/completion-theme/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export const COMPLETION_THEME_MANAGER: JupyterFrontEndPlugin<ILSPCompletionTheme
commandPalette: ICommandPalette,
translator: ITranslator
) => {
const trans = translator.load('jupyterlab-lsp');
const trans = translator.load('jupyterlab_lsp');
let manager = new CompletionThemeManager(themeManager, trans);
const command_id = 'lsp:completer-about-themes';
app.commands.addCommand(command_id, {
Expand Down
34 changes: 24 additions & 10 deletions packages/jupyterlab-lsp/src/components/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { IDocumentWidget } from '@jupyterlab/docregistry';
import { nullTranslator } from '@jupyterlab/translation';

import { WidgetAdapter } from '../adapters/adapter';
import { BrowserConsole } from '../virtual/console';
import { VirtualDocument } from '../virtual/document';

import { get_breadcrumbs } from './utils';
import { getBreadcrumbs } from './utils';

function create_dummy_document(options: Partial<VirtualDocument.IOptions>) {
return new VirtualDocument({
Expand All @@ -20,13 +21,18 @@ function create_dummy_document(options: Partial<VirtualDocument.IOptions>) {
}

describe('get_breadcrumbs', () => {
const trans = nullTranslator.load('jupyterlab_lsp');
it('should collapse long paths', () => {
let document = create_dummy_document({
path: 'dir1/dir2/Test.ipynb'
});
let breadcrumbs = get_breadcrumbs(document, {
has_multiple_editors: false
} as WidgetAdapter<IDocumentWidget>);
let breadcrumbs = getBreadcrumbs(
document,
{
has_multiple_editors: false
} as WidgetAdapter<IDocumentWidget>,
trans
);
expect(breadcrumbs[0].props['title']).toBe('dir1/dir2/Test.ipynb');
expect(breadcrumbs[0].props['children']).toBe('dir1/.../Test.ipynb');
});
Expand All @@ -37,9 +43,13 @@ describe('get_breadcrumbs', () => {
file_extension: 'py',
has_lsp_supported_file: false
});
let breadcrumbs = get_breadcrumbs(document, {
has_multiple_editors: false
} as WidgetAdapter<IDocumentWidget>);
let breadcrumbs = getBreadcrumbs(
document,
{
has_multiple_editors: false
} as WidgetAdapter<IDocumentWidget>,
trans
);
expect(breadcrumbs[0].props['children']).toBe('Test.ipynb');
});

Expand All @@ -49,9 +59,13 @@ describe('get_breadcrumbs', () => {
file_extension: 'py',
has_lsp_supported_file: true
});
let breadcrumbs = get_breadcrumbs(document, {
has_multiple_editors: false
} as WidgetAdapter<IDocumentWidget>);
let breadcrumbs = getBreadcrumbs(
document,
{
has_multiple_editors: false
} as WidgetAdapter<IDocumentWidget>,
trans
);
expect(breadcrumbs[0].props['children']).toBe('test.py');
});
});
11 changes: 7 additions & 4 deletions packages/jupyterlab-lsp/src/components/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { IDocumentWidget } from '@jupyterlab/docregistry';
import { TranslationBundle } from '@jupyterlab/translation';
import React from 'react';

import { WidgetAdapter } from '../adapters/adapter';
import { VirtualDocument } from '../virtual/document';

export function get_breadcrumbs(
export function getBreadcrumbs(
document: VirtualDocument,
adapter: WidgetAdapter<IDocumentWidget>,
trans: TranslationBundle,
collapse = true
): JSX.Element[] {
return document.ancestry.map((document: VirtualDocument) => {
Expand Down Expand Up @@ -46,8 +48,8 @@ export function get_breadcrumbs(

let cell_locator =
first_cell === last_cell
? `cell ${first_cell + 1}`
: `cells: ${first_cell + 1}-${last_cell + 1}`;
? trans.__('cell %1', first_cell + 1)
: trans.__('cells: %1-%2', first_cell + 1, last_cell + 1);

return (
<span key={document.uri}>
Expand All @@ -73,6 +75,7 @@ export function focus_on(node: HTMLElement) {
export function DocumentLocator(props: {
document: VirtualDocument;
adapter: WidgetAdapter<any>;
trans?: TranslationBundle;
}) {
let { document, adapter } = props;
let target: HTMLElement = null;
Expand All @@ -84,7 +87,7 @@ export function DocumentLocator(props: {
console.warn('Could not get first line of ', document);
}
}
let breadcrumbs = get_breadcrumbs(document, adapter);
let breadcrumbs = getBreadcrumbs(document, adapter, props.trans);
return (
<div
className={'lsp-document-locator'}
Expand Down
16 changes: 8 additions & 8 deletions packages/jupyterlab-lsp/src/features/diagnostics/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class DiagnosticsPanel {
this._content.addClass('lsp-diagnostics-panel-content');
const widget = new MainAreaWidget({ content: this._content });
widget.id = 'lsp-diagnostics-panel';
widget.title.label = this.trans?.__('Diagnostics Panel');
widget.title.label = this.trans.__('Diagnostics Panel');
widget.title.closable = true;
widget.title.icon = diagnosticsIcon;
return widget;
Expand All @@ -95,10 +95,10 @@ class DiagnosticsPanel {
register(app: JupyterFrontEnd) {
const widget = this.widget;

let get_column = (name: string) => {
let get_column = (id: string) => {
// TODO: a hashmap in the panel itself?
for (let column of widget.content.columns) {
if (column.name === name) {
if (column.id === id) {
return column;
}
}
Expand All @@ -110,21 +110,21 @@ class DiagnosticsPanel {

app.commands.addCommand(CMD_COLUMN_VISIBILITY, {
execute: args => {
let column = get_column(args['name'] as string);
let column = get_column(args['id'] as string);
column.is_visible = !column.is_visible;
widget.update();
},
label: args => this.trans.__(`${args['name']}`) as string,
label: args => this.trans.__(args['id'] as string),
isToggled: args => {
let column = get_column(args['name'] as string);
let column = get_column(args['id'] as string);
return column.is_visible;
}
});

for (let column of widget.content.columns) {
columns_menu.addItem({
command: CMD_COLUMN_VISIBILITY,
args: { name: column.name }
args: { id: column.id }
});
}
app.contextMenu.addItem({
Expand Down Expand Up @@ -238,7 +238,7 @@ class DiagnosticsPanel {
.writeText(message)
.then(() => {
this.content.model.status_message.set(
this.trans.__(`Successfully copied "%1" to clipboard`, message)
this.trans.__('Successfully copied "%1" to clipboard', message)
);
})
.catch(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/jupyterlab-lsp/src/features/diagnostics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const DIAGNOSTICS_PLUGIN: JupyterFrontEndPlugin<void> = {
translator: ITranslator
) => {
const settings = new FeatureSettings(settingRegistry, FEATURE_ID);
const trans = translator.load('jupyterlab-lsp');
const trans = translator.load('jupyterlab_lsp');

featureManager.register({
feature: {
Expand Down
Loading

0 comments on commit dc5d899

Please sign in to comment.