Skip to content

Commit

Permalink
Uses translator
Browse files Browse the repository at this point in the history
  • Loading branch information
hbcarlos committed Feb 23, 2023
1 parent a7bb5da commit bef99bc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
7 changes: 5 additions & 2 deletions packages/collaboration-extension/src/filebrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
IDefaultFileBrowser,
IFileBrowserFactory
} from '@jupyterlab/filebrowser';
import { ITranslator } from '@jupyterlab/translation';

import { CommandRegistry } from '@lumino/commands';

Expand All @@ -27,11 +28,12 @@ namespace CommandIDs {
export const defaultFileBrowser: JupyterFrontEndPlugin<IDefaultFileBrowser> = {
id: '@jupyter/collaboration-extension:defaultFileBrowser',
provides: IDefaultFileBrowser,
requires: [IFileBrowserFactory],
requires: [IFileBrowserFactory, ITranslator],
optional: [IRouter, JupyterFrontEnd.ITreeResolver, ILabShell],
activate: async (
app: JupyterFrontEnd,
fileBrowserFactory: IFileBrowserFactory,
translator: ITranslator,
router: IRouter | null,
tree: JupyterFrontEnd.ITreeResolver | null,
labShell: ILabShell | null
Expand All @@ -41,7 +43,8 @@ export const defaultFileBrowser: JupyterFrontEndPlugin<IDefaultFileBrowser> = {
);
const { commands } = app;

const drive = new YDrive(app.serviceManager.user);
const trans = translator.load('jupyter_collaboration');
const drive = new YDrive(app.serviceManager.user, trans);
app.serviceManager.contents.addDrive(drive);

// Manually restore and load the default file browser.
Expand Down
8 changes: 6 additions & 2 deletions packages/docprovider/src/ydrive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
YNotebook
} from '@jupyter/ydoc';
import { URLExt } from '@jupyterlab/coreutils';
import { TranslationBundle } from '@jupyterlab/translation';
import { Contents, Drive, User } from '@jupyterlab/services';
import { WebSocketProvider } from './yprovider';

Expand All @@ -27,9 +28,10 @@ export class YDrive extends Drive {
*
* @param user - The user manager to add the identity to the awareness of documents.
*/
constructor(user: User.IManager) {
constructor(user: User.IManager, translator: TranslationBundle) {
super({ name: 'YDrive' });
this._user = user;
this._translator = translator;
this._providers = new Map<string, WebSocketProvider>();

this.sharedModelFactory = new SharedModelFactory(this._onCreate);
Expand Down Expand Up @@ -155,7 +157,8 @@ export class YDrive extends Drive {
format: options.format,
contentType: options.contentType,
model: sharedModel,
user: this._user
user: this._user,
translator: this._translator
});

const key = `${options.contentType}:${options.format}:${options.path}`;
Expand All @@ -178,6 +181,7 @@ export class YDrive extends Drive {
};

private _user: User.IManager;
private _translator: TranslationBundle;
private _providers: Map<string, WebSocketProvider>;
}

Expand Down
16 changes: 13 additions & 3 deletions packages/docprovider/src/yprovider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { URLExt } from '@jupyterlab/coreutils';
import { showErrorMessage, Dialog } from '@jupyterlab/apputils';
import { ServerConnection, User } from '@jupyterlab/services';
import { TranslationBundle } from '@jupyterlab/translation';

import { PromiseDelegate } from '@lumino/coreutils';
import { IDisposable } from '@lumino/disposable';
Expand Down Expand Up @@ -53,6 +54,7 @@ export class WebSocketProvider implements IDocumentProvider {
this._sharedModel = options.model;
this._awareness = options.model.awareness;
this._yWebsocketProvider = null;
this._translator = options.translator;

const user = options.user;

Expand Down Expand Up @@ -133,9 +135,11 @@ export class WebSocketProvider implements IDocumentProvider {
console.error('Document provider closed:', event.reason);

showErrorMessage(
'Session expired',
'The document session expired. We need to reload this browser tab.',
[Dialog.okButton()]
this._translator.__('Session expired'),
this._translator.__(
'The document session expired. You need to reload this browser tab.'
),
[Dialog.okButton({ label: this._translator.__('Reload') })]
)
.then(r => window.location.reload())
.catch(e => window.location.reload());
Expand All @@ -154,6 +158,7 @@ export class WebSocketProvider implements IDocumentProvider {
private _serverUrl: string;
private _sharedModel: YDocument<DocumentChange>;
private _yWebsocketProvider: YWebsocketProvider | null;
private _translator: TranslationBundle;
}

/**
Expand Down Expand Up @@ -193,5 +198,10 @@ export namespace WebSocketProvider {
* The user data
*/
user: User.IManager;

/**
* The jupyterlab translator
*/
translator: TranslationBundle;
}
}

0 comments on commit bef99bc

Please sign in to comment.